Skip to content

Commit 56d0548

Browse files
committed
[css-highlight-api-1] Make HighlightRegistry maplike and remove name property from Highlight.
1 parent b990485 commit 56d0548

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

css-highlight-api-1/Overview.bs

+21-38
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Introduction</h2>
103103
r.setStart(document.body, 0);
104104
r.setEnd(document.body, 2);
105105

106-
CSS.highlights.add(new Highlight("example-highlight", r));
106+
CSS.highlights.set("example-highlight", new Highlight(r));
107107
</script>
108108
</xmp>
109109

@@ -139,7 +139,7 @@ Setting up Custom Highlights</h2>
139139
<h3 id=creation>
140140
Creating Custom Highlights</h3>
141141

142-
A <dfn>custom highlight</dfn> is a named collection of [=ranges=]
142+
A <dfn>custom highlight</dfn> is a collection of [=ranges=]
143143
representing portions of a document.
144144
They do not necessarily fit into the element tree,
145145
and can arbitrarily cross element boundaries without honoring its nesting structure.
@@ -160,35 +160,24 @@ Creating Custom Highlights</h3>
160160
authors can chose between using {{Range}} objects and {{StaticRange}} objects.
161161
See [[#range-invalidation]] for more details about this choice and its implications.
162162

163-
The <dfn for="custom highlight">name</dfn> of a [=custom highlight=]
164-
is represented by its {{Highlight/name}} attribute,
165-
which must be a valid <<ident-token>>.
166-
167163
<xmp class="idl">
168164
[Exposed=Window]
169165
interface Highlight {
170-
constructor(CSSOMString name, AbstractRange... initialRanges);
166+
constructor(AbstractRange... initialRanges);
171167
setlike<AbstractRange>;
172168
attribute long priority;
173-
readonly attribute CSSOMString name;
174169
};
175170
</xmp>
176171

177172
See [[#priorities]] for more information on the {{Highlight/priority}} attribute.
178173

179174
<div algorithm="to create a custom highlight">
180-
When the <dfn for=Highlight constructor>Highlight(CSSOMString name, AbstractRange... initialRanges)</dfn> constructor is invoked,
175+
When the <dfn for=Highlight constructor>Highlight(AbstractRange... initialRanges)</dfn> constructor is invoked,
181176
run the following steps:
182177

183178
<ol>
184179
<li>
185180
Let |highlight| be the new {{Highlight}} object.
186-
<li>
187-
If {{name!!argument}} does not [=CSS/parse=] as an <<ident-token>>, then [=throw=] a {{"SyntaxError"}}.
188-
<li>
189-
Let |nameArg| be the result of [=converted to an ECMAScript value|converting=] {{name!!argument}} to an ECMAScript value.
190-
<li>
191-
Set |highlight|'s {{Highlight/name}} to |nameArg|
192181
<li>
193182
Set |highlight|'s {{Highlight/priority}} to <code>0</code>.
194183
<li>
@@ -206,13 +195,13 @@ Creating Custom Highlights</h3>
206195
Registering Custom Highlights</h3>
207196

208197
In order to have any effect,
209-
[=custom highlights=] then needs to be
210-
[=registered=] it into the [=highlight registry=].
198+
[=custom highlights=] need to be
199+
[=registered=] into the [=highlight registry=].
211200

212201
The <dfn>highlight registry</dfn> is accessed via the {{CSS/highlights}} attribute of the {{CSS}} namespace,
213202
and represents all the [=custom highlights=] [=registered=] for the [=current global object=]’s [=associated Document=].
214-
It is a [=setlike=], and can be updated using the usual methods.
215-
It's [=set entries=] is initially empty.
203+
It is a [=maplike=], and can be updated using the usual methods.
204+
It's [=map entries=] is initially empty.
216205

217206
A [=custom highlight=] is said to be <dfn>registered</dfn>
218207
if it is in the [=highlight registry=].
@@ -225,41 +214,35 @@ Registering Custom Highlights</h3>
225214

226215
[Exposed=Window]
227216
interface HighlightRegistry {
228-
setlike<Highlight>;
217+
maplike<DOMString, Highlight>;
229218
};
230219
</xmp>
231220

232221
<div algorithm="to register a custom highlight">
233222
To [=register=] a [=custom highlight=],
234-
invoke the {{HighlightRegistry/add()}} method of the [=highlight registry=]
235-
with the [=custom highlight=] as the argument.
236-
237-
When invoked,
238-
the <dfn method for=HighlightRegistry>add(Highlight value)</dfn> method must run these steps:
239-
240-
1. If there is already a [=set entry=] with the same {{Highlight/name}} as the {{Highlight/name}} of {{value}},
241-
then [=throw=] an {{"OperationError"}}.
242-
3. Let |valueArg| be the result of [=converted to an ECMAScript value|converting=] {{value}} to an ECMAScript value.
243-
4. Let |result| be the result of running [[webidl#es-add-delete|the steps for a built-in setlike add function]],
244-
with the [=context object=] as the <code>this</code> value
245-
and with |valueArg| as the argument.
246-
5. Return |result|.
247-
</div>
223+
invoke the <code>set</code> method of the [=highlight registry=]
224+
which will run [[webidl#es-map-set|the steps for a built-in maplike set function]],
225+
with the [=context object=] as the <code>this</code> value,
226+
the passed-in [=custom highlight name=] as |keyArg|,
227+
and the passed-in highlight as |valueArg|.
228+
229+
The <dfn>custom highlight name</dfn> assigned to a [=custom highlight=] when it is [=registered=]
230+
is used to identify the highlight during styling (see [[#styling-highlights]]).
248231

249232
<h2 id=styling-highlights>
250233
Styling Custom Highlights</h2>
251234

252235
<h3 id=custom-highlight-pseudo>
253236
The Custom Highlight Pseudo-element: ''::highlight()''</h3>
254237

255-
The <dfn>::highlight(<<highlight-name>>)</dfn> pseudo-element
238+
The <dfn>::highlight(<<custom-highlight-name>>)</dfn> pseudo-element
256239
(also known as the <dfn>custom highlight pseudo-element</dfn>)
257240
represents the portion of a document that
258241
is being [=contained=] or [=partially contained=]
259242
in all the [=ranges=] of the [=registered=] [=custom highlight=]
260-
with the [=custom highlight/name=] <<highlight-name>>,
243+
with the [=custom highlight name=] <<custom-highlight-name>>,
261244
if any.
262-
<dfn type><<highlight-name>></dfn> must be a valid CSS <<ident-token>>.
245+
<dfn type><<custom-highlight-name>></dfn> must be a valid CSS <<ident-token>>.
263246

264247

265248
<h3 id=processing-model>
@@ -317,7 +300,7 @@ Painting</h4>
317300
r2.setStart(textNode, 3);
318301
r2.setEnd(textNode, 7);
319302

320-
CSS.highlights.add(new Highlight("sample", r1, r2));
303+
CSS.highlights.set("sample", new Highlight(r1, r2));
321304
</script>
322305
</xmp>
323306

0 commit comments

Comments
 (0)