forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.bs
2887 lines (2289 loc) · 118 KB
/
Overview.bs
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: https://drafts.csswg.org/cssom/
TR: https://www.w3.org/TR/cssom-1/
Previous Version: https://www.w3.org/TR/2016/WD-cssom-1-20160317/
Previous Version: https://www.w3.org/TR/2013/WD-cssom-20131205/
Previous Version: https://www.w3.org/TR/2011/WD-cssom-20110712/
Previous Version: https://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/
Group: CSSWG
Status: ED
Work Status: Exploring
Shortname: cssom
Level: 1
Editor: Simon Pieters, Opera Software ASA http://www.opera.com, simonp@opera.com
Editor: Daniel Glazman, Disruptive Innovations http://disruptive-innovations.com/, daniel.glazman@disruptive-innovations.com
Former 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/
!Legacy issues list: <a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=CSSOM&resolution=---">Bugzilla</a>
Abstract: CSSOM defines APIs (including generic parsing and serialization rules) for Media Queries, Selectors, and of course CSS itself.
Ignored Terms: EmptyString, mediaText, cssText, InvalidCharacterError, SecurityError, SyntaxError, IndexSizeError, HierarchyRequestError, InvalidStateError, InvalidModificationError, NoModificationAllowedError, CORS-same-origin, group of selectors, list of css page selectors, CSSCharsetRule, ProcessingInstruction, EventTarget, EventListener, Event, EventInit, Element, Range, Node, Text, style, CSSFontFaceRule, -webkit-transform
Ignored Vars: m1, m2, camel_cased_attribute, webkit_cased_attribute, dashed_attribute
</pre>
<pre class='anchors'>
urlPrefix: https://html.spec.whatwg.org/multipage/
urlPrefix: infrastructure.html
type: dfn
text: html elements
text: tree order
text: document base url
text: content-type metadata; url: #content-type
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 loop
text: event handlers
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: rules for parsing integers
urlPrefix: xhtml.html
type: dfn
text: xml parser
urlPrefix: semantics.html
type: dfn
text: a style sheet that is blocking scripts
text: style sheet ready
urlPrefix: https://dom.spec.whatwg.org/#concept-
type: dfn
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
text: document url
urlPrefix: https://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
text: supported property indices
urlPrefix: https://encoding.spec.whatwg.org/#; spec: ENCODING
type: dfn; text: get an encoding; url: concept-encoding-get
urlPrefix: https://url.spec.whatwg.org/#concept-
type: dfn
text: URL
text: URL parser
text: URL serializer
urlPrefix: https://www.w3.org/TR/xml-stylesheet/#dt-
type: dfn; text: xml-stylesheet processing instruction
type: dfn; text: pseudo-attribute
urlPrefix: https://fetch.spec.whatwg.org/#concept-
type: dfn;
text: fetch
text: request
for: request
text: url; url: request-url
text: origin; url: request-origin
text: referrer; url: request-referrer
text: network error
</pre>
<pre class='link-defaults'>
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
spec:html5; type:element; text:style
spec:css-namespaces-3; type:dfn; text:namespace prefix
spec:dom; type:interface; text:Document
spec:html; type:dfn; text:ascii case-insensitive
spec:html; type:dfn; text:case-sensitive
spec:css-logical-props-1; type:property; text:inline-size
spec:css-variables-1; type:dfn; text:custom property
</pre>
<script src=https://resources.whatwg.org/file-issue.js async data-file-issue-url="https://github.com/w3c/csswg-drafts/issues/new?title=%5Bcssom%5D%20"></script>
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.
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><var>A</var></code> where <code><var>A</var></code> is actually an interface, it generally means an object implementing interface
<code><var>A</var></code>.
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 export>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 export>supported CSS property</dfn> refers to a CSS property that the user agent
implements, including any vendor-prefixed properties, but excluding <a>custom properties</a>. A
<a>supported CSS property</a> must be in its lowercase form for the purpose of comparisons in this
specification.
In this specification the ''::before'' and ''::after'' pseudo-elements
are assumed to exist for all elements even if no box is generated for them.
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>\</code>" (U+005C), followed by the character.
To <dfn lt="escape a character as code point|escaped as code point">escape a character as code point</dfn> means to create a
string of "<code>\</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 export>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 the REPLACEMENT CHARACTER (U+FFFD).
<li>If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F, then the character
<a>escaped as code point</a>.
<li>If the character is the first character and is in the range \[0-9]
(U+0030 to U+0039), then the character
<a>escaped as code point</a>.
<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>-</code>"
(U+002D), then the character
<a>escaped as code point</a>.
<li>If the character is the first character and is a "<code>-</code>" (U+002D),
and there is no second character,
then the <a lt="escape a character">escaped</a> character.
<li>If the character is not handled by one of the above rules and is
greater than or equal to U+0080, is "<code>-</code>" (U+002D) or
"<code>_</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 <a lt="escape a character">escaped</a>
character.
</ul>
To <dfn export>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 the REPLACEMENT CHARACTER (U+FFFD)
<a>escaped as code point</a>.
<li>If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F, the character
<a>escaped as code point</a>.
<li>If the character is '"' (U+0022) or "<code>\</code>"
(U+005C), the <a lt="escape a character">escaped</a> character.
<li>Otherwise, the character itself.
</ul>
Note: "<code>'</code>" (U+0027) is not escaped because strings
are always serialized with '"' (U+0022).
To <dfn export>serialize a URL</dfn> means to create a string represented by
"<code>url(</code>", followed by the
<a lt="serialize a string">serialization</a> of the URL as a
string, followed by "<code>)</code>".
To <dfn export>serialize a comma-separated list</dfn> concatenate all items of
the list in list order while separating them by "<code>, </code>", i.e.,
COMMA (U+002C) followed by a single SPACE (U+0020).
To <dfn export>serialize a whitespace-separated list</dfn> concatenate all
items of the list in list order while separating them by "<code> </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 export>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 media
queries that the algorithm defined there gives. <!-- XXX ref -->
Note: A media query that ends up being "ignored" will turn
into "<code>not all</code>".
To <dfn export>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>not all</code>".
Serializing Media Queries {#serializing-media-queries}
------------------------------------------------------
To
<dfn export>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><a lt="serialize a media query">Serialize</a> each media query in the list of media queries, in the same order as they appear in the list of
media queries, and then <a lt="serialize a comma-separated list">serialize</a> the list.
</ol>
To
<dfn export>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>not</code>", followed
by a single SPACE (U+0020), to <var>s</var>.
<li>Let <var>type</var> be the <a lt="serialize an identifier">serialization
as an identifier</a> of the media type of the media query,
<a>converted to ASCII lowercase</a>.
<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>all</code>" or if the
media query is negated append <var>type</var>, followed by a
single SPACE (U+0020), followed by "<code>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>(</code>" (U+0028), followed by the media feature
name, <a>converted to ASCII lowercase</a>,
to <var>s</var>.
<li>If a value is given append a "<code>:</code>" (U+003A), followed
by a single SPACE (U+0020), followed by the
<a lt="serialize a media feature value">serialized media feature value</a>,
to <var>s</var>.
<li>Append a "<code>)</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>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 export>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>portrait</code>".
If the value is ''landscape'': "<code>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>progressive</code>".
If the value is ''interlace'': "<code>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 export>compare media queries</dfn>
<var>m1</var> and <var>m2</var> means to
<a lt="serialize a media query">serialize</a> them both and
return true if they are a
<a>case-sensitive</a> match and false if they
are not.
The {{MediaList}} Interface {#the-medialist-interface}
------------------------------------------------------
An object that implements the <code>MediaList</code> interface has an associated <dfn export for=MediaList>collection of media queries</dfn>.
<pre class=idl>
[LegacyArrayClass]
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 <a>supported property indices</a> 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
<a>supported property indices</a>.
To <dfn export>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 {{MediaList/mediaText}} 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
<a lt="serialize a media query list">serialization</a> of the <a>collection of media queries</a>.
Setting the {{MediaList/mediaText}} 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 <a lt="parse a media query list">parsing</a> 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 a
<a lt="serialize a media query">serialization</a> of 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 <a lt="parse a media query">parsing</a> the given value.
<li>If <var>m</var> is null terminate these steps.
<li>If <a lt="compare media queries">comparing</a> <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 <a lt="parse a media query">parsing</a> 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
<a lt="compare media queries">comparing</a> the media query with <var>m</var> returns true.
If nothing was removed, then <a>throw</a> a {{NotFoundError}} exception.
</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 A some not -->
Parsing Selectors {#parsing-selectors}
--------------------------------------
To
<dfn export>parse a group of selectors</dfn>
means to parse the value using the <code>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 export>serialize a group of selectors</dfn>
<a lt="serialize a selector">serialize</a> each selector in the
group of selectors and then
<a lt="serialize a comma-separated list">serialize</a> a
comma-separated list of these serializations.
To <dfn export>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>compound selectors</a> which is a
<a>universal selector</a>, append the result of
<a lt="serialize a simple selector">serializing</a> the
<a>universal selector</a> to <var>s</var>.
<li>Otherwise, for each <a>simple selector</a> in the
<a>compound 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>
<a lt="serialize a simple selector">serialize</a> 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>></code>",
"<code>+</code>",
"<code>~</code>",
"<code>>></code>",
"<code>||</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>::</code>" followed by the name of the
pseudo-element, to <var>s</var>.
</ol>
To
<dfn export>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
<a lt="serialize an identifier">serialization</a> of the
<a>namespace prefix</a> as an identifier, followed by a
"<code>|</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>|</code>" (U+007C) to <var>s</var>.
<!-- This includes |* -->
<li>If this is a type selector append the
<a lt="serialize an identifier">serialization</a> of the element name
as an identifier to <var>s</var>.
<li>If this is a universal selector append "<code>*</code>" (U+002A)
to <var>s</var>.
</ol>
<dt>attribute selector
<dd>
<ol>
<li>Append "<code>[</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
<a lt="serialize an identifier">serialization</a> of the
<a>namespace prefix</a> as an identifier, followed by a
"<code>|</code>" (U+007C) to <var>s</var>.
<li>Append the <a lt="serialize an identifier">serialization</a>
of the attribute name as an identifier to <var>s</var>.
<li>If there is an attribute value specified, append
"<code>=</code>",
"<code>~=</code>",
"<code>|=</code>",
"<code>^=</code>",
"<code>$=</code>", or
"<code>*=</code>"
as appropriate (depending on the type of attribute selector), followed
by the <a lt="serialize a string">serialization</a> of the
attribute value as a string, to <var>s</var>.
<li>If the attribute selector has the case-sensitivity flag present,
append "<code> i</code>" (U+0020 U+0069) to <var>s</var>.
<li>Append "<code>]</code>" (U+005D) to
<var>s</var>.
</ol>
<dt>class selector
<dd>Append a "<code>.</code>" (U+002E), followed by the
<a lt="serialize an identifier">serialization</a> of the class name
as an identifier to <var>s</var>.
<dt>ID selector
<dd>Append a "<code>#</code>" (U+0023), followed by the
<a lt="serialize an identifier">serialization</a> of the ID
as an identifier to <var>s</var>.
<dt>pseudo-class
<dd>
If the pseudo-class does not accept arguments append
"<code>:</code>" (U+003A), followed by the name of the pseudo-class, to
<var>s</var>.
Otherwise, append "<code>:</code>" (U+003A), followed by the name of
the pseudo-class, followed by "<code>(</code>" (U+0028), followed by the
value of the pseudo-class argument(s) determined as per below, followed by
"<code>)</code>" (U+0029), to <var>s</var>.
<dl class="switch">
<dt><code>:lang()</code>
<dd>The <a lt="serialize a comma-separated list">serialization of a
comma-separated list</a> of each argument's
<a lt="serialize a string">serialization as a string</a>, preserving
relative order.
<dt><code>:nth-child()</code>
<dt><code>:nth-last-child()</code>
<dt><code>:nth-of-type()</code>
<dt><code>:nth-last-of-type()</code>
<dd>The result of serializing the value using the rules to <a>serialize an <an+b> value</a>.
<dt><code>:not()</code>
<dd>The result of serializing the value using the rules for
<a lt="serialize a group of selectors">serializing a group of selectors</a>.
</dl>
</dl>
CSS {#css-object-model}
=======================
CSS Style Sheets {#css-style-sheets}
------------------------------------
A <dfn export>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 {{CSSStyleSheet}} object. A
<a>CSS style sheet</a> has a number of associated state items:
<dl dfn-for="CSSStyleSheet">
<dt><dfn id=concept-css-style-sheet-type>type</dfn>
<dd>The literal string "<code>text/css</code>".
<dt><dfn id=concept-css-style-sheet-location>location</dfn>
<dd>Specified when created. The <a>absolute URL</a> 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 id=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 id=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 id=concept-css-style-sheet-owner-css-rule>owner CSS rule</dfn>
<dd>Specified when created. The <a for=/>CSS rule</a>
in the <a for=CSSStyleSheet>parent CSS style sheet</a>
that caused the inclusion of the <a>CSS style sheet</a> or null if
there is no associated rule.
<dt><dfn id=concept-css-style-sheet-media>media</dfn>
<dd>
Specified when created. The {{MediaList}} object associated with the
<a>CSS style sheet</a>.
If this property is specified to a string, the <a>media</a> must be set to the return value of invoking
<a>create a <code>MediaList</code> object</a> steps for that string.
If this property is specified to an attribute of the <a for=CSSStyleSheet>owner node</a>, the
<a>media</a> must be set to the return value of invoking <a>create a <code>MediaList</code> object</a> steps
for the value of that attribute. Whenever the attribute is set, changed or removed, the <a>media</a>'s
{{MediaList/mediaText}} attribute must be set to the new value of the attribute, or to null if the attribute is absent.
Note: Changing the <a>media</a>'s {{MediaList/mediaText}} attribute does not
change the corresponding attribute on the <a for=CSSStyleSheet>owner node</a>.
<dt><dfn id=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 <a>title</a> is non-empty
for the first style sheet, but is empty for the second and third style sheets.
<pre>
<style title="papaya whip">
body { background: #ffefd5; }
</style>
</pre>
<pre>
<style title="">
body { background: orange; }
</style>
</pre>
<pre>
<style>
body { background: brown; }
</style>
</pre>
</div>
If this property is specified to an attribute of the <a for=CSSStyleSheet>owner node</a>, the
<a>title</a> must be set to the value of that attribute. Whenever the attribute is set, changed or removed, the
<a>title</a> must be set to the new value of the attribute, or to the empty string if the attribute is absent.
<dt><dfn id=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 <a>CSS style sheets</a> have
their <a>alternate flag</a> set:
<pre><?xml-stylesheet alternate="yes" title="x" href="data:text/css,…"?></pre>
<pre><link rel="alternate stylesheet" title="x" href="data:text/css,…"></pre>
</div>
<dt><dfn id=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 id=concept-css-style-sheet-css-rules>CSS rules</dfn>
<dd>The CSS rules associated with the
<a>CSS style sheet</a>.
<dt><dfn id=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 <a for=CSSStyleSheet>CSS rules</a>.
</dl>
### The {{StyleSheet}} Interface ### {#the-stylesheet-interface}
The {{StyleSheet}} 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 <a for=CSSStyleSheet>type</a>.
The <dfn attribute for=StyleSheet>href</dfn> attribute must return the <a>location</a>.
The <dfn attribute for=StyleSheet>ownerNode</dfn> attribute must return the <a for=CSSStyleSheet>owner node</a>.
The <dfn attribute for=StyleSheet>parentStyleSheet</dfn> attribute must return the
<a for=CSSStyleSheet>parent CSS style sheet</a>.
The <dfn attribute for=StyleSheet>title</dfn> attribute must return the <a>title</a> or null if
<a>title</a> is the empty string.
The <dfn attribute for=StyleSheet>media</dfn> attribute must return the <a>media</a>.
The <dfn attribute for=StyleSheet>disabled</dfn> attribute, on getting, must return true if the
<a>disabled flag</a>
is set, or false otherwise. On setting, the {{StyleSheet/disabled}} attribute must set the
<a>disabled flag</a> if the new value is true, or unset the
<a>disabled flag</a> otherwise.
### The {{CSSStyleSheet}} Interface ### {#the-cssstylesheet-interface}
The {{CSSStyleSheet}} 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 <a for=CSSStyleSheet>owner CSS rule</a>.
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 <a>origin-clean flag</a> is unset,
<a>throw</a> a {{SecurityError}} exception.
<li>Return a read-only, live {{CSSRuleList}} object representing
the <a for=CSSStyleSheet>CSS rules</a>.
Note: Even though the returned {{CSSRuleList}} 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 {{CSSStyleSheet/insertRule()}} or {{CSSStyleSheet/deleteRule()}} 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 <a>origin-clean flag</a> is unset,
<a>throw</a> a {{SecurityError}} exception.
<li>Return the result of invoking <a>insert a CSS rule</a> <var>rule</var> in the <a for=CSSStyleSheet>CSS rules</a>
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 <a>origin-clean flag</a> is unset,
<a>throw</a> a {{SecurityError}} exception.
<li><a>Remove a CSS rule</a> in the <a for=CSSStyleSheet>CSS rules</a> at <var>index</var>.
</ol>
CSS Style Sheet Collections {#css-style-sheet-collections}
----------------------------------------------------------
Below various new concepts are defined that are associated with each
{{Document}} object.
Each {{Document}} has an associated list of zero or more
<a>CSS style sheets</a>, named the
<dfn>document CSS style sheets</dfn>. This is
an ordered list that contains all
<a>CSS style sheets</a> associated with the
{{Document}}, in
<a>tree order</a>, with
<a>CSS style sheets</a> created from HTTP
<code>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 <a>origin-clean flag</a> 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
<a>disabled flag</a>.
<li>If the <a>disabled flag</a> is set, terminate
these steps.
<li>If the <a>title</a> is not the empty string, the
<a>alternate flag</a> 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
<a>title</a>.
<li>
If any of the following is true unset the
<a>disabled flag</a> and terminate these steps:
<ul>
<li>The <a>title</a> is the empty string.
<li>The <a>last CSS style sheet set name</a> is null and the
<a>title</a> is a
<a>case-sensitive</a> match
for the <a>preferred CSS style sheet set name</a>.
<li>The <a>title</a> is a
<a>case-sensitive</a> match for the
<a>last CSS style sheet set name</a>.
</ul>
<li>Set the <a>disabled flag</a>.
</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 <a for=CSSStyleSheet>parent CSS style sheet</a>,
<a for=CSSStyleSheet>owner node</a> and <a for=CSSStyleSheet>owner CSS rule</a> 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 <a>title</a> is the empty string and whose
<a>alternate flag</a> is unset.
A <dfn>CSS style sheet set</dfn> is an ordered
collection of one or more <a>CSS style sheets</a>
from the <a>document CSS style sheets</a> which have an identical
<a>title</a> that is not the empty string.
A <dfn>CSS style sheet set name</dfn> is the
<a>title</a> 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 <a>disabled flag</a> 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
<a>disabled flag</a> for each <a>CSS style sheet</a>
that is in a <a>CSS style sheet set</a> and terminate these steps.
<li>Unset the <a>disabled flag</a> 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
<a>case-sensitive</a> match for
<var>name</var> and set it for all other
<a>CSS style sheets</a> in a
<a>CSS style sheet set</a>.
</ol>