Skip to content

Commit a40b2bd

Browse files
committed
[css-highlight-api][css-pseudo] add style attribute to pseudo-elements
Use it in css-highlight-api as a replacement for the style attribute on Highlight. Closes #4588 Closes #4602
1 parent f9c2de2 commit a40b2bd

File tree

2 files changed

+28
-52
lines changed

2 files changed

+28
-52
lines changed

css-highlight-api-1/Overview.bs

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Complain About: accidental-2119 yes
4444
<pre class=link-defaults>
4545
spec:css-color-4; type:property; text:color
4646
spec:css-pseudo-4; type:dfn; text:highlight overlay
47+
spec:html; type:element; text:style
4748
</pre>
4849

4950
<style>
@@ -166,14 +167,12 @@ Creating Custom Highlights</h3>
166167
interface Highlight {
167168
constructor(CSSOMString name, optional sequence<AbstractRange> initialRanges = []);
168169
setlike<AbstractRange>;
169-
attribute CSSStyleDeclaration style;
170170
attribute double priority;
171171
readonly attribute CSSOMString name;
172172
};
173173
</xmp>
174174

175-
See [[#priorities]] for more information on the {{Highlight/priority}} attribute,
176-
and [[#style-attr]] for more information on the {{Highlight/style}} attribute.
175+
See [[#priorities]] for more information on the {{Highlight/priority}} attribute.
177176

178177
<div algorithm="to create a custom highlight">
179178
When the <dfn for=Highlight constructor>Highlight(CSSOMString name, optional sequence<AbstractRange> initialRanges = [])</dfn> constructor is invoked,
@@ -190,13 +189,6 @@ Creating Custom Highlights</h3>
190189
Set |highlight|'s {{Highlight/name}} to |nameArg|
191190
<li>
192191
Set |highlight|'s {{Highlight/priority}} to <code>0</code>.
193-
<li>
194-
Set |highlight|'s {{Highlight/style}}
195-
to a [=CSS declaration block=] object
196-
whose [=readonly flag=] is unset,
197-
whose [=parent CSS rule=] is <code>null</code>,
198-
whose [=owner node=] is <code>null</code>,
199-
and whose [=declarations=] list is empty.
200192
<li>
201193
For each |range| of {{initialRanges}},
202194
let |rangeArg| be the result of [=converted to an ECMAScript value|converting=] |range| to an ECMAScript value,
@@ -270,24 +262,20 @@ The Custom Highlight Pseudo-element: ''::highlight()''</h3>
270262

271263

272264
<h3 id=style-attr>
273-
Default Styling of a Custom Highlight</h3>
274-
275-
A [=custom highlight=]'s {{Highlight/style}} attribute
276-
is a [=CSS declaration block=] object
277-
which authors can use to define
278-
the [=custom highlight=]'s <dfn>default style</dfn>.
279-
This determines the appearance of the [=custom highlight=]
280-
when ''::highlight()'' has not been used to specify other styles.
281-
(See also [[#c-and-h]] for more information on
282-
how to determine which styles apply
283-
when several are specified).
265+
Styling of a Custom Highlight via scripting</h3>
266+
267+
The {{CSSPseudoElement/type}} attribute of {{CSSPseudoElement}} (see [[css-pseudo-4]]) is extended
268+
to accept <code>"::highlight(<<highlight-name>>)"</code> as one of the possible values.
269+
Together with the {{CSSPseudoElement/style}} attribute of {{CSSPseudoElement}},
270+
this enables authors to set the appearance of the [=custom highlight=]
271+
entirely through scripting.
284272

285273
<div class=example id=style-attr-ex>
286274

287275
The following example achieves the same rendering
288276
as <a href=#intro-ex>the example in the overview section</a>
289-
without using the ''::highlight()'' pseudo-element,
290-
by providing a default style via scripting instead.
277+
without any declaration in a <{style}> element
278+
by providing a style attribute via scripting instead.
291279

292280
<xmp highlight=html>
293281
<body><span>One </span><span>two </span><span>three...</span>
@@ -296,25 +284,15 @@ Default Styling of a Custom Highlight</h3>
296284
r.setStart(document.body, 0);
297285
r.setEnd(document.body, 2);
298286

299-
let h = new Highlight("inline-highlight", [r]);
300-
h.style.backgroundColor = "yellow";
301-
h.style.color = "blue";
287+
CSS.highlights.add(new Highlight("inline-highlight", [r]));
302288

303-
CSS.highlights.add(h);
289+
let s = document.documentElement.pseudo("::highlight(inline-highlight)").style;
290+
s.backgroundColor = "yellow";
291+
s.color = "blue";
304292
</script>
305293
</xmp>
306-
307-
This would be overriden if by any use of ''::highlight(inline-highlight)'' in a stylesheet.
308294
</div>
309295

310-
Issue(4588): Do we really need this?
311-
Would it not make more sense to have a generic mechanism to set the style attribute
312-
on any pseudo element?
313-
In that case I'd also expect it
314-
to behave more like [[css-style-attr]]
315-
and to have a higher specificity than any selector,
316-
instead of being a default filling in if there's not specified style.
317-
318296
<h3 id=processing-model>
319297
Processing Model</h3>
320298

@@ -325,21 +303,13 @@ Applicable Properties</h4>
325303
like the built-in [=highlight pseudo-elements=],
326304
can only be styled with a limited set of properties.
327305
See [[css-pseudo-4#highlight-styling]] for the full list.
328-
The same limitation applies to the {{Highlight/style}} attribute of [=custom highlights=].
329306

330307
<h4 id=c-and-h>
331308
Cascading and Inheritance</h4>
332309

333310
The [=cascading=] and [=inheritance=] of [=custom highlight pseudo-elements=] is handled
334311
identically to that of the built-in [=highlight pseudo-elements=],
335-
as defined in [[css-pseudo-4#highlight-cascade]],
336-
with one addition:
337-
similarly to how
338-
the User Agent is expected to use the OS-default highlight colors for ''::selection''
339-
when neither 'color' nor 'background-color' have been specified,
340-
the User Agent must use the styles provided in
341-
the {{Highlight/style}} attribute of the corresponding [=custom highlight=]
342-
when no applicable property has been specified via ''::highlight()''.
312+
as defined in [[css-pseudo-4#highlight-cascade]].
343313

344314
<h4 id=painting>
345315
Painting</h4>
@@ -499,7 +469,6 @@ Repaints</h3>
499469
The User Agent must also repaint highlights as needed
500470
in response to changes by the author
501471
to the {{Highlight/priority}},
502-
to the {{Highlight/style}},
503472
or to the [=boundary points=] of {{Range}}s
504473
of a [=registered=] [=custom highlight=].
505474

css-pseudo-4/Overview.bs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Indent: 2
2222
spec:css-color-3; type:value; text:currentcolor
2323
spec:css-color-3; type:property; text:color
2424
spec:fill-stroke-3; type:property; text:stroke-width
25+
spec:css-style-attr; type:dfn; text:style attribute
2526
</pre>
2627

2728
<h2 id="intro">Introduction</h2>
@@ -864,6 +865,7 @@ Additions to the CSS Object Model</h2>
864865
interface CSSPseudoElement : EventTarget {
865866
readonly attribute CSSOMString type;
866867
readonly attribute Element element;
868+
attribute CSSStyleDeclaration style;
867869
};
868870
</pre>
869871

@@ -883,12 +885,17 @@ Additions to the CSS Object Model</h2>
883885
The <dfn attribute for=CSSPseudoElement>element</dfn> attribute is the
884886
[=originating element=] of the pseudo-element.
885887

888+
The <dfn attribute for=CSSPseudoElement>style</dfn> attribute
889+
is [=CSS declaration block=] whose associated properties
890+
are as follows:
891+
* the [=readonly flag=] is unset,
892+
* the [=parent CSS rule=] is <code>null</code>,
893+
* the [=owner node=] is the pseudo-element
894+
* the initially empty [=declarations=] list represents a [=style attribute=] for this pseudo-element
895+
in the sence of [[!css-style-attr]] and as used in [[!css-cascade-4]].
896+
886897
Note: This interface may be extended in the future
887-
to other pseudo-element types
888-
and/or to allow setting style information
889-
through a {{CSSStyleDeclaration}} <code>style</code> attribute.
890-
The current functionality is limited
891-
to that which is needed to support [[web-animations-1]].
898+
to other pseudo-element types.
892899

893900
<h3 id="window-interface">
894901
{{pseudo()}} method of the {{Element}} interface</h3>

0 commit comments

Comments
 (0)