@@ -143,7 +143,7 @@ The core features of the CSSOM are oriented towards providing basic capabilities
143
143
and manipulation of style related state information and processes.
144
144
145
145
The features defined below are fundamentally based on prior specifications of the W3C DOM Working Group, primarily
146
- [[DOM-LEVEL-2-STYLE ]] . The purposes of the present document are (1) to improve on that prior work by providing
146
+ [[DOM]] . The purposes of the present document are (1) to improve on that prior work by providing
147
147
more technical specificity (so as to improve testability and interoperability), (2) to deprecate or remove certain less-widely implemented
148
148
features no longer considered to be essential in this context, and (3) to newly specify certain extensions that have been
149
149
or expected to be widely implemented.
@@ -293,22 +293,22 @@ typedef DOMString CSSOMString;
293
293
</pre>
294
294
295
295
<div class=note>
296
- The difference is only observable from web content
297
- when <a>surrogate</a> code units are involved.
298
- {{DOMString}} would preserve them,
299
- whereas {{USVString}} would replace them with U+FFFD REPLACEMENT CHARACTER.
300
-
301
- This choice effectively allows implementations to do this replacement,
302
- but does not require it.
303
-
304
- Using {{USVString}} enables an implementation
305
- to use UTF-8 internally to represent strings in memory.
306
- Since well-formed UTF-8 specifically disallows <a>surrogate</a> code points,
307
- it effectively requires this replacement.
308
-
309
- On the other hand,
310
- implementations that internally represent strings as 16-bit <a>code units</a>
311
- might prefer to avoid the cost of doing this replacement.
296
+ The difference is only observable from web content
297
+ when <a>surrogate</a> code units are involved.
298
+ {{DOMString}} would preserve them,
299
+ whereas {{USVString}} would replace them with U+FFFD REPLACEMENT CHARACTER.
300
+
301
+ This choice effectively allows implementations to do this replacement,
302
+ but does not require it.
303
+
304
+ Using {{USVString}} enables an implementation
305
+ to use UTF-8 internally to represent strings in memory.
306
+ Since well-formed UTF-8 specifically disallows <a>surrogate</a> code points,
307
+ it effectively requires this replacement.
308
+
309
+ On the other hand,
310
+ implementations that internally represent strings as 16-bit <a>code units</a>
311
+ might prefer to avoid the cost of doing this replacement.
312
312
</div>
313
313
314
314
@@ -743,7 +743,38 @@ CSS Style Sheets {#css-style-sheets}
743
743
744
744
A <dfn export>CSS style sheet</dfn> is an abstract concept that
745
745
represents a style sheet as defined by the CSS specification. In the CSSOM a
746
- <a>CSS style sheet</a> is represented as a {{CSSStyleSheet}} object. A
746
+ <a>CSS style sheet</a> is represented as a {{CSSStyleSheet}} object.
747
+
748
+ <dl>
749
+ <dt> <dfn constructor for=CSSStyleSheet>CSSStyleSheet(<var>options</var>)</dfn> </dt>
750
+ <dd>
751
+ When called, execute these steps:
752
+ <ol>
753
+ <li> Construct a new {{/CSSStyleSheet}} object <var> sheet</var> with the following properties:
754
+ <ul>
755
+ <li> <a spec=cssom>location</a> set to the <a spec=html>base URL</a> of the <a>associated Document</a> for the <a>current global object</a> .
756
+ <li> <a>stylesheet base URL</a> set to the {{CSSStyleSheetInit/baseURL}} attribute value from <var> options</var> .
757
+ <li> No <a spec=cssom>parent CSS style sheet</a> .
758
+ <li> No <a spec=cssom>owner node</a> .
759
+ <li> No <a spec=cssom>owner CSS rule</a> .
760
+ <li> <a spec=cssom>title</a> set to the the empty string.
761
+ <li> Unset <a spec=cssom>alternate flag</a> .
762
+ <li> Set <a spec=cssom>origin-clean flag</a> .
763
+ <li> Set <a>constructed flag</a> .
764
+ <li> <a>Constructor document</a> set to the <a>associated Document</a> for the <a>current global object</a> .
765
+ </ul>
766
+ <li> If the {{CSSStyleSheetInit/media}} attribute of <var> options</var> is a string,
767
+ <a>create a MediaList object</a> from the string
768
+ and assign it as <var> sheet</var> 's <a spec=cssom>media</a> .
769
+ Otherwise, <a>serialize a media query list</a> from the attribute and then <a>create a MediaList object</a>
770
+ from the resulting string and set it as <var> sheet</var> 's <a spec=cssom>media</a> .
771
+ <li> If the {{CSSStyleSheetInit/disabled}} attribute of <var> options</var> is true,
772
+ set <var> sheet</var> 's <a spec=cssom>disabled flag</a> .
773
+ <li> Return <var> sheet</var> .
774
+ </ol>
775
+ </dd>
776
+ </dl>
777
+
747
778
<a>CSS style sheet</a> has a number of associated state items:
748
779
749
780
<dl dfn-for="CSSStyleSheet">
@@ -855,6 +886,22 @@ represents a style sheet as defined by the CSS specification. In the CSSOM a
855
886
856
887
<dt> <dfn id=concept-css-style-sheet-origin-clean-flag>origin-clean flag</dfn>
857
888
<dd> Specified when created. Either set or unset. If it is set, the API allows reading and modifying of the <a for=CSSStyleSheet>CSS rules</a> .
889
+
890
+ <dt> <dfn id=concept-css-style-sheet-constructed-flag>constructed flag</dfn> </dt>
891
+ <dd> Specified when created. Either set or unset. Unset by default.
892
+ Signifies whether this stylesheet was created by invoking the IDL-defined constructor.
893
+
894
+ <dt> <dfn id=concept-css-style-sheet-disallow-modification-flag>disallow modification flag</dfn> </dt>
895
+ <dd> Either set or unset. Unset by default. If set, modification of the stylesheet's rules is not allowed.
896
+
897
+ <dt> <dfn id=concept-css-style-sheet-constructor-document>constructor document</dfn> </dt>
898
+ <dd> Specified when created. The {{Document}} a constructed stylesheet is associated with. Null by default.
899
+ Only non-null for stylesheets that have <a>constructed flag</a> set.
900
+
901
+ <dt> <dfn id=concept-css-style-sheet-stylesheet-base-url>stylesheet base URL</dfn> </dt>
902
+ <dd> The base URL to use when resolving relative URLs in the stylesheet. Null by default.
903
+ Only non-null for stylesheets that have <a>constructed flag</a> set.
904
+
858
905
</dl>
859
906
860
907
@@ -903,10 +950,21 @@ The {{CSSStyleSheet}} interface represents a <a>CSS style sheet</a>.
903
950
<pre class=idl>
904
951
[Exposed=Window]
905
952
interface CSSStyleSheet : StyleSheet {
953
+ constructor(optional CSSStyleSheetInit options = {});
954
+
906
955
readonly attribute CSSRule? ownerRule;
907
956
[SameObject] readonly attribute CSSRuleList cssRules;
908
957
unsigned long insertRule(CSSOMString rule, optional unsigned long index = 0);
909
958
undefined deleteRule(unsigned long index);
959
+
960
+ Promise<CSSStyleSheet> replace(USVString text);
961
+ undefined replaceSync(USVString text);
962
+ };
963
+
964
+ dictionary CSSStyleSheetInit {
965
+ DOMString baseURL = null;
966
+ (MediaList or DOMString) media = "";
967
+ boolean disabled = false;
910
968
};
911
969
</pre>
912
970
@@ -933,6 +991,11 @@ The <dfn method for=CSSStyleSheet>insertRule(<var>rule</var>, <var>index</var>)<
933
991
<ol>
934
992
<li> If the <a>origin-clean flag</a> is unset,
935
993
<a>throw</a> a {{SecurityError}} exception.
994
+ <li> If the <a>disallow modification flag</a> is set, throw a {{NotAllowedError}} {{DOMException}} .
995
+ <li> Let <var> parsed rule</var> be the return value of invoking <a>parse a rule</a> with <var> rule</var> .
996
+ <li> If <var> parsed rule</var> is a syntax error, return <var> parsed rule</var> .
997
+ <li> If <var> parsed rule</var> is an <a>@import</a> rule, and the <a>constructed flag</a> or any ancestor
998
+ style sheet's <a>constructed flag</a> is set, throw a {{NotAllowedError}} {{DOMException}} .
936
999
<li> Return the result of invoking <a>insert a CSS rule</a> <var> rule</var> in the <a for=CSSStyleSheet>CSS rules</a>
937
1000
at <var> index</var> .
938
1001
</ol>
@@ -942,9 +1005,60 @@ The <dfn method for=CSSStyleSheet>deleteRule(<var>index</var>)</dfn> method must
942
1005
<ol>
943
1006
<li> If the <a>origin-clean flag</a> is unset,
944
1007
<a>throw</a> a {{SecurityError}} exception.
1008
+ <li> If the <a>disallow modification flag</a> is set, throw a {{NotAllowedError}} {{DOMException}} .
945
1009
<li> <a>Remove a CSS rule</a> in the <a for=CSSStyleSheet>CSS rules</a> at <var> index</var> .
946
1010
</ol>
947
1011
1012
+ The <dfn method for=CSSStyleSheet>replace(<a for=CSSRule>text</a>)</dfn> method must run the following steps:
1013
+ <ol>
1014
+ <li> Let <var> promise</var> be a promise.
1015
+ <li> If the <a>constructed flag</a> is not set, or the <a>disallow modification flag</a> is set, reject <var> promise</var> with a
1016
+ {{NotAllowedError}} {{DOMException}} and return <var> promise</var> .
1017
+ <li> Set the <a>disallow modification flag</a> .
1018
+ <li> <a>In parallel</a> , do these steps:
1019
+ <ol>
1020
+ <li> Let <var> rules</var> be the result of running <a>parse a list of rules</a> from <var> text</var> . If <var> rules</var> is not a list of rules
1021
+ (i.e. an error occurred during parsing), set <var> rules</var> to an empty list.
1022
+ <li> Wait for loading of <a>@import</a> rules in <var> rules|</var> and any nested <a>@import</a> s from those rules (and so on).
1023
+ <ul>
1024
+ <li> If any of them failed to load, <a>terminate</a> fetching of the remaining <a>@import</a> rules, and <a>queue a task</a> on the
1025
+ <a>networking task source</a> to perform the following steps:
1026
+ <ol>
1027
+ <li> Unset <var> sheet</var> 's <a>disallow modification flag</a> .
1028
+ <li> Reject <var> promise</var> with a {{NetworkError}} {{DOMException}} .
1029
+ </ol>
1030
+ <li> Otherwise, once all of them have finished loading, <a>queue a task</a> on the [<a>etworking task source</a> to perform the
1031
+ following steps:
1032
+ <ol>
1033
+ <li> Set <var> sheet</var> 's <a>CSS rules</a> to <var> rules</var> .
1034
+ <li> Unset <var> sheet</var> 's <a>disallow modification flag</a> .
1035
+ <li> Resolve <var> promise</var> with <var> sheet</var> .
1036
+ </ol>
1037
+ </ul>
1038
+ <p class="note">
1039
+ Note: Loading of <a>@import</a> rules should follow the rules used for fetching style sheets for <a>@import</a> rules of
1040
+ stylesheets from <link> elements, in regard to what counts as success, CSP, and Content-Type header checking.
1041
+ </p>
1042
+ <p class="note">
1043
+ Note: We will use the <a>fetch group</a> of <var> sheet</var> 's <a>constructor document</a>' s <a>relevant settings object</a> for
1044
+ <a>@import</a> rules and other (fonts, etc) loads.
1045
+ </p>
1046
+ <p class="note">
1047
+ Note: The rules regarding loading mentioned above are currently not specified rigorously anywhere.
1048
+ </p>
1049
+ <li> Return <var> promise</var> .
1050
+ </ol>
1051
+
1052
+ The <dfn method for=CSSStyleSheet>replaceSync(<a for=CSSRule>text</a>)</dfn> method must run the following steps:
1053
+ <ol>
1054
+ <li> If the <a>constructed flag</a> is not set, or the <a>disallow modification flag</a> is set, throw a {{NotAllowedError}}
1055
+ {{DOMException}} .
1056
+ <li> Let <var> rules</var> be the result of running <a>parse a list of rules</a> from <var> text</var> . If <var> rules</var> is
1057
+ not a list of rules (i.e. an error occurred during parsing), set <var> rules</var> to an empty list.
1058
+ <li> If <var> rules</var> contains one or more <a>@import</a> rules, throw a {{NotAllowedError}} {{DOMException}} .
1059
+ <li> Set <a>CSS rules</a> to <var> rules</var> .
1060
+ </ol>
1061
+
948
1062
#### Deprecated CSSStyleSheet members #### {#legacy-css-style-sheet-members}
949
1063
950
1064
Note: These members are required for compatibility with existing sites.
0 commit comments