forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·4171 lines (3165 loc) · 166 KB
/
Overview.html
File metadata and controls
executable file
·4171 lines (3165 loc) · 166 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang=en-US>
<head>
<title>CSSOM</title>
<style type="text/css">
pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
pre.idl :link, pre.idl :visited { color:inherit; background:transparent }
dfn { font-weight:bold; font-style:normal }
.example { margin-left:1em; padding-left:1em; border-left:double; color:#222; background:#fcfcfc }
.example table code { color:inherit }
td, th { padding:.1em }
.note { margin-left:2em; color:green; font-style:italic; font-weight:bold }
p.note::before { content:"Note: " }
.XXX { padding:.5em; border:solid red }
p.XXX::before { content:"Issue: " }
dl.switch { padding-left:2em }
dl.switch > dt { text-indent:-1.5em }
dl.switch > dt:before { content:'\21AA'; padding:0 0.5em 0 0; display:inline-block; width:1em; text-align:right; line-height:0.5em }
m em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
code { color:orangered }
code :link, code :visited { color:inherit }
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet>
<body class=draft>
<div class=head>
<h1 id=cssom>CSSOM</h1>
<h2 class="no-num no-toc" id="">Editor's Draft 31 August 2010</h2>
<dl>
<dt>This Version:
<dd><a
href="http://www.w3.org/TR/2010/ED-cssom-20100831/">http://www.w3.org/TR/2010/ED-cssom-20100831/</a>
<dt>Latest Version:
<dd><a href="http://www.w3.org/TR/cssom/">http://www.w3.org/TR/cssom/</a>
<dt>Latest Editor's draft:
<dd><a
href="http://dev.w3.org/csswg/cssom/">http://dev.w3.org/csswg/cssom/</a>
<dt>Previous Version:
<dd><a
href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/">http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/</a>
<dt>Editor:
<dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a> (<a
href="http://www.opera.com/">Opera Software ASA</a>) <<a
href="mailto:annevk@opera.com">annevk@opera.com</a>>
</dl>
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p>CSSOM defines APIs (including generic parsing and serialization rules)
for Media Queries, Selectors, and of course CSS itself.
<h2 class="no-num no-toc" id=sotd>Status of this Document</h2>
<p class=XXX>The plan is that this document provides the successor to DOM
Level 2 Style.</p>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. It probably contains errors.
Its publication here does not imply endorsement of its contents by W3C.
<!--end-status-->
<h2 class="no-num no-toc" id=toc>Table of Contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
<ul class=toc>
<li><a href="#history"><span class=secno>1.1. </span>History</a>
</ul>
<li><a href="#infrastructure"><span class=secno>2. </span>Common
Infrastructure</a>
<ul class=toc>
<li><a href="#terminology"><span class=secno>2.1. </span>Terminology</a>
<li><a href="#conformance"><span class=secno>2.2. </span>Conformance
Requirements</a>
<li><a href="#common-serializing-idioms"><span class=secno>2.3.
</span>Common Serializing Idioms</a>
</ul>
<li><a href="#media-queries"><span class=secno>3. </span>Media Queries</a>
<ul class=toc>
<li><a href="#parsing-media-queries"><span class=secno>3.1.
</span>Parsing Media Queries</a>
<li><a href="#serializing-media-queries"><span class=secno>3.2.
</span>Serializing Media Queries</a>
<ul class=toc>
<li><a href="#serializing-media-feature-values"><span
class=secno>3.2.1. </span>Serializing Media Feature Values</a>
</ul>
<li><a href="#comparing-media-queries"><span class=secno>3.3.
</span>Comparing Media Queries</a>
<li><a href="#the-medialist-interface"><span class=secno>3.4. </span>The
<code title="">MediaList</code> Interface</a>
<li><a href="#creating-a-medialist-object"><span class=secno>3.5.
</span>Creating a <code title="">MediaList</code> Object</a>
</ul>
<li><a href="#selectors"><span class=secno>4. </span>Selectors</a>
<ul class=toc>
<li><a href="#parsing-selectors"><span class=secno>4.1. </span>Parsing
Selectors</a>
<li><a href="#serializing-selectors"><span class=secno>4.2.
</span>Serializing Selectors</a>
</ul>
<li><a href="#css"><span class=secno>5. </span>CSS</a>
<ul class=toc>
<li><a href="#style-sheet0"><span class=secno>5.1. </span>Style
Sheet</a>
<ul class=toc>
<li><a href="#the-stylesheet-interface"><span class=secno>5.1.1.
</span>The <code title="">StyleSheet</code> Interface</a>
<li><a href="#the-cssstylesheet-interface"><span class=secno>5.1.2.
</span>The <code title="">CSSStyleSheet</code> Interface</a>
</ul>
<li><a href="#style-sheet-collections"><span class=secno>5.2.
</span>Style Sheet Collections</a>
<ul class=toc>
<li><a href="#the-http-default-style-header"><span class=secno>5.2.1.
</span>The HTTP <code title="">Default-Style</code> Header</a>
<li><a href="#the-stylesheetlist-sequence"><span class=secno>5.2.2.
</span>The <code title="">StyleSheetList</code> Sequence</a>
<li><a href="#extensions-to-the-document-interface"><span
class=secno>5.2.3. </span>Extensions to the <code
title="">Document</code> Interface</a>
<li><a href="#interaction-with-the-user-interface"><span
class=secno>5.2.4. </span>Interaction with the User Interface</a>
<ul class=toc>
<li><a href="#persisting-the-selected-style-sheet-set"><span
class=secno>5.2.4.1. </span>Persisting the selected style sheet
set</a>
</ul>
<li><a href="#examples"><span class=secno>5.2.5. </span>Examples</a>
</ul>
<li><a href="#style-sheet-association"><span class=secno>5.3.
</span>Style Sheet Association</a>
<ul class=toc>
<li><a href="#the-linkstyle-interface"><span class=secno>5.3.1.
</span>The <code title="">LinkStyle</code> Interface</a>
<li><a href="#requirements-on-specifications"><span class=secno>5.3.2.
</span>Requirements on specifications</a>
<li><a href="#requirements-on-user-agents-implementing"><span
class=secno>5.3.3. </span>Requirements on User Agents Implementing
the <span title=""><code>xml-stylesheet</code> processing
instruction</span></a>
<li><a href="#requirements-on-user-agents-implementing0"><span
class=secno>5.3.4. </span>Requirements on User Agents Implementing
the HTTP <code title="">Link</code> Header</a>
</ul>
<li><a href="#css-rules"><span class=secno>5.4. </span>CSS Rules</a>
<ul class=toc>
<li><a href="#the-cssrulelist-sequence"><span class=secno>5.4.1.
</span>The <code title="">CSSRuleList</code> Sequence</a>
<li><a href="#the-cssrule-interface"><span class=secno>5.4.2.
</span>The <code title="">CSSRule</code> Interface</a>
<ul class=toc>
<li><a href="#extensibility"><span class=secno>5.4.2.1.
</span>Extensibility</a>
</ul>
<li><a href="#css-style-rule-rule-set"><span class=secno>5.4.3.
</span>CSS Style Rule (Rule Set)</a>
<li><a href="#css-import-rule"><span class=secno>5.4.4. </span>CSS
<code title="">@import</code> Rule</a>
<li><a href="#css-media-rule"><span class=secno>5.4.5. </span>CSS
<code title="">@media</code> Rule</a>
<li><a href="#css-font-face-rule"><span class=secno>5.4.6. </span>CSS
<code title="">@font-face</code> Rule</a>
<li><a href="#css-page-rule"><span class=secno>5.4.7. </span>CSS <code
title="">@page</code> Rule</a>
<li><a href="#css-namespace-rule"><span class=secno>5.4.8. </span>CSS
<code title="">@namespace</code> Rule</a>
</ul>
<li><a href="#css-declaration-blocks"><span class=secno>5.5. </span>CSS
Declaration Blocks</a>
<ul class=toc>
<li><a href="#the-cssstyledeclaration-interface"><span
class=secno>5.5.1. </span>The <code
title="">CSSStyleDeclaration</code> Interface</a>
<li><a href="#the-cssstyledeclarationvalue-interface"><span
class=secno>5.5.2. </span>The <code
title="">CSSStyleDeclarationValue</code> Interface</a>
</ul>
<li><a href="#css-values"><span class=secno>5.6. </span>CSS Values</a>
<ul class=toc>
<li><a href="#parsing-css-values"><span class=secno>5.6.1.
</span>Parsing CSS Values</a>
<li><a href="#serializing-css-values"><span class=secno>5.6.2.
</span>Serializing CSS Values</a>
<ul class=toc>
<li><a href="#examples0"><span class=secno>5.6.2.1.
</span>Examples</a>
</ul>
<li><a href="#the-csspropertyvalue-interface"><span class=secno>5.6.3.
</span>The <code title="">CSSPropertyValue</code> Interface</a>
<li><a href="#the-cssmapvalue-interface"><span class=secno>5.6.4.
</span>The <code title="">CSSMapValue</code> Interface</a>
<li><a href="#the-csspropertyvaluelist-interface"><span
class=secno>5.6.5. </span>The <code
title="">CSSPropertyValueList</code> Interface</a>
<li><a href="#the-csscomponentvalue-interface"><span
class=secno>5.6.6. </span>The <code title="">CSSComponentValue</code>
Interface</a>
</ul>
</ul>
<li><a href="#dom-access-to-css-declaration-blocks"><span class=secno>6.
</span>DOM Access to CSS Declaration Blocks</a>
<ul class=toc>
<li><a href="#the-elementcssinlinestyle-interface"><span
class=secno>6.1. </span>The <code>ElementCSSInlineStyle</code>
Interface</a>
<li><a href="#extensions-to-the-window-interface"><span class=secno>6.2.
</span>Extensions to the <code title="">Window</code> Interface</a>
</ul>
<li><a href="#resolved-values"><span class=secno>7. </span>Resolved
Values</a>
<li><a href="#iana-considerations"><span class=secno>8. </span>IANA
Considerations</a>
<ul class=toc>
<li><a href="#default-style-"><span class=secno>8.1.
</span><code>Default-Style</code> </a>
</ul>
<li class=no-num><a href="#references">References</a>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
</ul>
<!--end-toc-->
<h2 id=introduction><span class=secno>1. </span>Introduction</h2>
<p class=XXX>...
<h3 id=history><span class=secno>1.1. </span>History</h3>
<p>Several interfaces from DOM Level 2 Style <a
href="http://www.w3.org/mid/Pine.LNX.4.05.10310302134070.1173-100000@lanalana.inria.fr"
title="[CSSOM] CSSValue and related interfaces (message from the CSS
WG)">have been obsoleted</a> because they were thought to be too awkward
for frequent use. This specification no longer contains those features.
<code>DOMImplementationCSS</code> and <code>CSSCharsetRule</code> have
been removed as well as they were not deemed necessary.
<h2 id=infrastructure><span class=secno>2. </span>Common Infrastructure</h2>
<h3 id=terminology><span class=secno>2.1. </span>Terminology</h3>
<p class=XXX> <dfn id=resolve-a-url>resolve a URL</dfn>, <dfn
id=case-sensitive>case-sensitive</dfn>, <dfn
id=converted-to-ascii-lowercase>converted to ASCII lowercase</dfn>, <dfn
id=ascii-case-insensitive>ASCII case-insensitive</dfn>, <dfn
id=url>URL</dfn>, <dfn id=content-type-metadata>Content-Type
metadata</dfn>, <dfn id=supported-styling-language>supported styling
language</dfn>, <dfn
id=xml-stylesheet-processing-instruction><code>xml-stylesheet</code>
processing instruction</dfn>, <dfn id=fetch>fetch</dfn>, ...
<p>When this specification talks about object <code><var
title="">A</var></code> where <code><var title="">A</var></code> is
actually an interface, it generally means an object implementing interface
<code><var title="">A</var></code>.
<p>The term <dfn id=whitespace>whitespace</dfn> is used as defined in CSS.
<!--XXX <a href="#ref-css">[CSS]</a>-->
<h3 id=conformance><span class=secno>2.2. </span>Conformance Requirements</h3>
<p>Everything in this specification is normative except for diagrams,
examples, notes and sections marked non-normative.
<p>The key words <em class=ct>must</em>, <em class=ct>must not</em>, <em
class=ct>required</em>, <em class=ct>shall</em>, <em class=ct>shall
not</em>, <em class=ct>should</em>, <em class=ct>should not</em>, <em
class=ct>recommended</em>, <em class=ct>may</em>, and <em
class=ct>optional</em> in the normative parts of this document are to be
interpreted as described in RFC 2119 <a href="#ref-rfc2119">[RFC2119]</a>.</p>
<!-- XXX
<p>The following conformance classes are defined (and considered) by this
specification:</p>
<dl>
<dt><dfn id="conforming-implementation">conforming implementation</dfn></dt>
<dd>A user agent that implements all interfaces described in this
specification and follows all <em class="ct">must</em>-,
<em class="ct">required</em>- and <em class="ct">shall</em>-level of criteria
in this specification.</dd>
<dt><dfn id="conforming-document">conforming document</dfn></dt>
<dd>A document that follows all <em class="ct">must</em>-,
<em class="ct">required</em>- and <em class="ct">shall</em>-level of criteria
in this specification that apply to document authors.</dd>
<dt><dfn id="conforming-authoring-tool">conforming authoring tool</dfn></dt>
<dd>One that produces conforming documents.</dd>
</dl>
-->
<h3 id=common-serializing-idioms><span class=secno>2.3. </span>Common
Serializing Idioms</h3>
<p>To <dfn id=serialize-a-character>serialize a character</dfn> means to
create a string of "<code>\</code>" (U+005C), followed by the character.
<p>To <dfn id=serialize-a-character-as-code-point>serialize 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 space
(U+0020).
<p>To <dfn id=serialize-an-identifier>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 in the range U+0000 to U+001F, the character <a
href="#serialize-a-character-as-code-point" title="serialize a character
as code point">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), the character <a
href="#serialize-a-character-as-code-point" title="serialize a character
as code point">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), the character <a href="#serialize-a-character-as-code-point"
title="serialize a character as code point">escaped as code point</a>.
<li>If the character is the second character and is "<code>-</code>"
(U+002D) and the first character is "<code>-</code>" too, the <a
href="#serialize-a-character" title="serialize 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), the character
itself.
<li>Otherwise, the <a href="#serialize-a-character" title="serialize a
character">escaped</a> character.
</ul>
<p>To <dfn id=serialize-a-string>serialize a string</dfn> means to create a
string represented by '<code>"</code>' (U+0022), followed by the result of
applying the rules below to each character of the given string, followed
by '<code>"</code>' (U+0022):
<ul>
<li>If the character is in the range U+0000 to U+001F, the character <a
href="#serialize-a-character-as-code-point" title="serialize a character
as code point">escaped as code point</a>.
<li>If the character is '<code>"</code>' (U+0022) or '<code>\</code>'
(U+005C), the <a href="#serialize-a-character" title="serialize a
character">escaped</a> character.
<li>Otherwise, the character itself.
</ul>
<p class=note>"<code>'</code>" (U+0027) is not escaped because strings are
always serialized with '<code>"</code>' (U+0022).
<p>To <dfn id=serialize-a-url>serialize a URL</dfn> means to create a
string represented by "<code title="">url(</code>", followed by the <a
href="#serialize-a-string" title="serialize a string">string escaped</a>
value of the given string, followed by "<code>)</code>".
<p>To <dfn id=serialize-a-comma-separated-list>serialize a comma-separated
list</dfn> concatenate all items of the list in list order while
separating them by "<code>,</code>" (U+002C), followed by a space
(U+0020).
<p>To <dfn id=serialize-a-whitespace-separated-list>serialize a
whitespace-separated list</dfn> concatenate all items of the list in list
order while separating them a space (U+0020).
<h2 id=media-queries><span class=secno>3. </span>Media Queries</h2>
<p>Media queries are defined by the Media Queries specification. This
section defines various concepts around media queries, including their API
and serialization form.</p>
<!-- XXX ref -->
<h3 id=parsing-media-queries><span class=secno>3.1. </span>Parsing Media
Queries</h3>
<p>To <dfn id=parse-a-media-query-list>parse a media query list</dfn> for a
given string <var title="">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.</p>
<!-- XXX ref -->
<p class=note>A media query that ends up being "ignored" will turn into
"<code title="">not all</code>".
<p>To <dfn id=parse-a-media-query>parse a media query</dfn> for a given
string <var title="">s</var> means to follow the <a
href="#parse-a-media-query-list">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.
<p class=note>Again, a media query that ends up being "ignored" will turn
into "<code title="">not all</code>".
<h3 id=serializing-media-queries><span class=secno>3.2. </span>Serializing
Media Queries</h3>
<p>To <dfn id=serialize-a-media-query-list>serialize a media query
list</dfn> run these steps:
<ol>
<li>
<p>If the media query list is empty return the empty string and terminate
these steps.
<li>
<p><a href="#serialize-a-media-query" title="serialize a media
query">Serialize</a> each media query in the list of media queries, sort
them in lexicographical order, and then <a
href="#serialize-a-comma-separated-list" title="serialize a
comma-separated list">serialize</a> the list.
</ol>
<p>To <dfn id=serialize-a-media-query>serialize a media query</dfn> let
<var title="">s</var> be the empty string, run the steps below, and
finally return <var title="">s</var>:
<ol>
<li>
<p>If the media query is negated append "<code>not</code>", followed by a
space (U+0020), to <var title="">s</var>.
<li>
<p>Let <var title="">type</var> be the media type of the media query, <a
href="#serialize-an-identifier" title="serialize an
identifier">escaped</a> and <a
href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.
<li>
<p>If the media query does not contain media features append <var
title="">type</var>, to <var title="">s</var>, then return <var
title="">s</var> and terminate this algorithm.
<li>
<p>If <var title="">type</var> is not "<code>all</code>" or if the media
query is negated append <var title="">type</var>, followed by a space
(U+0020), followed by "<code>and</code>", followed by a space (U+0020),
to <var title="">s</var>.
<li>
<p>Sort the media features in lexicographical order.
<li>
<p>Then, for each media feature:</p>
<ol>
<li>Append a "<code>(</code>" (U+0028), followed by the media feature
name, <a href="#converted-to-ascii-lowercase">converted to ASCII
lowercase</a>, to <var title="">s</var>.
<li>
<p>If a value is given append a "<code>:</code>" (U+003A), followed by
a space (U+0020), followed by the <a
href="#serialize-a-media-feature-value" title="serialize a media
feature value">serialized media feature value</a>, to <var
title="">s</var>.</p>
<li>
<p>Append a "<code>)</code>" (U+0029) to <var title="">s</var>.
<li>
<p>If this is not the last media feature append a space (U+0020),
followed by "<code>and</code>", followed by a space (U+0020), to <var
title="">s</var>.
</ol>
</ol>
<div class=example>
<p>Here are some examples of input (first column) and output (second
column):</p>
<table>
<thead>
<tr>
<th>Input
<th>Output
<tbody>
<tr>
<td><code>not screen and (min-WIDTH:5px) AND (max-width:40px )</code>
<td><code>not screen and (max-width: 40px) and (min-width: 5px)</code>
<tr>
<td><code>all and (color) and (color)</code>
<td><code>(color)</code>
</table>
</div>
<h4 id=serializing-media-feature-values><span class=secno>3.2.1.
</span>Serializing Media Feature Values</h4>
<p class=XXX>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.
<p>To <dfn id=serialize-a-media-feature-value>serialize a media feature
value</dfn> named <var title="">v</var> locate <var title="">v</var> in
the first column of the table below and use the serialization format
described in the second column:
<table>
<tbody>
<tr>
<th>Media Feature
<th>Serialization
<tr>
<td><code title="">width</code>
<td>...
<tr>
<td><code title="">height</code>
<td>...
<tr>
<td><code title="">device-width</code>
<td>...
<tr>
<td><code title="">device-height</code>
<td>...
<tr>
<td><code title="">orientation</code>
<td>
<p>If the value is `<code title="">portrait</code>`: "<code
title="">portrait</code>".</p>
<p>If the value is `<code title="">landscape</code>`: "<code
title="">landscape</code>".</p>
<tr>
<td><code title="">aspect-ratio</code>
<td>...
<tr>
<td><code title="">device-aspect-ratio</code>
<td>...
<tr>
<td><code title="">color</code>
<td>...
<tr>
<td><code title="">color-index</code>
<td>...
<tr>
<td><code title="">monochrome</code>
<td>...
<tr>
<td><code title="">resolution</code>
<td>...
<tr>
<td><code title="">scan</code>
<td>
<p>If the value is `<code title="">progressive</code>`: "<code
title="">progressive</code>".</p>
<p>If the value is `<code title="">interlace</code>`: "<code
title="">interlace</code>".</p>
<tr>
<td><code title="">grid</code>
<td>...
</table>
<p>Other specifications can extend this table and vendor-prefixed media
features can have custom serialization formats as well.
<h3 id=comparing-media-queries><span class=secno>3.3. </span>Comparing
Media Queries</h3>
<p>To <dfn id=compare-media-queries>compare media queries</dfn> <var
title="">m1</var> and <var title="">m2</var> means to <a
href="#serialize-a-media-query" title="serialize a media
query">serialize</a> them both and return true if they are a <a
href="#case-sensitive">case-sensitive</a> match and false if they are not.
<h3 id=the-medialist-interface><span class=secno>3.4. </span>The <code
title="">MediaList</code> Interface</h3>
<p>An object that implements the <a
href="#medialist"><code>MediaList</code></a> interface has an associated
<dfn id=collection-of-media-queries>collection of media queries</dfn>.</p>
<!-- http://dev.w3.org/2006/webapi/WebIDL/#idl-indexed-properties -->
<pre class=idl>interface <dfn id=medialist>MediaList</dfn> {
stringifier attribute DOMString <a href="#dom-medialist-mediatext" title=dom-MediaList-mediaText>mediaText</a>;
readonly attribute unsigned long <a href="#dom-medialist-length" title=dom-MediaList-length>length</a>;
getter DOMString <a href="#dom-medialist-item" title=dom-MediaList-item>item</a>(unsigned long <var title="">index</var>);
void <a href="#dom-medialist-appendmedium" title=dom-MediaList-appendMedium>appendMedium</a>(DOMString <var title="">medium</var>);
void <a href="#dom-medialist-deletemedium" title=dom-MediaList-deleteMedium>deleteMedium</a>(DOMString <var title="">medium</var>);
};</pre>
<p>The <dfn id=dom-medialist-mediatext
title=dom-MediaList-mediaText><code>mediaText</code></dfn> attribute, on
getting, <em class=ct>must</em> return a <a
href="#serialize-a-media-query-list" title="serialize a media query
list">serialization</a> of the <a
href="#collection-of-media-queries">collection of media queries</a>.
<p>On setting the <a href="#dom-medialist-mediatext"><code
title=dom-MediaList-mediaText>mediaText</code></a> attribute these steps
<em class=ct>must</em> be run:
<ol>
<li>
<p>Empty the <a href="#collection-of-media-queries">collection of media
queries</a>.
<li>
<p>If the given value is the empty string terminate these steps.
<li>
<p>Append all the media queries as a result of <a
href="#parse-a-media-query-list" title="parse a media query
list">parsing</a> the given value to the <a
href="#collection-of-media-queries">collection of media queries</a>.
</ol>
<p>The <dfn id=dom-medialist-length
title=dom-MediaList-length><code>length</code></dfn> attribute <em
class=ct>must</em> return the number of media queries in the <a
href="#collection-of-media-queries">collection of media queries</a>.
<p>The <dfn id=dom-medialist-item title=dom-MediaList-item><code>item(<var
title="">index</var>)</code></dfn> method <em class=ct>must</em> return
the media query in the <a href="#collection-of-media-queries">collection
of media queries</a> given by <var title="">index</var>, or null, if <var
title="">index</var> is greater than or equal to the number of media
queries in the <a href="#collection-of-media-queries">collection of media
queries</a>.</p>
<!-- XXX need consistency here WebIDL? list of media queries? -->
<p>The <dfn id=dom-medialist-appendmedium
title=dom-MediaList-appendmedium><code>appendMedium(<var
title="">medium</var>)</code></dfn> method <em class=ct>must</em> run
these steps:
<ol>
<li>
<p>Let <var title="">m</var> be the result of <a
href="#parse-a-media-query" title="parse a media query">parsing</a> the
given value.
<li>
<p>If <var title="">m</var> is null terminate these steps.
<li>
<p>If <a href="#compare-media-queries" title="compare media
queries">comparing</a> <var title="">m</var> with any of the media
queries in the <a href="#collection-of-media-queries">collection of
media queries</a> returns true terminate these steps.
<li>
<p>Append <var title="">m</var> to the <a
href="#collection-of-media-queries">collection of media queries</a>.
</ol>
<p>The <dfn id=dom-medialist-deletemedium
title=dom-MediaList-deletemedium><code>deleteMedium(<var
title="">medium</var>)</code></dfn> method <em class=ct>must</em> run
these steps:
<ol>
<li>
<p>Let <var title="">m</var> be the result of <a
href="#parse-a-media-query" title="parse a media query">parsing</a> the
given value.
<li>
<p>If <var title="">m</var> is null terminate these steps.
<li>
<p>Remove any media query from the <a
href="#collection-of-media-queries">collection of media queries</a> for
which <a href="#compare-media-queries" title="compare media
queries">comparing</a> the media query with <var title="">m</var>
returns true.
</ol>
<h3 id=creating-a-medialist-object><span class=secno>3.5. </span>Creating a
<code title="">MediaList</code> Object</h3>
<p>To <dfn id=create-a-medialist-object>create a <code>MediaList</code>
object</dfn> from <var title="">s</var> run these steps:
<ol>
<li>
<p>Create a new <a href="#medialist"><code>MediaList</code></a> object.
<li>
<p>Set its <a href="#dom-medialist-mediatext"
title=dom-MediaList-mediaText>mediaText</a> attribute to <var
title="">s</var>.
<li>
<p>Return the newly created <a
href="#medialist"><code>MediaList</code></a> object.
</ol>
<h2 id=selectors><span class=secno>4. </span>Selectors</h2>
<p>Selectors are defined in the Selectors specification. This section
mainly defines how to serialize them.</p>
<!-- XXX ref -->
<!-- XXX ref universal selector etc? some are in <span> some not -->
<h3 id=parsing-selectors><span class=secno>4.1. </span>Parsing Selectors</h3>
<p>To <dfn id=parse-a-group-of-selectors>parse a group of selectors</dfn>
means to parse the value using the <code title="">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.</p>
<!-- XXX ref -->
<h3 id=serializing-selectors><span class=secno>4.2. </span>Serializing
Selectors</h3>
<!-- http://dump.testsuite.org/2009/cssom/serializing-selectors.htm -->
<p>To <dfn id=serialize-a-group-of-selectors>serialize a group of
selectors</dfn> <a href="#serialize-a-selector" title="serialize a
selector">serialize</a> each selector in the group of selectors and then
<a href="#serialize-a-comma-separated-list" title="serialize a
comma-separated list">serialize</a> the group.
<p>To <dfn id=serialize-a-selector>serialize a selector</dfn> let <var
title="">s</var> be the empty string, run the steps below for each part of
the chain of the selector, and finally return <var title="">s</var>:
<ol>
<li>
<p>If there is only one <span>simple selector</span> in the
<span>sequence of simple selectors</span> which is a <span>universal
selector</span>, append the result of <a
href="#serialize-a-simple-selector" title="serialize a simple
selector">serializing</a> the <span>universal selector</span> to <var
title="">s</var>.
<li>
<p>Otherwise, for each <span>simple selector</span> in the <span>sequence
of simple selectors</span> that is not a universal selector of which the
<span>namespace prefix</span> maps to the null namespace (not in a
namespace) or of which the <span>namespace prefix</span> maps to a
namespace that is not the <span>default namespace</span> <a
href="#serialize-a-simple-selector" title="serialize a simple
selector">serialize</a> the <span>simple selector</span> and append the
result to <var title="">s</var>.
<li>
<p>If this is not the last part of the chain of the selector append a
space (U+0020), followed by the combinator "<code>></code>",
"<code>+</code>", or "<code>~</code>" as appropriate, followed by
another space (U+0020) if the combinator was not whitespace, to <var
title="">s</var>.
<li>
<p>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-class, to <var title="">s</var>.
</ol>
<p>To <dfn id=serialize-a-simple-selector>serialize a simple selector</dfn>
let <var title="">s</var> be the empty string, run the steps below, and
finally return <var title="">s</var>:
<dl class=switch>
<dt>type selector
<dt>universal selector
<dd>
<ol>
<li>
<p>If the <span>namespace prefix</span> maps to a namespace that is not
the <span>default namespace</span> and is not the null namespace (not
in a namespace) append the <a href="#serialize-an-identifier"
title="serialize an identifier">escaped</a> <span>namespace
prefix</span>, followed by a "<code>|</code>" (U+007C) to <var
title="">s</var>.
<li>
<p>If the <span>namespace prefix</span> maps to a namespace that is the
null namespace (not in a namespace) append "<code>|</code>" (U+007C)
to <var title="">s</var>.
</li>
<!-- This includes |* -->
<li>
<p>If this is a type selector append the <a
href="#serialize-an-identifier" title="serialize an
identifier">escaped</a> element name to <var title="">s</var>.</p>
<li>
<p>If this is a universal selector append "<code>*</code> (U+002A) to
<var title="">s</var>.
</ol>
<dt>attribute selector
<dd>
<ol>
<li>
<p>Append "<code>[</code>" (U+005B) to <var title="">s</var>.
<li>
<p>If the <span>namespace prefix</span> maps to a namespace that is not
the null namespace (not in a namespace) append the <a
href="#serialize-an-identifier" title="serialize an
identifier">escaped</a> <span>namespace prefix</span>, followed by a
"<code>|</code>" (U+007C) to <var title="">s</var>.
<li>
<p>If the <span>namespace prefix</span> maps to a namespace that is the
null namespace (not in a namespace) append "<code>|</code>" (U+007C)
to <var title="">s</var>.
</li>
<!-- This includes |* -->
<li>
<p>Append the <a href="#serialize-an-identifier" title="serialize an
identifier">escaped</a> attribute name to <var title="">s</var>.
<li>
<p>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
href="#serialize-a-string" title="serialize a string">string
escaped</a> attribute value, to <var title="">s</var>.
<li>
<p>Append "<code>]</code>" (U+005D) to <var title="">s</var>.
</ol>
<dt>class selector
<dd>
<p>Append a "<code>.</code>" (U+002E), followed by the <a
href="#serialize-an-identifier" title="serialize an
identifier">escaped</a> class name to <var title="">s</var>.
<dt>ID selector
<dd>
<p>Append a "<code>#</code>" (U+0023), followed by the <a
href="#serialize-an-identifier" title="serialize an
identifier">escaped</a> ID to <var title="">s</var>.
<dt>pseudo-class
<dd>
<p>If the pseudo-class does not accept arguments append "<code>:</code>"
(U+003A), followed by the name of the pseudo-class, to <var
title="">s</var>.</p>
<p>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 determined as per below, followed by
"<code>)</code>" (U+0029), to <var title="">s</var>.</p>
<dl class=switch>
<dt><code title="">:lang()</code>
<dd>
<p>The <a href="#serialize-an-identifier" title="serialize an
identifier">escaped</a> value.
<dt><code title="">:nth-child()</code>
<dt><code title="">:nth-last-child()</code>
<dt><code title="">:nth-of-type()</code>
<dt><code title="">:nth-last-of-type()</code>
<dd>
<ol>
<li>
<p>If the value is odd let the value be "<code title="">2n+1</code>".
<li>
<p>If the value is even let the value be "<code title="">2n</code>".
<li>
<p>If <var title="">a</var> is zero let the value be <var
title="">b</var> <a href="#serialize-a-css-value-component"
title="serialize a CSS component value">serialized</a> as
<integer>.
<li>
<p>If <var title="">a</var> is one or minus one and <var
title="">b</var> is zero let the value be "<code title="">n</code>"
(U+006E).
<li>
<p>If <var title="">a</var> is one or minus one let the value be
"<code title="">n</code>" (U+006E), followed by "<code>+</code>"
(U+002B) if <var title="">b</var> is positive, followed by <var
title="">b</var> <a href="#serialize-a-css-value-component"
title="serialize a CSS component value">serialized</a> as
<integer>.
<li>
<p>If <var title="">b</var> is zero let the value be <var
title="">a</var> <a href="#serialize-a-css-value-component"
title="serialize a CSS component value">serialized</a> as
<integer>, followed by "<code title="">n</code>" (U+006E).
<li>
<p>Otherwise let the value be <var title="">a</var> <a