-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.bs
More file actions
3257 lines (2595 loc) · 150 KB
/
Overview.bs
File metadata and controls
3257 lines (2595 loc) · 150 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class='metadata'>
Title: CSS Object Model (CSSOM)
ED: http://dev.w3.org/csswg/cssom/
TR: http://www.w3.org/TR/cssom/
Previous Version: http://www.w3.org/TR/2011/WD-cssom-20110712/
Previous Version: http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/
Group: CSSWG
Status: WD
Shortname: cssom
Level: 1
Editor: Simon Pieters, Opera Software ASA http://www.opera.com, simonp@opera.com
Editor: Glenn Adams, Cox Communications, Inc. http://www.cox.com, glenn.adams@cos.com, http://www.w3.org/wiki/User:Gadams
Former Editor: Anne van Kesteren, Opera Software ASA http://www.opera.com, annevk@annevk.nl, https://annevankesteren.nl/
Abstract: CSSOM defines APIs (including generic parsing and serialization rules) for Media Queries, Selectors, and of course CSS itself.
Ignored Terms: EmptyString, mediaText, cssText
</pre>
<pre class='anchors'>
urlPrefix: https://html.spec.whatwg.org/multipage/
urlPrefix: infrastructure.html
type: dfn; text: html elements
urlPrefix: browsers.html
type: interface; text: WindowProxy
type: dfn
text: browsing context
text: auxiliary browsing context
text: familiar with
text: same origin
urlPrefix: webappapis.html
type: dfn
text: responsible browsing context
text: incumbent settings object
text: event handler
text: event handler event type
text: event handler IDL attributes
urlPrefix: infrastructure.html
type: dfn
text: split a string on commas
text: skip whitespace
text: collect a sequence of characters
text: space character
text: converted to ascii lowercase
text: rules for parsing integers
urlPrefix: https://dom.spec.whatwg.org/#concept-
type: dfn
text: context object
text: dispatch; url: event-dispatch
text: event
text: event listener
text: quirks mode; url: document-quirks
text: fire an event; url: event-fire
text: node document
urlPrefix: https://dom.spec.whatwg.org/
type: attribute; for: Event; urlPrefix: #dom-Event-
text: type
text: isTrusted
type: dfn; text: dispatch flag
type: dfn; text: case-sensitive
urlPrefix: http://www.w3.org/TR/CSS21/visuren.html
type: dfn; text: anonymous block box; url: #anonymous-block-level
urlPrefix: http://heycam.github.io/webidl/#
type: interface; urlPrefix: idl-
text: double
text: long
type: dfn; urlPrefix: dfn-
text: converted to an IDL value
text: throw
</pre>
<pre class='link-defaults'>
spec: dom-core-ls; type: interface; text: Document
spec:css-display-3; type:value; for:display; text:table
spec:css-color-4; type:property; text:color
spec:css-position-3; type:property; text:left
</pre>
Introduction {#introduction}
============================
This document formally specifies the core features of the CSS Object Model (CSSOM). Other documents in the CSSOM family of specifications
as well as other CSS related specifications define extensions to these core features.
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to
and manipulation of style related state information and processes.
The features defined below are fundamentally based on prior specifications of the W3C DOM Working Group, primarily
[[DOM-LEVEL-2-STYLE]]. The purposes of the present document are (1) to improve on that prior work by providing
more technical specificity (so as to improve testability and interoperability), (2) to deprecate or remove certain less-widely implemented
features no longer considered to be essential in this context, and (3) to newly specify certain extensions that have been
or expected to be widely implemented.
<!--A full list of the changes to API signatures can be found in <a href="#changes-from-dom-2-style"><cite>Changes from DOM-2 Style</cite></a>.-->
Terminology {#terminology}
==========================
This specification employs certain terminology from the following documents:
<cite>DOM</cite>,
<cite>HTML</cite>,
<cite>CSS Syntax</cite>,
<cite>Encoding</cite>,
<cite>URL</cite>,
<cite>Fetch</cite>,
<cite>Associating Style Sheets with XML documents</cite>
and
<cite>XML</cite>.
[[!DOM]]
[[!HTML]]
[[!CSS3SYN]]
[[!ENCODING]]
[[!URL]]
[[!FETCH]]
[[!XML-STYLESHEET]]
[[!XML]]
When this specification talks about object
<code lt><var>A</var></code> where <code lt><var>A</var></code> is actually an interface, it generally means an object implementing interface
<code lt><var>A</var></code>.
The terms <dfn>whitespace</dfn> and <dfn>ignored</dfn> are defined in CSS. [[!CSS21]]
The terms <dfn>cascaded value</dfn>, <dfn>computed value</dfn> and <dfn>used value</dfn> are defined in CSS Cascade and Inheritance.
[[!CSS3CASCADE]]
The terms <dfn>simple selector</dfn>, <dfn>sequence of simple selectors</dfn>, <dfn>universal selector</dfn> and <dfn>group of selectors</dfn> are defined in
Selectors. [[!SELECTORS4]]
The terms <dfn>namespace prefix</dfn> and <dfn>default namespace</dfn> are defined in CSS Namespaces Module. [[!CSS3NAMESPACE]]
The term <dfn>list of CSS page selectors</dfn> refers to the comma-separated list of page selectors, as defined in CSS Paged Media Module.
[[!CSS3PAGE]]
The terms <dfn>set</dfn> and <dfn>unset</dfn> to refer to the true and
false values of binary flags or variables, respectively. These terms are also used as verbs in which case they refer to
mutating some value to make it true or false, respectively.
The term <dfn>supported styling language</dfn> refers to CSS.
Note: If another styling language becomes supported in user agents, this specification is expected to be updated as necessary.
The term <dfn>supported CSS property</dfn> refers to a CSS property that the user agent implements, and that is defined to be a case-insensitive property in
the CSS specification. A <a>supported CSS property</a> must be in its lowercase form for the purpose of comparisons this specification.
The term <dfn>author-defined CSS property</dfn> refers to <code lt>var-*</code> properties as defined in CSS Custom Properties for Cascading Variables,
and are case-sensitive. [[!CSS-VARIABLES]]
The terms <dfn>before pseudo-element</dfn> and <dfn>after pseudo-element</dfn> refer to the :before and :after pseudo-elements in CSS, except in this
specification the pseudo-elements are assumed to exist for all elements even if no box is generated for them. [[!CSS21]]
The term <dfn>environment encoding</dfn> is defined in CSS Syntax Module. [[!CSS3SYN]]
The algorithm <dfn>get an encoding</dfn> is defined in the Encoding standard. [[!ENCODING]]
The term <dfn>document's character encoding</dfn> is defined in DOM. [[!DOM]]
When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that
e.g. the author can't change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.
Unless otherwise stated, string comparisons are done in a <a>case-sensitive</a> manner.
Common Serializing Idioms {#common-serializing-idioms}
------------------------------------------------------
To <dfn>escape a character</dfn> means to create a string of
"<code lt>\</code>" (U+005C), followed by the character.
To <dfn>escape a character as code point</dfn> means to create a
string of "<code lt>\</code>" (U+005C), followed by the Unicode code point as
the smallest possible number of hexadecimal digits in the range 0-9 a-f
(U+0030 to U+0039 and U+0061 to U+0066) to represent the code point in
base 16, followed by a single SPACE (U+0020).
To <dfn>serialize an identifier</dfn> means to create a string represented
by the concatenation of, for each character of the identifier:
<ul>
<li>If the character is NULL (U+0000), then <a>throw</a> an
<code data-anolis-spec=webidl>InvalidCharacterError</code> exception and terminate these steps.
<li>If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F, then the character
<span lt="escape a character as code point">escaped as code point</span>.
<li>If the character is the first character and is in the range \[0-9]
(U+0030 to U+0039), then the character
<span lt="escape a character as code point">escaped as code point</span>.
<li>If the character is the second character and is in the range \[0-9]
(U+0030 to U+0039) and the first character is a "<code lt>-</code>"
(U+002D), then the character
<span lt="escape a character as code point">escaped as code point</span>.
<li>If the character is not handled by one of the above rules and is
greater than or equal to U+0080, is "<code lt>-</code>" (U+002D) or
"<code lt>_</code>" (U+005F), or is in one of the ranges \[0-9] (U+0030 to
U+0039), \[A-Z] (U+0041 to U+005A), or \[a-z] (U+0061 to U+007A), then the character
itself.
<li>Otherwise, the <span lt="escape a character">escaped</span>
character.
</ul>
To <dfn>serialize a string</dfn> means to create a string represented
by '"' (U+0022), followed by the result of applying the rules
below to each character of the given string, followed by
'"' (U+0022):
<ul>
<li>If the character is NULL (U+0000), then <a>throw</a> an
<code data-anolis-spec=webidl>InvalidCharacterError</code> exception and terminate these steps.
<li>If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F, the character
<span lt="escape a character as code point">escaped as code point</span>.
<li>If the character is '"' (U+0022) or "<code lt>\</code>"
(U+005C), the <span lt="escape a character">escaped</span> character.
<li>Otherwise, the character itself.
</ul>
Note: "<code lt>'</code>" (U+0027) is not escaped because strings
are always serialized with '"' (U+0022).
To <dfn>serialize a URL</dfn> means to create a string represented by
"<code lt>url(</code>", followed by the
<span lt="serialize a string">string escaped</span> value of the given
string, followed by "<code lt>)</code>".
To <dfn>serialize a comma-separated list</dfn> concatenate all items of
the list in list order while separating them by "<code lt>, </code>", i.e.,
COMMA (U+002C) followed by a single SPACE (U+0020).
To <dfn>serialize a whitespace-separated list</dfn> concatenate all
items of the list in list order while separating them by "<code lt> </code>", i.e.,
a single SPACE (U+0020).
Note: When serializing a list according to the above rules,
extraneous whitespace is not inserted prior to the first item or subsequent to
the last item. Unless otherwise specified, an empty list is serialized as the
empty string.
Media Queries {#media-queries}
==============================
Media queries are defined by the Media Queries specification. This
section defines various concepts around media queries, including their API
and serialization form.
<!-- XXX ref -->
Parsing Media Queries {#parsing-media-queries}
----------------------------------------------
To
<dfn>parse a media query list</dfn> for a
given string <var>s</var> into a media query list is defined in
the Media Queries specification. Return the list of one or more media
queries that the algorithm defined there gives. <!-- XXX ref -->
Note: A media query that ends up being "ignored" will turn
into "<code lt>not all</code>".
To
<dfn>parse a media query</dfn> for a given string
<var>s</var> means to follow the
<a>parse a media query list</a> steps and return null if more
than one media query is returned or a media query if a
single media query is returned.
Note: Again, a media query that ends up being "ignored" will
turn into "<code lt>not all</code>".
Serializing Media Queries {#serializing-media-queries}
------------------------------------------------------
To
<dfn>serialize a media query list</dfn>
run these steps:
<ol>
<li>If the media query list is empty return the empty string and
terminate these steps.
<li><span lt="serialize a media query">Serialize</span> each media query in the list of media queries, in the same order as they appear in the list of
media queries, and then <span lt="serialize a comma-separated list">serialize</span> the list.
</ol>
To
<dfn>serialize a media query</dfn> let
<var>s</var> be the empty string, run the steps below, and
finally return <var>s</var>:
<ol>
<li>If the media query is negated append "<code lt>not</code>", followed
by a single SPACE (U+0020), to <var>s</var>.
<li>Let <var>type</var> be the media type of the media query,
<span lt="serialize an identifier">escaped</span> and
<span data-anolis-spec=dom>converted to ASCII lowercase</span>.
<li>If the media query does not contain media features append
<var>type</var>, to <var>s</var>,
then return <var>s</var> and terminate this algorithm.
<li>If <var>type</var> is not "<code lt>all</code>" or if the
media query is negated append <var>type</var>, followed by a
single SPACE (U+0020), followed by "<code lt>and</code>", followed by a single SPACE
(U+0020), to <var>s</var>.
<li>Sort the media features in lexicographical order.
<li>
Then, for each media feature:
<ol>
<li>Append a "<code lt>(</code>" (U+0028), followed by the media feature
name, <span data-anolis-spec=dom>converted to ASCII lowercase</span>,
to <var>s</var>.
<li>If a value is given append a "<code lt>:</code>" (U+003A), followed
by a single SPACE (U+0020), followed by the
<span lt="serialize a media feature value">serialized media feature value</span>,
to <var>s</var>.
<li>Append a "<code lt>)</code>" (U+0029) to
<var>s</var>.
<li>If this is not the last media feature append a single SPACE (U+0020),
followed by "<code lt>and</code>", followed by a single SPACE (U+0020), to
<var>s</var>.
</ol>
</ol>
<div class="example">
Here are some examples of input (first column) and output (second
column):
<table class="complex data">
<thead>
<tr><th>Input<th>Output
<tbody>
<tr>
<td><pre>not screen and (min-WIDTH:5px) AND (max-width:40px)</pre>
<td><pre>not screen and (max-width: 40px) and (min-width: 5px)</pre>
<tr>
<td><pre>all and (color) and (color)</pre>
<td><pre>(color)</pre>
</table>
</div>
### Serializing Media Feature Values ### {#serializing-media-feature-values}
Issue: This should probably be done in terms of mapping it to
serializing CSS values as media features are defined in terms of CSS
values after all.
To <dfn>serialize a media feature value</dfn>
named <var>v</var> locate <var>v</var> in the first
column of the table below and use the serialization format described in
the second column:
<table class="complex data" spec=mediaqueries-4>
<thead>
<tr>
<th>Media Feature
<th>Serialization
<tbody>
<tr>
<td>'width'
<td>...
<tr>
<td>'height'
<td>...
<tr>
<td>'device-width'
<td>...
<tr>
<td>'device-height'
<td>...
<tr>
<td>'orientation'
<td>
If the value is ''portrait'': "<code lt>portrait</code>".
If the value is ''landscape'': "<code lt>landscape</code>".
<tr>
<td>'aspect-ratio'
<td>...
<tr>
<td>'device-aspect-ratio'
<td>...
<tr>
<td>'color'
<td>...
<tr>
<td>'color-index'
<td>...
<tr>
<td>'monochrome'
<td>...
<tr>
<td>'resolution'
<td>...
<tr>
<td>'scan'
<td>
If the value is ''progressive'': "<code lt>progressive</code>".
If the value is ''interlace'': "<code lt>interlace</code>".
<tr>
<td>'grid'
<td>...
</table>
Other specifications can extend this table and vendor-prefixed media
features can have custom serialization formats as well.
Comparing Media Queries {#comparing-media-queries}
--------------------------------------------------
To
<dfn>compare media queries</dfn>
<var>m1</var> and <var>m2</var> means to
<span lt="serialize a media query">serialize</span> them both and
return true if they are a
<span data-anolis-spec=dom>case-sensitive</span> match and false if they
are not.
The {{MediaList}} Interface {#the-medialist-interface}
------------------------------------------------------
<!--
//
// All members defined since DOM-2 Style. The only differences are:
//
// 1. addition of stringifier qualifier on mediaText
// 2. addition of getter qualifier on item
// 3. removal of raises(DOMException) from {append,delete}Medium
//
-->
An object that implements the <code>MediaList</code> interface has an associated <dfn>collection of media queries</dfn>.
<pre class=idl>[ArrayClass]
interface MediaList {
[TreatNullAs=EmptyString] stringifier attribute DOMString mediaText;
readonly attribute unsigned long length;
getter DOMString? item(unsigned long index);
void appendMedium(DOMString medium);
void deleteMedium(DOMString medium);
};</pre>
The object's <span data-anolis-spec=webidl>supported property indices</span> are the numbers in the range zero to one less than the number of media queries
in the <a>collection of media queries</a> represented by the collection. If there are no such media queries, then there are no
<span data-anolis-spec=webidl>supported property indices</span>.
To <dfn>create a <code>MediaList</code> object</dfn> with a string <var>text</var>, run the following steps:
<ol>
<li>Create a new <code>MediaList</code> object.
<li>Set its <code attribute for=MediaList>mediaText</code> attribute to <var>text</var>.
<li>Return the newly created <code>MediaList</code> object.
</ol>
The <dfn attribute for=MediaList>mediaText</dfn> attribute, on getting, must return a
<span lt="serialize a media query list">serialization</span> of the <a>collection of media queries</a>.
Setting the <code attribute for=MediaList>mediaText</code> attribute must run these steps:
<ol>
<li>Empty the <a>collection of media queries</a>.
<li>If the given value is the empty string terminate these steps.
<li>Append all the media queries as a result of <span lt="parse a media query list">parsing</span> the given
value to the <a>collection of media queries</a>.
</ol>
The <dfn method for=MediaList>item(<var>index</var>)</dfn> method must return the media query in the <a>collection of media
queries</a> given by <var>index</var>, or null, if <var>index</var> is greater than or equal to the number of media queries in the
<a>collection of media queries</a>.
The <dfn attribute for=MediaList>length</dfn> attribute must return the number of media queries in the <a>collection of media
queries</a>.
The <dfn method for=MediaList>appendMedium(<var>medium</var>)</dfn> method must run these steps:
<ol>
<li>Let <var>m</var> be the result of <span lt="parse a media query">parsing</span> the given value.
<li>If <var>m</var> is null terminate these steps.
<li>If <span lt="compare media queries">comparing</span> <var>m</var> with any of the media queries in the
<a>collection of media queries</a> returns true terminate these steps.
<li>Append <var>m</var> to the <a>collection of media queries</a>.
</ol>
The <dfn method for=MediaList>deleteMedium(<var>medium</var>)</dfn> method must run these steps:
<ol>
<li>Let <var>m</var> be the result of <span lt="parse a media query">parsing</span> the given value.
<li>If <var>m</var> is null terminate these steps.
<li>Remove any media query from the <a>collection of media queries</a> for which
<span lt="compare media queries">comparing</span> the media query with <var>m</var> returns true.
</ol>
Selectors {#selectors}
======================
Selectors are defined in the Selectors specification. This section
mainly defines how to serialize them. <!-- XXX ref -->
<!-- XXX ref universal selector etc? some are in <span> some not -->
Parsing Selectors {#parsing-selectors}
--------------------------------------
To
<dfn>parse a group of selectors</dfn>
means to parse the value using the <code lt>selectors_group</code>
production defined in the Selectors specification and return either a
group of selectors if parsing did not fail or null if parsing did
fail. <!-- XXX ref -->
Serializing Selectors {#serializing-selectors}
----------------------------------------------
<!-- http://dump.testsuite.org/2009/cssom/serializing-selectors.htm -->
To
<dfn>serialize a group of selectors</dfn>
<span lt="serialize a selector">serialize</span> each selector in the
group of selectors and then
<span lt="serialize a comma-separated list">serialize</span> the
group.
To <dfn>serialize a selector</dfn> let
<var>s</var> be the empty string, run the steps below for each
part of the chain of the selector, and finally return
<var>s</var>:
<ol>
<li>If there is only one <a>simple selector</a> in the
<a>sequence of simple selectors</a> which is a
<a>universal selector</a>, append the result of
<span lt="serialize a simple selector">serializing</span> the
<a>universal selector</a> to <var>s</var>.
<li>Otherwise, for each <a>simple selector</a> in the
<a>sequence of simple selectors</a> that is not a
universal selector of which the
<a>namespace prefix</a> maps to a namespace that is not the
<a>default namespace</a>
<span lt="serialize a simple selector">serialize</span> the
<a>simple selector</a> and append the result to
<var>s</var>.
<li>If this is not the last part of the chain of the selector append a
single SPACE (U+0020), followed by the combinator
"<code lt>></code>",
"<code lt>+</code>",
"<code lt>~</code>",
"<code lt>>></code>",
"<code lt>||</code>",
as appropriate, followed by another single SPACE (U+0020) if the combinator was
not whitespace, to <var>s</var>.
<li>If this is the last part of the chain of the selector and there is
a pseudo-element, append "<code lt>::</code>" followed by the name of the
pseudo-element, to <var>s</var>.
</ol>
To
<dfn>serialize a simple selector</dfn>
let <var>s</var> be the empty string, run the steps below, and
finally return <var>s</var>:
<dl class="switch">
<dt>type selector
<dt>universal selector
<dd>
<ol>
<li>If the <a>namespace prefix</a> maps to a namespace that is
not the <a>default namespace</a> and is not the
null namespace (not in a namespace) append the
<span lt="serialize an identifier">escaped</span>
<a>namespace prefix</a>, followed by a "<code lt>|</code>" (U+007C)
to <var>s</var>.
<li>If the <a>namespace prefix</a> maps to a namespace that is
the null namespace (not in a namespace) append
"<code lt>|</code>" (U+007C) to <var>s</var>.
<!-- This includes |* -->
<li>If this is a type selector append the
<span lt="serialize an identifier">escaped</span> element name to
<var>s</var>.
<li>If this is a universal selector append "<code lt>*</code>" (U+002A)
to <var>s</var>.
</ol>
<dt>attribute selector
<dd>
<ol>
<li>Append "<code lt>[</code>" (U+005B) to
<var>s</var>.
<li>If the <a>namespace prefix</a> maps to a namespace that is
not the null namespace (not in a namespace) append the
<span lt="serialize an identifier">escaped</span>
<a>namespace prefix</a>, followed by a "<code lt>|</code>" (U+007C)
to <var>s</var>.
<li>Append the <span lt="serialize an identifier">escaped</span>
attribute name to <var>s</var>.
<li>If there is an attribute value specified, append
"<code lt>=</code>",
"<code lt>~=</code>",
"<code lt>|=</code>",
"<code lt>^=</code>",
"<code lt>$=</code>", or
"<code lt>*=</code>"
as appropriate (depending on the type of attribute selector), followed
by the <span lt="serialize a string">string escaped</span>
attribute value, to <var>s</var>.
<li>If the attribute selector has the case-sensitivity flag present,
append "<code lt> i</code>" (U+0020 U+0069) to <var>s</var>.
<li>Append "<code lt>]</code>" (U+005D) to
<var>s</var>.
</ol>
<dt>class selector
<dd>Append a "<code lt>.</code>" (U+002E), followed by the
<span lt="serialize an identifier">escaped</span> class name to
<var>s</var>.
<dt>ID selector
<dd>Append a "<code lt>#</code>" (U+0023), followed by the
<span lt="serialize an identifier">escaped</span> ID to
<var>s</var>.
<dt>pseudo-class
<dd>
If the pseudo-class does not accept arguments append
"<code lt>:</code>" (U+003A), followed by the name of the pseudo-class, to
<var>s</var>.
Otherwise, append "<code lt>:</code>" (U+003A), followed by the name of
the pseudo-class, followed by "<code lt>(</code>" (U+0028), followed by the
value of the pseudo-class argument(s) determined as per below, followed by
"<code lt>)</code>" (U+0029), to <var>s</var>.
<dl class="switch">
<dt><code lt>:lang()</code>
<dd>The value of each argument <span lt="serialize a string">string escaped</span>,
preserving relative order,
separated by "<code lt>, </code>" (U+002C U+0020).
<dt><code lt>:nth-child()</code>
<dt><code lt>:nth-last-child()</code>
<dt><code lt>:nth-of-type()</code>
<dt><code lt>:nth-last-of-type()</code>
<dd>The result of serializing the value using the rules for <span data-anolis-spec=csssyntax>serializing <an+b></span>.
<dt><code lt>:not()</code>
<dd>The result of serializing the value using the rules for
<span lt="serialize a group of selectors">serializing a group of selectors</span>.
</dl>
</dl>
CSS {#css}
==========
CSS Style Sheets {#css-style-sheets}
------------------------------------
A <dfn>CSS style sheet</dfn> is an abstract concept that
represents a style sheet as defined by the CSS specification. In the CSSOM a
<a>CSS style sheet</a> is represented as a <code>CSSStyleSheet</code> object. A
<a>CSS style sheet</a> has a number of associated state items:
<dl>
<dt><dfn lt=concept-css-style-sheet-type>type</dfn>
<dd>The literal string "<code lt>text/css</code>".
<dt><dfn lt=concept-css-style-sheet-location>location</dfn>
<dd>Specified when created. The <span data-anolis-spec=url lt=concept-absolute-url>absolute URL</span> of the first request of the
<a>CSS style sheet</a> or null if the <a>CSS style sheet</a> was
embedded. Does not change during the lifetime of the <a>CSS style sheet</a>.
<dt><dfn lt=concept-css-style-sheet-parent-css-style-sheet>parent CSS style sheet</dfn>
<dd>Specified when created. The <a>CSS style sheet</a> that is the parent of the
<a>CSS style sheet</a> or null if there is no associated parent.
<dt><dfn lt=concept-css-style-sheet-owner-node>owner node</dfn>
<dd>Specified when created. The DOM node associated with the <a>CSS style sheet</a> or
null if there is no associated DOM node.
<dt><dfn lt=concept-css-style-sheet-owner-css-rule>owner CSS rule</dfn>
<dd>Specified when created. The <a>CSS rule</a> in the <span lt=concept-css-style-sheet-parent-css-style-sheet>parent CSS style sheet</span>
that caused the inclusion of the <a>CSS style sheet</a> or null if
there is no associated rule.
<dt><dfn lt=concept-css-style-sheet-media>media</dfn>
<dd>
Specified when created. The <code>MediaList</code> object associated with the
<a>CSS style sheet</a>.
If this property is specified to a string, the <span lt=concept-css-style-sheet-media>media</span> must be set to the return value of invoking
<span>create a <code>MediaList</code> object</span> steps for that string.
If this property is specified to an attribute of the <span lt=concept-css-style-sheet-owner-node>owner node</span>, the
<span lt=concept-css-style-sheet-media>media</span> must be set to the return value of invoking <span>create a <code>MediaList</code> object</span> steps
for the value of that attribute. Whenever the attribute is set, changed or removed, the <span lt=concept-css-style-sheet-media>media</span>'s
<code attribute for=MediaList>mediaText</code> attribute must be set to the new value of the attribute, or to null if the attribute is absent.
Note: Changing the <span lt=concept-css-style-sheet-media>media</span>'s <code attribute for=MediaList>mediaText</code> attribute does not
change the corresponding attribute on the <span lt=concept-css-style-sheet-owner-node>owner node</span>.
<dt><dfn lt=concept-css-style-sheet-title>title</dfn>
<dd>
Specified when created. The title of the <a>CSS style sheet</a>, which can be the empty string.
<div class="example">
In the following, the <span lt=concept-css-style-sheet-title>title</span> is non-empty
for the first style sheet, but is empty for the second and third style sheets.
<pre><style lt="papaya whip">
body { background: #ffefd5; }
</style></pre>
<pre><style lt="">
body { background: orange; }
</style></pre>
<pre><style>
body { background: brown; }
</style></pre>
</div>
If this property is specified to an attribute of the <span lt=concept-css-style-sheet-owner-node>owner node</span>, the
<span lt=concept-css-style-sheet-title>title</span> must be set to the value of that attribute. Whenever the attribute is set, changed or removed, the
<span lt=concept-css-style-sheet-title>title</span> must be set to the new value of the attribute, or to the empty string if the attribute is absent.
<dt><dfn lt=concept-css-style-sheet-alternate-flag>alternate flag</dfn>
<dd>
Specified when created. Either set or unset. Unset by default.
<div class="example">
The following <span lt="CSS style sheet">CSS style sheets</span> have
their <span lt=concept-css-style-sheet-alternate-flag>alternate flag</span> set:
<pre><?xml-stylesheet alternate="yes" lt="x" href="data:text/css,…"?></pre>
<pre><link rel="alternate stylesheet" lt="x" href="data:text/css,…"></pre>
</div>
<dt><dfn lt=concept-css-style-sheet-disabled-flag>disabled flag</dfn>
<dd>
Either set or unset. Unset by default.
Note: Even when unset it does not necessarily mean that the
<a>CSS style sheet</a> is actually used for rendering.
<dt><dfn lt=concept-css-style-sheet-css-rules>CSS rules</dfn>
<dd>The <span lt="CSS rule">CSS rules</span> associated with the
<a>CSS style sheet</a>.
<dt><dfn lt=concept-css-style-sheet-origin-clean-flag>origin-clean flag</dfn>
<dd>Specified when created. Either set or unset. If it is set, the API allows reading and modifying of the <span lt=concept-css-style-sheet-css-rules>CSS
rules</span>.
</dl>
### The {{StyleSheet}} Interface ### {#the-stylesheet-interface}
<!--
//
// All members defined since DOM-2 Style. Only difference
// is addition of [PutForwards=mediaText], which is presently
// not defined in CSSOM draft.
//
-->
The <code>StyleSheet</code> interface represents an abstract, base style sheet.
<pre class=idl>interface StyleSheet {
readonly attribute DOMString type;
readonly attribute DOMString? href;
readonly attribute (Element or ProcessingInstruction)? ownerNode;
readonly attribute StyleSheet? parentStyleSheet;
readonly attribute DOMString? title;
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
attribute boolean disabled;
};</pre>
The <dfn attribute for=StyleSheet>type</dfn> attribute must return the <span lt=concept-css-style-sheet-type>type</span>.
The <dfn attribute for=StyleSheet>href</dfn> attribute must return the <span lt=concept-css-style-sheet-location>location</span>.
The <dfn attribute for=StyleSheet>ownerNode</dfn> attribute must return the <span lt=concept-css-style-sheet-owner-node>owner
node</span>.
The <dfn attribute for=StyleSheet>parentStyleSheet</dfn> attribute must return the
<span lt=concept-css-style-sheet-parent-css-style-sheet>parent CSS style sheet</span>.
The <dfn attribute for=StyleSheet>title</dfn> attribute must return the <span lt=concept-css-style-sheet-title>title</span> or null if
<span lt=concept-css-style-sheet-title>title</span> is the empty string.
The <dfn attribute for=StyleSheet>media</dfn> attribute must return the <span lt=concept-css-style-sheet-media>media</span>.
The <dfn attribute for=StyleSheet>disabled</dfn> attribute, on getting, must return true if the
<span lt=concept-css-style-sheet-disabled-flag>disabled flag</span>
is set, or false otherwise. On setting, the <code attribute for=StyleSheet>disabled</code> attribute must set the
<span lt=concept-css-style-sheet-disabled-flag>disabled flag</span> if the new value is true, or unset the
<span lt=concept-css-style-sheet-disabled-flag>disabled flag</span> otherwise.
### The {{CSSStyleSheet}} Interface ### {#the-cssstylesheet-interface}
<!--
//
// All members defined since DOM-2 Style. The only differences are:
//
// 1. removal of raises(DOMException) on {insert,delete}Rule operations.
//
-->
The <code>CSSStyleSheet</code> interface represents a <a>CSS style sheet</a>.
<pre class=idl>interface CSSStyleSheet : StyleSheet {
readonly attribute CSSRule? ownerRule;
[SameObject] readonly attribute CSSRuleList cssRules;
unsigned long insertRule(DOMString rule, unsigned long index);
void deleteRule(unsigned long index);
};</pre>
The <dfn attribute for=CSSStyleSheet>ownerRule</dfn> attribute must return the <span lt=concept-css-style-sheet-owner-css-rule>owner
CSS rule</span>. If a value other than null is ever returned, then that same value must always be returned on each get access.
The <dfn attribute for=CSSStyleSheet>cssRules</dfn> attribute must follow these steps:
<ol>
<li>If the <span lt=concept-css-style-sheet-origin-clean-flag>origin-clean flag</span> is unset,
<a>throw</a> a <code data-anolis-spec=webidl>SecurityError</code> exception.
<li>Return a read-only, live <code>CSSRuleList</code> object representing
the <span lt=concept-css-style-sheet-css-rules>CSS rules</span>.
Note: Even though the returned <code>CSSRuleList</code> object is read-only (from the perspective of
client-authored script), it can nevertheless change over time due to its liveness status. For example, invoking
the <code method for=CSSStyleSheet>insertRule()</code> or <code method for=CSSStyleSheet>deleteRule()</code> methods can result in
mutations reflected in the returned object.
</ol>
The <dfn method for=CSSStyleSheet>insertRule(<var>rule</var>, <var>index</var>)</dfn> method must run the following steps:
<ol>
<li>If the <span lt=concept-css-style-sheet-origin-clean-flag>origin-clean flag</span> is unset,
<a>throw</a> a <code data-anolis-spec=webidl>SecurityError</code> exception.
<li>Return the result of invoking <a>insert a CSS rule</a> <var>rule</var> in the <span lt=concept-css-style-sheet-css-rules>CSS rules</span>
at <var>index</var>.
</ol>
The <dfn method for=CSSStyleSheet>deleteRule(<var>index</var>)</dfn> method must run the following steps:
<ol>
<li>If the <span lt=concept-css-style-sheet-origin-clean-flag>origin-clean flag</span> is unset,
<a>throw</a> a <code data-anolis-spec=webidl>SecurityError</code> exception.
<li><a>Remove a CSS rule</a> in the <span lt=concept-css-style-sheet-css-rules>CSS rules</span> at <var>index</var>.
</ol>
CSS Style Sheet Collections {#css-style-sheet-collections}
----------------------------------------------------------
Below various new concepts are defined that are associated with each
<code data-anolis-spec=dom>Document</code> object.
Each <code data-anolis-spec=dom>Document</code> has an associated list of zero or more
<span lt="CSS style sheet">CSS style sheets</span>, named the
<dfn>document CSS style sheets</dfn>. This is
an ordered list that contains all
<span lt="CSS style sheet">CSS style sheets</span> associated with the
<code data-anolis-spec=dom>Document</code>, in
<span data-anolis-spec=dom lt=concept-tree-order>tree order</span>, with
<span lt="CSS style sheet">CSS style sheets</span> created from HTTP
<code lt>Link</code> headers first, if any, in header
order.
To <dfn>create a CSS style sheet</dfn>, run these
steps:
<ol>
<li>Create a new <a>CSS style sheet</a> object and set its
properties as specified.
<li>
Then run the <a>add a CSS style sheet</a> steps for the newly created <a>CSS style sheet</a>.
<p class=warning>If the <span lt=concept-css-style-sheet-origin-clean-flag>origin-clean flag</span> is unset, this can expose information from the user's
intranet.
</ol>
To <dfn>add a CSS style sheet</dfn>, run these
steps:
<ol>
<li>Add the <a>CSS style sheet</a> to the list of
<a>document CSS style sheets</a> at the appropriate location. The
remainder of these steps deal with the
<span lt=concept-css-style-sheet-disabled-flag>disabled flag</span>.
<li>If the <span lt=concept-css-style-sheet-disabled-flag>disabled flag</span> is set, terminate
these steps.
<li>If the <span lt=concept-css-style-sheet-title>title</span> is not the empty string, the
<span lt=concept-css-style-sheet-alternate-flag>alternate flag</span> is unset, and
<a>preferred CSS style sheet set name</a> is the empty string
<a>change the preferred CSS style sheet set name</a> to the
<span lt=concept-css-style-sheet-title>title</span>.
<li>
If any of the following is true unset the
<span lt=concept-css-style-sheet-disabled-flag>disabled flag</span> and terminate these steps:
<ul>
<li>The <span lt=concept-css-style-sheet-title>title</span> is the empty string.
<li>The <a>last CSS style sheet set name</a> is null and the
<span lt=concept-css-style-sheet-title>title</span> is a
<span data-anolis-spec=dom>case-sensitive</span> match
for the <a>preferred CSS style sheet set name</a>.
<li>The <span lt=concept-css-style-sheet-title>title</span> is a
<span data-anolis-spec=dom>case-sensitive</span> match for the
<a>last CSS style sheet set name</a>.
</ul&g
1DCB
t;
<li>Set the <span lt=concept-css-style-sheet-disabled-flag>disabled flag</span>.
</ol>
To <dfn>remove a CSS style sheet</dfn>, run these steps:
<ol>
<li>Remove the <a>CSS style sheet</a> from the list of <a>document CSS style sheets</a>.
<li>Set the <a>CSS style sheet</a>'s <span lt=concept-css-style-sheet-parent-css-style-sheet>parent CSS style sheet</span>,
<span lt=concept-css-style-sheet-owner-node>owner node</span> and <span lt=concept-css-style-sheet-owner-css-rule>owner CSS rule</span> to null.
<!-- "associated CSS style sheet" is defined in terms of owner node, so we don't need to set it to null explicitly -->
<!-- XXX does anything need to happen wrt alternate style sheets? what if the last style sheet with the preferred style sheet set name is removed? -->
</ol>
A <dfn>persistent CSS style sheet</dfn> is a
<a>CSS style sheet</a> from the <a>document CSS style sheets</a>
whose <span lt=concept-css-style-sheet-title>title</span> is the empty string and whose
<span lt=concept-css-style-sheet-alternate-flag>alternate flag</span> is unset.
A <dfn>CSS style sheet set</dfn> is an ordered
collection of one or more <span lt="CSS style sheet">CSS style sheets</span>
from the <a>document CSS style sheets</a> which have an identical
<span lt=concept-css-style-sheet-title>title</span> that is not the empty
53DE
string.
A <dfn>CSS style sheet set name</dfn> is the
<span lt=concept-css-style-sheet-title>title</span> the <a>CSS style sheet set</a> has in
common.
An <dfn>enabled CSS style sheet set</dfn> is a
<a>CSS style sheet set</a> of which each <a>CSS style sheet</a> has
its <span lt=concept-css-style-sheet-disabled-flag>disabled flag</span> unset.
To <dfn>enable a CSS style sheet set</dfn>
with name <var>name</var>, run these steps:
<ol>
<li>If <var>name</var> is the empty string, set the
<span lt=concept-css-style-sheet-disabled-flag>disabled flag</span> for each <a>CSS style sheet</a>
that is in a <a>CSS style sheet set</a> and terminate these steps.
<li>Unset the <span lt=concept-css-style-sheet-disabled-flag>disabled flag</span> for each
<a>CSS style sheet</a> in a <a>CSS style sheet set</a> whose
<a>CSS style sheet set name</a> is a
<span data-anolis-spec=dom>case-sensitive</span> match for
<var>name</var> and set it for all other
<span lt="CSS style sheet">CSS style sheets</span> in a
<a>CSS style sheet set</a>.
</ol>
To <dfn>select a CSS style sheet set</dfn>
with name <var>name</var>, run these steps:
<ol>
<li><a>enable a CSS style sheet set</a> with name
<var>name</var>.
<li>Set <a>last CSS style sheet set name</a> to
<var>name</var>.