-
Notifications
You must be signed in to change notification settings - Fork 792
Expand file tree
/
Copy pathOverview.html
More file actions
executable file
·2185 lines (1724 loc) · 95.2 KB
/
Overview.html
File metadata and controls
executable file
·2185 lines (1724 loc) · 95.2 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>Cascading Style Sheets Object Model (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 }
div.example { margin-left:1em; padding-left:1em; border-left:double; color:#222; background:#fcfcfc }
div.example table code { color:inherit }
td, th { padding:.1em }
.proposal { padding:.5em; border:solid blue }
p.note { margin-left:2em; color:green; font-style:italic; font-weight:bold }
p.note::before { content:"Note: " }
.issue { padding:.5em; border:solid red }
.issue::before { content:"Issue: " }
em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
code { color:orangered }
code :link, code :visited { color:inherit }
.members dt { margin:.5em 0 }
.members dd p:first-child { margin-top:0 }
.members dd p:last-child { margin-bottom:0 }
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet>
<body class=draft>
<div class=head>
<h1 id=cssom>Cascading Style Sheets Object Model (<abbr>CSSOM</abbr>)</h1>
<h2 class="no-num no-toc" id="">Editor's Draft 30 December 2007</h2>
<dl>
<dt>This version:
<dd><a
href="http://dev.w3.org/csswg/cssom/">http://dev.w3.org/csswg/cssom/</a></dd>
<!--<dd><a href="http://www.w3.org/TR/2007/ED-cssom-20071230/">http://www.w3.org/TR/2007/WD-cssom-20071230/</a></dd>-->
<dt>Latest version:
<dd><a href="http://www.w3.org/TR/cssom/">http://www.w3.org/TR/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>The Cascading Style Sheets Object Model defines enables developers to
find style sheets associated with a <code>Document</code> and to query and
modify rules within a CSS style sheet (through an object model).
<h2 class="no-num no-toc" id=sotd>Status of this Document</h2>
<!--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-->
<p class=issue>This document is in its very early stages. The intention is
that this specification will in due course supersede DOM Level 2 Style.
<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="#conformance"><span class=secno>2. </span>Conformance
Requirements</a>
<ul class=toc>
<li><a href="#terminology"><span class=secno>2.1. </span>Terminology</a>
</ul>
<li><a href="#style"><span class=secno>3. </span>Style Sheets and the
DOM</a>
<ul class=toc>
<li><a href="#style0"><span class=secno>3.1. </span>Style Sheet</a>
<ul class=toc>
<li><a href="#the-stylesheet"><span class=secno>3.1.1. </span>The
<code title="">StyleSheet</code> Interface</a>
<li><a href="#the-stylesheetlist"><span class=secno>3.1.2. </span>The
<code title="">StyleSheetList</code> Interface</a>
</ul>
<li><a href="#media"><span class=secno>3.2. </span>Media Queries</a>
<ul class=toc>
<li><a href="#the-medialist"><span class=secno>3.2.1. </span>The
<code>MediaList</code> Interface</a>
</ul>
<li><a href="#style1"><span class=secno>3.3. </span>Style Sheet
Types</a>
<li><a href="#accessing"><span class=secno>3.4. </span>Accessing Style
Sheets</a>
<ul class=toc>
<li><a href="#the-linkstyle"><span class=secno>3.4.1. </span>The <code
title="">LinkStyle</code> Interface</a>
<ul class=toc>
<li><a href="#requirements"><span class=secno>3.4.1.1.
</span>Requirements on specifications</a>
</ul>
<li><a href="#requirements0"><span class=secno>3.4.2.
</span>Requirements User Agents Implementing SVG</a>
<li><a href="#requirements1"><span class=secno>3.4.3.
</span>Requirements on User Agents Implementing
<code><?xml-stylesheet?></code></a>
<li><a href="#requirements2"><span class=secno>3.4.4.
</span>Requirements on User Agents Implementing the HTTP <code
title="">Link</code> Header</a>
<li><a href="#the-documentstyle"><span class=secno>3.4.5. </span>The
<code title="">DocumentStyle</code> Interface</a>
</ul>
<li><a href="#dynamically"><span class=secno>3.5. </span>Dynamically
adding new style sheets</a>
<ul class=toc>
<li><a href="#adding"><span class=secno>3.5.1. </span>Adding style
sheets</a>
<li><a href="#changing"><span class=secno>3.5.2. </span>Changing the
preferred style sheet set</a>
<li><a href="#examples"><span class=secno>3.5.3. </span>Examples</a>
</ul>
<li><a href="#interaction"><span class=secno>3.6. </span>Interaction
with the User Interface</a>
<ul class=toc>
<li><a href="#persisting"><span class=secno>3.6.1. </span>Persisting
the selected style sheet set</a>
</ul>
<li><a href="#forward"><span class=secno>3.7. </span>Forward
compatibility</a>
</ul>
<li><a href="#cascading"><span class=secno>4. </span>Cascading Style
Sheets APIs</a>
<ul class=toc>
<li><a href="#parsing"><span class=secno>4.1. </span>Parsing and
Serializing CSS Constructs</a>
<ul class=toc>
<li><a href="#css-value"><span class=secno>4.1.1. </span>CSS Value
Rules</a>
<ul class=toc>
<li><a href="#examples0"><span class=secno>4.1.1.1. </span>Examples
of the CSS Value Serializing Algorithm </a>
</ul>
<li><a href="#selectors"><span class=secno>4.1.2. </span>Selectors
Rules</a>
<li><a href="#css-page"><span class=secno>4.1.3. </span>CSS Page
Selectors Rules</a>
<li><a href="#processing"><span class=secno>4.1.4. </span>Processing
CSS Statements</a>
</ul>
<li><a href="#the-cssstylesheet"><span class=secno>4.2. </span>The <code
title="">CSSStyleSheet</code> Interface</a>
<li><a href="#the-cssrulelist"><span class=secno>4.3. </span>The <code
title="">CSSRuleList</code> Interface</a>
<li><a href="#interfaces"><span class=secno>4.4. </span>Interfaces for
CSS Statements</a>
<ul class=toc>
<li><a href="#the-cssrule"><span class=secno>4.4.1. </span>The <code
title="">CSSRule</code> Interface</a>
<ul class=toc>
<li><a href="#extensibility"><span class=secno>4.4.1.1.
</span>Extensibility</a>
</ul>
<li><a href="#the-cssstylerule"><span class=secno>4.4.2. </span>The
<code title="">CSSStyleRule</code> Interface</a>
<li><a href="#the-cssimportrule"><span class=secno>4.4.3. </span>The
<code title="">CSSImportRule</code> Interface</a>
<li><a href="#the-cssmediarule"><span class=secno>4.4.4. </span>The
<code title="">CSSMediaRule</code> Interface</a>
<li><a href="#the-cssfontfacerule"><span class=secno>4.4.5. </span>The
<code title="">CSSFontFaceRule</code> Interface</a>
<li><a href="#the-csspagerule"><span class=secno>4.4.6. </span>The
<code title="">CSSPageRule</code> Interface</a>
<li><a href="#the-cssnamespacerule"><span class=secno>4.4.7.
</span>The <code title="">CSSNamespaceRule</code> Interface</a>
</ul>
<li><a href="#accessing0"><span class=secno>4.5. </span>Accessing
declaration blocks</a>
<ul class=toc>
<li><a href="#the-elementcssinlinestyle"><span class=secno>4.5.1.
</span>The <code>ElementCSSInlineStyle</code> Interface</a>
<li><a href="#the-viewcss"><span class=secno>4.5.2. </span>The <code
title="">ViewCSS</code> Interface</a>
</ul>
<li><a href="#css-declaration-blocks"><span class=secno>4.6. </span>CSS
Declaration Blocks</a>
<ul class=toc>
<li><a href="#the-cssstyledeclaration"><span class=secno>4.6.1.
</span>The <code title="">CSSStyleDeclaration</code> Interface</a>
<li><a href="#the-css2properties"><span class=secno>4.6.2. </span>The
&
F889
lt;code title="">CSS2Properties</code> Interface</a>
</ul>
</ul>
<li class=no-num><a href="#references">References</a>
<li class=no-num><a href="#acknowledgements">Acknowledgements</a>
</ul>
<!--end-toc-->
<h2 id=introduction><span class=secno>1. </span>Introduction</h2>
<p class=issue>...
<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 where 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=conformance><span class=secno>2. </span>Conformance Requirements</h2>
<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 [<cite><a
href="#ref-rfc2119">RFC2119</a></cite>].
<p>The following conformance classes are defined (and considered) by this
specification:
<dl>
<dt><dfn id=conforming-implementation>conforming implementation</dfn>
<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.
<dt><dfn id=conforming-document>conforming document</dfn>
<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.
<dt><dfn id=conforming-authoring-tool>conforming authoring tool</dfn>
<dd>One that produces conforming documents.
</dl>
<h3 id=terminology><span class=secno>2.1. </span>Terminology</h3>
<p>A <dfn id=color>color component integer</dfn> is a base-ten integer in
the range 0-255 using digits 0-9, U+0030 to U+0039, in the shortest form
possible.
<p>A <dfn id=color0>color component separator</dfn> is a literal U+002C
COMMA followed by a U+0020 SPACE.
<p>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>.</p>
<!--
<p>The term <dfn id="whitespace">whitespace</dfn> when used in this
specification refers to the U+0020 SPACE, U+0009 <control>, U+000A
<control>, U+000D <control> and U+000C <control> (if
applicable).</p>
-->
<p>The terms <dfn id=whitespace>whitespace</dfn> and <dfn
id=style-sheet>style sheet</dfn> are used as defined in the <cite>CSS 2.1
Specification</cite> [CSS21].
<p>A <dfn id=css-style-sheet>CSS style sheet</dfn> is a <a
href="#style-sheet">style sheet</a> that conforms to the CSS syntax rules.</p>
<!-- XXX: "Cascading Style Sheet style sheet" is just a joke... -->
<h2 id=style><span class=secno>3. </span>Style Sheets and the DOM</h2>
<h3 id=style0><span class=secno>3.1. </span>Style Sheet</h3>
<p>Each document has a collection of zero or more associated style sheets.
A <dfn id=style-sheet>style sheet</dfn> is represented by an object that
implements the <code><a href="#stylesheet">StyleSheet</a></code> interface
(as described below) and has a number of properties that need to be set
when a style sheet is created. These properties can be modified over time.
<dl>
<dt><dfn id=style-sheet-type>style sheet type</dfn>
<dd>
<p>A string that is the MIME type of the style sheet. [RFC2046].
<dt><dfn id=style-sheet-location>style sheet location</dfn>
<dd>
<p>A string that is the URI of the style sheet's location or the
<code>null</code> value if the style sheet was embedded within a
document.
<dt><dfn id=style-sheet-media>style sheet media</dfn>
<dd>
<p>A string with the media queries applicable to the style sheet. When
the style sheet is created the <code>mediaText</code> attribute returned
by the <code>media</code> attribute on the style sheet <em
class=ct>must</em> be set to this string.
<dt><dfn id=style-sheet-title>style sheet title</dfn>
<dd>
<p>A string that is the title of the style sheet. A style sheet is said
to <dfn id=have-a>have a title</dfn> if this string is not the empty
string.</p>
<div class=example>
<p>The following CSS style sheets have a style sheet title that is the
empty string:</p>
<pre><style title=""> body { background:lime } </style></pre>
<pre><style> body { background:lime } </style></pre>
</div>
<dt><dfn id=style-sheet-alternate-flag>style sheet alternate flag</dfn>
<dd>
<p>...</p>
<div class=example>
<p>The following style sheets have their style sheet alternate flag set
to <i>true</i>:</p>
<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=style2>style sheet disabled flag</dfn>
<dd>
<p>...</p>
<p class=note>This flag is independent of whether the style sheet is
actually applied. That depends on the style sheet media as well, for
instance.</p>
</dl>
<p>Specifications <em class=ct>must not</em> allow the creation of <a
href="#style-sheet" title="style sheet">style sheets</a> with the <a
href="#style-sheet-alternate-flag">style sheet alternate flag</a> set to
<i>true</i> and the <a href="#style-sheet-title">style sheet title</a> set
to the empty string. In addition they <em class=ct>must not</em> allow the
creation of <a href="#style-sheet" title="style sheet">style sheets</a>
for which the user agent does not support the style sheet language.
<h4 id=the-stylesheet><span class=secno>3.1.1. </span>The <code
title="">StyleSheet</code> Interface</h4>
<pre class=idl>interface <dfn id=stylesheet>StyleSheet</dfn> {
readonly attribute DOMString <a href="#stylesheet-type" title=stylesheet-type>type</a>;
attribute boolean <a href="#stylesheet-disabled" title=stylesheet-disabled>disabled</a>;
readonly attribute Node <a href="#stylesheet-ownernode" title=stylesheet-ownernode>ownerNode</a>;
readonly attribute <a href="#stylesheet">StyleSheet</a> <a href="#stylesheet-parentstylesheet" title=stylesheet-parentstylesheet>parentStyleSheet</a>;
readonly attribute DOMString <a href="#stylesheet-href" title=stylesheet-href>href</a>;
readonly attribute DOMString <a href="#stylesheet-title" title=stylesheet-title>title</a>;
[PutForwards=mediaText] readonly attribute <a href="#medialist">MediaList</a> <a href="#stylesheet-media" title=stylesheet-media>media</a>;
};</pre>
<p class=note>CSS style sheets objects implement the <code><a
href="#cssstylesheet">CSSStyleSheet</a></code> interface which inherits
from the <code><a href="#stylesheet">StyleSheet</a></code> interface.
<p>The <dfn id=stylesheet-type
title=stylesheet-type><code>type</code></dfn> attribute, on getting, <em
class=ct>must</em> return the <a href="#style-sheet-type">style sheet
type</a>.
<p>The <dfn id=stylesheet-disabled
title=stylesheet-disabled><code>disabled</code></dfn> attribute, on
getting, <em class=ct>must</em> return <code>true</code> when the <a
href="#style2">style sheet disabled flag</a> is <i>true</i> and
<code>false</code> if that flag is <i>false</i>. On setting, it <em
class=ct>must</em> set the <a href="#style2">style sheet disabled flag</a>
to <i>true</i> if set to <code>true</code>, and set the flag to
<i>false</i> if set to <code>false</code>.
<p>The <dfn id=stylesheet-ownernode
title=stylesheet-ownernode><code>ownerNode</code></dfn> attribute, on
getting, <em class=ct>must</em> return the <code>Node</code> that
associates the style sheet with the document or it <em class=ct>must</em>
return <code>null</code> if there is no such <code>Node</code>.
<p class=note>The aformentioned <code>Node</code> has implemented the
<code><a href="#linkstyle">LinkStyle</a></code> interface.
<p>The <dfn id=stylesheet-parentstylesheet
title=stylesheet-parentstylesheet><code>parentStyleSheet</code></dfn>
attribute, on getting, <em class=ct>must</em> return the <code><a
href="#stylesheet">StyleSheet</a></code> object that caused the inclusion
of the current style sheet or <code>null</code> if there is no such
object.
<p>The <dfn id=stylesheet-href
title=stylesheet-href><code>href</code></dfn> attribute, on getting, <em
class=ct>must</em> return the <a href="#style-sheet-location">style sheet
location</a>.
<p>The <dfn id=stylesheet-title
title=stylesheet-title><code>title</code></dfn> attribute, on getting, <em
class=ct>must</em> return the <a href="#style-sheet-title">style sheet
title</a>.
<p>The <dfn id=stylesheet-media
title=stylesheet-media><code>media</code></dfn> attribute, on getting, <em
class=ct>must</em> return an object implementing the <code><a
href="#medialist">MediaList</a></code> interface that represents the <a
href="#style-sheet-media">style sheet media</a>.
<h4 id=the-stylesheetlist><span class=secno>3.1.2. </span>The <code
title="">StyleSheetList</code> Interface</h4>
<p>The object implementing this interface represents an ordered collection
of objects implementing the <code><a
href="#stylesheet">StyleSheet</a></code> interface. Items in this
collection are accessible through an integral index, starting from zero.
<pre class=idl>interface <dfn id=stylesheetlist>StyleSheetList</dfn> {
readonly attribute unsigned long <a href="#stylesheetlist-length" title=stylesheetlist-length>length</a>;
[IndexGetter] <a href="#stylesheet">StyleSheet</a> <a href="#stylesheetlist-item" title=stylesheetlist-item>item</a>(in unsigned long <var title="">index</var>);
};</pre>
<p>The <dfn id=stylesheetlist-length
title=stylesheetlist-length><code>length</code></dfn> attribute, on
getting, <em class=ct>must</em> return the number of objects currently in
the list.
<p>The <dfn id=stylesheetlist-item
title=stylesheetlist-item><code>item(<var
title="">index</var>)</code></dfn> method, when invoked, <em
class=ct>must</em> return the <code><a
href="#stylesheet">StyleSheet</a></code> object in the list given by
<var>index</var>, or <code>null</code>, if <var>index</var> is greater
than or equal to the number of items in the list.
<h3 id=media><span class=secno>3.2. </span>Media Queries</h3>
<p>creating a MediaList object?
<p>The <dfn id=parsing-media-query title="parsing media query">rules for
parsing a media query</dfn> for a given string <var>s</var> are to follow
the <span>rules for parsing a list of media queries</span> and return the
first media query those rules return, or <i>null</i> if <i>null</i> is
returned.
<p>The <dfn id=parsing-media-queries title="parsing media queries">rules
for parsing a list of media queries</dfn> ...
<p>The <dfn id=serializing-media-query title="serializing media
query">rules for serializing a media query</dfn> are as follows:
<ol>
<li>
<p>Let <var>s</var> be the empty string.
<li>
<p>If the media query is negated append the literal string
"<code>not</code>", followed by a U+0020 character, to <var>s</var>.
<li>
<p>If the media query does not contain media features append the
canonical form of the media type (as specified in the syntax) to
<var>s</var>, then return <var>s</var> and terminate this algorithm.
<li>
<p>If the media type is not <code>all</code> append the canonical form of
the media type, followed by a U+0020 character, followed by the literal
string "<code>and</code>", followed by a U+0020 character, to
<var>s</var>.
<li>
<p>Remove all duplicate media features.
<li>
<p>Convert each media feature name and media feature value to its
canonical form (as specified in the syntax).
<li>
<p>Sort the media features in lexicographical order.
<li>
<p>Then, for each media feature:</p>
<ol>
<li>Append a U+0028 (<code>(</code>) character, followed by the media
feature name, to <var>s</var>.
<li>
<p>If a value is given append a U+003A (<code>:</code>) character,
followed by a U+0020 character, followed by the media feature value,
to <var>s</var>.</p>
<li>
<p>Append a U+0029 (<code>)</code>) character to <var>s</var>.
<li>
<p>If this is not the last media feature append a U+0020 character,
followed by the literal string "<code>and</code>", followed by a
U+0020 character, to <var>s</var>.</p>
</ol>
<li>
<p>Return <var>s</var>.
</ol>
<div class=example>
<p>Here are some examples of input and output:</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>
<p>The <dfn id=serializing-media-queries title="serializing media
queries">rules for serializing a list of media queries</dfn> are as
follows:
<ol>
<li>
<p>Let <var>s</var> be the empty string.
<li>
<p>If the list is empty return <var>s</var> and terminate this algorithm.
<li>
<p>For each media query in the list:</p>
<ol>
<li>
<p>Append the result of <span title=serializing-media-query>serializing
the media query</span> to <var>s</var>.
<li>
<p>If this is not the last media query append a U+002C (<code>,</code>)
character, followed by a U+0020 character to <var>s</var>.
</ol>
<li>
<p>Return <var>s</var>.
</ol>
<p>The <dfn id=compare-media-queries title="compare media queries">rules
for comparing media queries</dfn> <var>m1</var> and <var>m2</var> are to
<a href="#serializing-media-query" title="serializing media
query">serialize</a> them both and if they are equal return <i>true</i>
and <i>false</i> otherwise.
<h4 id=the-medialist><span class=secno>3.2.1. </span>The <code><a
href="#medialist">MediaList</a></code> Interface</h4>
<div class=issue>
<p>There are several rules:</p>
<ul>
<li>No duplicates
<li>Canonicalized on getting
</ul>
</div>
<p>Objects implementing the <code><a href="#medialist">MediaList</a></code>
interface represent an ordered collection of media queries. Items in this
collection are accessible through an integral index, starting from zero.
<pre class=idl>interface <dfn id=medialist>MediaList</dfn> {
attribute DOMString <a href="#medialist-mediatext" title=medialist-mediatext>mediaText</a>;
readonly attribute unsigned long <a href="#medialist-length" title=medialist-length>length</a>;
[IndexGetter] DOMString <a href="#medialist-item" title=medialist-item>item</a>(in unsigned long <var title="">index</var>);
void <a href="#medialist-appendmedium" title=medialist-appendmedium>appendMedium</a>(in DOMString <var title="">medium</var>)
void <a href="#medialist-deletemedium" title=medialist-deletemedium>deleteMedium</a>(in DOMString <var title="">medium</var>)
};</pre>
<p>In bindings that allow it, such as ECMAScript, <code><a
href="#medialist">MediaList</a></code> objects <em class=ct>must</em>
stringify to their <code title=medialist-mediatext><a
href="#medialist-mediatext">mediaText</a></code> attribute's value.</p>
<!-- XXX Web IDL ^^ -->
<p>The <dfn id=medialist-mediatext
title=medialist-mediatext><code>mediaText</code></dfn> attribute, on
getting, <em class=ct>must</em> return a <a
href="#serializing-media-queries" title="serializing media
queries">serialization of the media qeuries</a>. On setting, setting <em
class=ct>must</em> be ignored if the return value of <a
href="#parsing-media-queries" title="parsing media queries">parsing</a>
the setted string is <i>null</i>. Otherwise the return values of parsing
<em class=ct>must</em> be used as the new media queries.</p>
<!-- XXX empty string -->
<p>The <dfn id=medialist-length
title=medialist-length><code>length</code></dfn> attribute, on getting,
<em class=ct>must</em> return the number of items in the collection.
<p>The <dfn id=medialist-item title=medialist-item><code>item(<var
title="">index</var>)</code></dfn> method, when invoked, <em
class=ct>must</em> return the item in the list given by <var>index</var>,
or <code>null</code>, if <var>index</var> is greater than or equal to the
number of items in the list.
<p>The <dfn id=medialist-appendmedium
title=medialist-appendmedium><code>appendMedium(<var
title="">medium</var>)</code></dfn> method, when invoked, <span
class=issue>...</span>.
<p>The <dfn id=medialist-deletemedium
title=medialist-deletemedium><code>deleteMedium(<var
title="">medium</var>)</code></dfn> method, when invoked, <em
class=ct>must</em> raise a <code>NOT_FOUND_ERR</code> exception when
<var>medium</var> is not in the collection. Otherwise, <var>medium</var>
<em class=ct>must</em> be removed from the collection.
<h3 id=style1><span class=secno>3.3. </span>Style Sheet Types</h3>
<p>A <dfn id=persistent-style-sheet>persistent style sheet</dfn> is a <a
href="#style-sheet">style sheet</a> whose <a
href="#style-sheet-title">style sheet title</a> is the empty string.
<p>A <dfn id=style-sheet-set>style sheet set</dfn> is a collection of one
or more <a href="#style-sheet" title="style sheet">style sheets</a> which
have an identical <a href="#style-sheet-title">style sheet title</a> that
is not the empty string.
<p>An <dfn id=alternative-style-sheet-set>alternative style sheet set</dfn>
is a <a href="#style-sheet-set">style sheet set</a> of which the <a
href="#style-sheet-alternate-flag">style sheet alternate flag</a> is
<i>true</i>.
<p class=issue><dfn id=preferred>preferred style sheet set</dfn>
<h3 id=accessing><span class=secno>3.4. </span>Accessing Style Sheets</h3>
<h4 id=the-linkstyle><span class=secno>3.4.1. </span>The <code
title="">LinkStyle</code> Interface</h4>
<p>The <code><a href="#linkstyle">LinkStyle</a></code> interface provides a
bridge between the node that takes care of the embedding or inclusion of a
<a href="#style-sheet">style sheet</a> and the <code><a
href="#stylesheet">StyleSheet</a></code> object representing the style
sheet.
<p class=note>The <code>style</code> content attribute found in various
markup languages does not embed, or represent, a style sheet.
<pre class=idl>interface <dfn id=linkstyle>LinkStyle</dfn> {
readonly attribute <a href="#stylesheet">StyleSheet</a> <a href="#linkstyle-sheet" title=linkstyle-sheet>sheet</a>;
};</pre>
<p>The <dfn id=linkstyle-sheet
title=linkstyle-sheet><code>sheet</code></dfn> attribute, on getting, <em
class=ct>must</em> return the associated <code><a
href="#stylesheet">StyleSheet</a></code> object, or <code>null</code>, if
there is no associated <code><a href="#stylesheet">StyleSheet</a></code>
object.
<div class=example>
<p>In the following HTML snippet the first HTML <code>style</code> element
has a <code>sheet</code> attribute that returns a <code><a
href="#stylesheet">StyleSheet</a></code> object representing the CSS
style sheet, but for the second <code>style</code> attribute it returns
<code>null</code>. (Assuming the user agent supports CSS
(<code>text/css</code>) and does not support ExampleSheets
(<code>text/example-sheets</code>).</p>
<pre><style type=text/css> body { background:lime } </style>
<style type=text/example-sheets> $(body).background := lime </style></pre>
</div>
<p class=note>Whether or not the node refers to a style sheet is defined by
the specification that defines the semantics of said node.
<h5 id=requirements><span class=secno>3.4.1.1. </span>Requirements on
specifications</h5>
<p>Specifications introducing new ways of associating style sheets through
the DOM <em class=ct>should</em> define which <code>Node</code>s implement
the <code><a href="#linkstyle">LinkStyle</a></code> interface. These
specifications <em class=ct>should</em> also define how the various
properties of a <a href="#style-sheet">style sheet</a> are set when <code
title=linkstyle-sheet><a href="#linkstyle-sheet">sheet</a></code> is not
<code>null</code>.
<p class=note>This specification defines it for SVG,
<code><?xml-stylesheet?></code>, and the HTTP <code>Link</code> header
for the time being.
<h4 id=requirements0><span class=secno>3.4.2. </span>Requirements User
Agents Implementing SVG</h4>
<p><em>This section applies to user agents implementing SVG.</em>
<p>SVG user agents <em class=ct>must</em> implement the <code><a
href="#linkstyle">LinkStyle</a></code> interfaces on objects implementing
the <code>SVGStyleElement</code> interface.
<p class=issue>...
<h4 id=requirements1><span class=secno>3.4.3. </span>Requirements on User
Agents Implementing <code><?xml-stylesheet?></code></h4>
<p><em>This section applies to user agents implementing
<code><?xml-stylesheet?></code>.</em>
<p>User agents supporting supporting <code><?xml-stylesheet?></code> <em
class=ct>must</em> implement the <code><a
href="#linkstyle">LinkStyle</a></code> on objects implementing
<code>ProcessingInstruction</code>.
<p>If the <code title="">target</code> DOM attribute of the
<code>ProcessingInstruction</code> is not <code>xml-stylesheet</code> then
the <code title=linkstyle-sheet><a
href="#linkstyle-sheet">sheet</a></code> attribute of the node's <code><a
href="#linkstyle">LinkStyle</a></code> interface <em class=ct>must</em>
return <code>null</code>.
<p>Else, if the <code title="">target</code> DOM attribute is
<code>xml-stylesheet</code> but the specified resource has not completed
downloading, or is not a supported style sheet language the <code
title=linkstyle-sheet><a href="#linkstyle-sheet">sheet</a></code>
attribute of the node's <code><a href="#linkstyle">LinkStyle</a></code>
interface <em class=ct>must</em> return <code>null</code>.
<p>Otherwise, a new <a href="#style-sheet">style sheet</a> <em
class=ct>must</em> be created with <a href="#style-sheet-type">style sheet
type</a> set to the canonical type, <a href="#style-sheet-location">style
sheet location</a> to the location of the style sheet, <a
href="#style-sheet-title">style sheet title</a> to the value of the <code
title="">title</code> pseudo-attribute, <a href="#style-sheet-media">style
sheet media</a> to the value of the <code title="">media</code>
pseudo-attribute, the <a href="#style-sheet-alternate-flag">style sheet
alternate flag</a> to <i>true</i> if the <code title="">alternate</code>
pseudo-attribute is "<code>yes</code>" and <i>false</i> otherwise, and the
<a href="#style2">style sheet disabled flag</a> to <i>false</i>.
<h4 id=requirements2><span class=secno>3.4.4. </span>Requirements on User
Agents Implementing the HTTP <code title="">Link</code> Header</h4>
<p class=issue>...
<h4 id=the-documentstyle><span class=secno>3.4.5. </span>The <code
title="">DocumentStyle</code> Interface</h4>
<p>Any object implementing the <code>Document</code> interface <em
class=ct>must</em> also implement the <code><a
href="#documentstyle">DocumentStyle</a></code> interface.</p>
<!-- https://bugzilla.mozilla.org/show_bug.cgi?id=200930 (FIXED) -->
<pre class=idl>interface <dfn id=documentstyle>DocumentStyle</dfn> {
readonly attribute <a href="#stylesheetlist">StyleSheetList</a> <a href="#documentstyle-stylesheets">styleSheets</a>;
attribute DOMString <a href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a>;
readonly attribute DOMString <a href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a>;
readonly attribute DOMString <a href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a>;
readonly attribute DOMStringList <a href="#documentstyle-styleSheetSets">styleSheetSets</a>;
void <a href="#documentstyle-enablestylesheetsforset" title=documentstyle-enablestylesheetsforset>enableStylesheetsForSet</a>(in DOMString <var>name</var>);
};</pre>
<!-- XXX Web IDL \/ -->
<p>For this interface, the <code>DOMString</code> values <code>null</code>
and "the empty string" are distinct and <em class=ct>must</em> not be
considered equivalent.
<dl class=members>
<dt><dfn id=documentstyle-stylesheets><code>styleSheets</code></dfn> of
type <code><a href="#stylesheetlist">StyleSheetList</a></code>
<dd>
<p>This attribute <em class=ct>must</em> be a <code><a
href="#stylesheetlist">StyleSheetList</a></code> object containing a
collection of all <code><a href="#stylesheet">StyleSheet</a></code>
objects in document order (those returned by <code
title=linkstyle-sheet><a href="#linkstyle-sheet">sheet</a></code>
attribute on objects implementing the <code><a
href="#linkstyle">LinkStyle</a></code> interface) preceded by style
sheets introduced through the HTTP <code>Link</code> header.
<dt><dfn
id=documentstyle-selectedStyleSheetSet><code>selectedStyleSheetSet</code></dfn>
of type <code>DOMString</code>
<dd>
<p>This attribute indicates which <a href="#style-sheet-set">style sheet
set</a> is in use. This attribute is <span>live</span>; changing the
<code title=stylesheet-disabled><a
href="#stylesheet-disabled">disabled</a></code> attribute on style
sheets directly will change the value of this attribute.</p>
<p>If all the sheets that are enabled and <a href="#have-a">have a
title</a> have the <em>same</em> title (by <span>case-sensitive</span>
comparisons) then the value of this attribute <em class=ct>must</em> be
exactly equal to the title of the first enabled style sheet with a title
in the <code><a href="#documentstyle-stylesheets">styleSheets</a></code>
list. Otherwise, if style sheets from different sets are enabled, then
the return value <em class=ct>must</em> be <code>null</code> (there is
no way to determine what the currently selected style sheet set is in
those conditions). Otherwise, either all style sheets that <a
href="#have-a">have a title</a> are disabled, or there are no
alternative style sheets, and <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
<em class=ct>must</em> return the empty string.</p>
<p>Setting this attribute to the <code>null</code> value <em
class=ct>must</em> have no effect.</p>
<p>Setting this attribute to a non-<code>null</code> value <em
class=ct>must</em> call <code
title=documentstyle-enablestylesheetsforset><a
href="#documentstyle-enablestylesheetsforset">enableStylesheetsForSet()</a></code>
with that value as the method's argument, and set <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code> to
that value.</p>
<p>From the DOM's perspective, all views have the same <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>.
If a user agent supports multiple views with different selected
alternative style sheets, then this attribute (and the <code><a
href="#stylesheet">StyleSheet</a></code> interface's
<code>disabled</code> attribute) <em class=ct>must</em> return and set
the value for the default view.</p>
<dt><dfn
id=documentstyle-lastStyleSheetSet><code>lastStyleSheetSet</code></dfn>
of type <code>DOMString</code>, readonly
<dd>
<p>This attribute <em class=ct>must</em> initially have the value
<code>null</code>. Its value changes when the <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
attribute is set.</p>
<dt><dfn
id=documentstyle-preferredStyleSheetSet><code>preferredStyleSheetSet</code></dfn>
of type <code>DOMString</code>, readonly
<dd>
<p>This attribute <em class=ct>must</em> be the preferred style sheet set
as set by the author. It is determined from the order of style sheet
declarations and the <code>Default-Style</code> HTTP headers. If there
is no preferred style sheet set, this attribute <em class=ct>must</em>
be the empty string. The case of this attribute <em class=ct>must</em>
exactly match the case given by the author where the preferred style
sheet is specified or implied. This attribute <em class=ct>must</em>
never be <code>null</code>.</p>
<dt><dfn id=documentstyle-styleSheetSets><code>styleSheetSets</code></dfn>
of type <code>DOMStringList</code>, readonly
<dd>
<p>This <em class=ct>must</em> be a <span>live</span> list of the
currently available <span>style sheet sets</span>. This list is
constructed by enumerating all the style sheets for this document
available to the implementation, in the order they are listed in the
<code><a href="#documentstyle-stylesheets">styleSheets</a></code>
attribute, adding the title of each style sheet <a href="#have-a"
title="have a title">with a title</a> to the list, avoiding duplicates
by dropping titles that match (<span>case-sensitively</span>) titles
that have already been added to the list.</p>
<dt><dfn id=documentstyle-enablestylesheetsforset
title=documentstyle-enablestylesheetsforset><code>enableStylesheetsForSet(<var
title="">name</var>)</code></dfn>, method
<dd>
<p>Invoking this method <em class=ct>must</em> change the <code
title=stylesheet-disabled><a
href="#stylesheet-disabled">disabled</a></code> attribute on each
<code><a href="#stylesheet">StyleSheet</a></code> object <a
href="#have-a" title="have a title">with a title</a> in the <code><a
href="#documentstyle-stylesheets">styleSheets</a></code> attribute, so
that all those whose title matches the <var title="">name</var> argument
are enabled, and all others are disabled. Title matches <em
class=ct>must</em> be <span>case-sensitive</span>.</p>
<p>Invoking this method with the empty string value <em
class=ct>must</em> disable all alternative and preferred style sheets
(but does not change the state of persistent style sheets).</p>
<p>Invoking this method with the <code>null</code> value <em
class=ct>must</em> have no effect.</p>
<!-- fact: -->
<p>Style sheets that do not <a href="#have-a">have a title</a> are never
affected by this method. This method does not change the values of the
<code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code> or
<code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
attributes.</p>
</dl>
<h3 id=dynamically><span class=secno>3.5. </span>Dynamically adding new
style sheets</h3>
<p>If new style sheets <a href="#have-a" title="have a title">with
titles</a> are added to the document, the user agent <em
class=ct>must</em> decide whether or not the style sheets should be
initially enabled or not. How this happens depends on the exact state of
the document at the time the style sheet is added, as follows.
<h4 id=adding><span class=secno>3.5.1. </span>Adding style sheets</h4>
<p>First, if the style sheet is a preferred style sheet (it <a
href="#have-a" title="have a title">has a title</a>, but is not marked as
alternative), and there is no current preferred style sheet (the <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
attribute is equal to the empty string) then the <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
attribute is set to the exact value of this style sheet's title. (This
changes the preferred style sheet set, which causes further changes
— see below.)
<p>Then, for all sheets, if any of the following is true, then the style
sheet <em class=ct>must</em> be enabled:
<ul>
<li>The style sheet has an empty title.
<li>The <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code> is
<code>null</code>, and the style sheet's title matches (by
<span>case-sensitive</span> match) the value of the <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
attribute.
<li>The style sheet's title matches (by <span>case-sensitive</span> match)
the value of the <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code>
attribute.
</ul>
<p>Otherwise, the style sheet <em class=ct>must</em> be disabled.
<h4 id=changing><span class=secno>3.5.2. </span>Changing the preferred
style sheet set</h4>