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
·2261 lines (1775 loc) · 98.7 KB
/
Copy pathOverview.html
File metadata and controls
executable file
·2261 lines (1775 loc) · 98.7 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/base" 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 <!--W3C Working Draft--> 27
December 2007</h2>
<dl>
<dt>This version:
<dd><a
href="http://www.w3.org/TR/2007/WD-cssom-20071227/">http://www.w3.org/TR/2007/WD-cssom-20071227/</a>
<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>[Sorry, the postprocessor doesn't yet have the boilerplate text for this
status]</p>
<!--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 Sheets</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="#terminology0"><span class=secno>3.2.
</span>Terminology</a>
<li><a href="#the-linkstyle"><span class=secno>3.3. </span>The
<code>LinkStyle</code> Interface</a>
<ul class=toc>
<li><a href="#requirements"><span class=secno>3.3.1.
</span>Requirements on specifications</a>
<li><a href="#requirements0"><span class=secno>3.3.2.
</span>Requirements on SVG user agents</a>
<li><a href="#ltxml-stylesheet"><span class=secno>3.3.3.
</span><code><?xml-stylesheet?></code> processing instruction</a>
</ul>
<li><a href="#the-documentstyle"><span class=secno>3.4. </span>The
<code>DocumentStyle</code> Interface</a>
<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>
<li><a href="#the-medialist"><span class=secno>3.8. </span>The
<code>MediaList</code> Interface</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-cssx"><span class=secno>4.4.3. </span>The <code
title="">CSSx</code> Interface</a>
<li><a href="#the-cssimportrule"><span class=secno>4.4.4. </span>The
<code title="">CSSImportRule</code> Interface</a>
<li><a href="#the-cssmediarule"><span class=secno>4.4.5. </span>The
<code title="">CSSMediaRule</code> Interface</a>
<li><a href="#the-cssfontfacerule"><span class=secno>4.4.6. </span>The
<code title="">CSSFontFaceRule</code> Interface</a>
<li><a href="#the-csspagerule"><span class=secno>4.4.7. </span>The
<code title="">CSSPageRule</code> Interface</a>
<li><a href="#the-cssnamespacerule"><span class=secno>4.4.8.
</span>The <code title="">CSSNamespaceRule</code> Interface</a>
</ul>
<li><a href="#accessing"><span class=secno>4.5. </span>Accessing
declaration blocks</a>
<ul class=toc>
<li><a href="#introduction0"><span class=secno>4.5.1.
</span>Introduction</a>
<li><a href="#the-elementcssinlinestyle"><span class=secno>4.5.2.
</span>The <code>ElementCSSInlineStyle</code> Interface</a>
<li><a href="#the-viewcss"><span class=secno>4.5.3. </span>The <code
title="">ViewCSS</code> Interface</a>
<li><a href="#the-documentcss"><span class=secno>4.5.4. </span>The
<code title="">DocumentCSS</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
<code title="">CSS2Properties</code> Interface</a>
</ul>
</ul>
<li><a href="#canon"><span class=secno>5. </span>Canonicalization</a>
<ul class=toc>
<li><a href="#media"><span class=secno>5.1. </span>Media queries</a>
<ul class=toc>
<li><a href="#examples1"><span class=secno>5.1.1. </span>Examples</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> has been removed as well.
<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="#style1">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 Sheets</h3>
<p>Each document has a collection of zero or more associated style sheets.
A <dfn id=style1>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=style2>style sheet type</dfn>
<dd>
<p>A string that is the MIME type of the style sheet. [RFC2046].
<dt><dfn id=style3>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=style4>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=style5>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=style6>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=style7>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>
<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="#style2">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="#style7">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="#style7">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>This <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="#style3">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="#style5">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="#style4">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.
<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>. If <var>index</var> is less than zero or greater than or
equal to the number of objects in the list then this method <em
class=ct>must</em> raise an <code>INDEX_SIZE_ERR</code> exception.</p>
<!-- XXX
<p>Each style sheet is represented by a <code>StyleSheet</code> object.
These objects can be accessed through the <code>LinkStyle</code> interface
implemented on individual <code>Node</code> objects or through the
<code>DocumentStyle</code> interface implemented on the
<code>Document</code> object. The <code>DocumentStyle</code> interface
also provides an interface for enabling alternative style sheets and
manipulating style sheet sets.</p>
-->
<h3 id=terminology0><span class=secno>3.2. </span>Terminology</h3>
<!-- XXX -->
<p>Each style sheet can have a title. A <a href="#style1">style sheet</a>
is said to <dfn id=style-sheet-title title="have a title">have a
title</dfn> if the <code>title</code> attribute on the <code><a
href="#stylesheet">StyleSheet</a></code> object is neither
<code>null</code> nor the empty string.
<p><dfn id=persistent title="persistent style sheet">Persistent style
sheets</dfn> are style sheets <a href="#style-sheet-title" title="have a
title">without a title</a>.
<p>One or more style sheets <a href="#style-sheet-title" title="have a
title">with the same title</a> (case-sensitive) form a <dfn id=style8
title="style sheet set">style sheet set</dfn>.
<h3 id=the-linkstyle><span class=secno>3.3. </span>The <code><a
href="#linkstyle">LinkStyle</a></code> Interface</h3>
<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
style sheet and the <code><a href="#stylesheet">StyleSheet</a></code>
object representing the style sheet.</p>
<!-- XXX
<p>The specification defining the node <em class="ct">should</em> say that
it implements the <code>LinkStyle</code> interface of which the
<code>sheet</code> attribute returns a <code>StyleSheet</code> object, ...
-->
<p class=note>The <code>style</code> content attribute found in various
markup languages does not embed 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.
<h4 id=requirements><span class=secno>3.3.1. </span>Requirements on
specifications</h4>
<p>Specifications introducing new ways of associating style sheets through
the DOM <em class=ct>should</em> define which objects implement the
<code><a href="#linkstyle">LinkStyle</a></code> interface. In addition,
these specifications <em class=ct>should</em> define how these objects
affect the potentially associated <code><a
href="#stylesheet">StyleSheet</a></code> object (when <code
title=linkstyle-sheet><a href="#linkstyle-sheet">sheet</a></code> is
non-<code>null</code>).
<h4 id=requirements0><span class=secno>3.3.2. </span>Requirements on SVG
user agents</h4>
<!-- Not needed for HTML. -->
<p><em>This section applies to user agents supporting SVG.</em>
<p>SVG user agents <em class=ct>must</em> implement <code><a
href="#linkstyle">LinkStyle</a></code> on objects implementing the
<code>SVGStyleElement</code> interface.
<p class=issue>...
<p class=issue>Should SVG define this instead?
<h4 id=ltxml-stylesheet><span class=secno>3.3.3.
</span><code><?xml-stylesheet?></code> processing instruction</h4>
<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> or
if the <code>href</code> pseudo-attribute of the processing instruction
does not point to an external resource or does point to an external
resource that has not yet been downloaded the <code
title=linkstyle-sheet><a href="#linkstyle-sheet">sheet</a></code>
attribute <em class=ct>must</em> be <code>null</code>. Otherwise, if the
<code title="">target</code> DOM attribute is <code>xml-stylesheet</code>,
the resource has been downloaded and the determined type is a supported
style sheet language the <code title=linkstyle-sheet><a
href="#linkstyle-sheet">sheet</a></code> attribute <em class=ct>must</em>
be a <code><a href="#stylesheet">StyleSheet</a></code> object with the
members implemented as follows:
<dl>
<dt><code title=stylesheet-type><a href="#stylesheet-type">type</a></code>
<dd>This <em class=ct>must</em> be the determined type.
<dt><code title=stylesheet-href><a href="#stylesheet-href">href</a></code>
<dd>This <em class=ct>must</em> be the value of the <code>href</code>
pseudo-attribute.
<dt><code title=stylesheet-media><a
href="#stylesheet-media">media</a></code>
<dd>This <em class=ct>must</em> be the value of the <code
title="">media</code> pseudo-attribute.
<dt><code title=stylesheet-title><a
href="#stylesheet-title">title</a></code>
<dd>This <em class=ct>must</em> be the value of the <code>title</code>
pseudo-attribute.
</dl>
<h3 id=the-documentstyle><span class=secno>3.4. </span>The <code><a
href="#documentstyle">DocumentStyle</a></code> Interface</h3>
<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.
<p>The members are defined as follows:
<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="#style8">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="#style-sheet-title">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="#style-sheet-title">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="#style-sheet-title" 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="#style-sheet-title" 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="#style-sheet-title">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="#style-sheet-title" 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="#style-sheet-title" 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>
<p>The first time the <span>preferred style sheet</span> set is set, which
is either before any alternative style sheets are seen (e.g. using a
<code>Default-Style</code> HTTP header), or is the first time a titled,
non-alternative style sheet is seen (in the absence of information to the
contrary, the first titled non-alternative sheet sets the name of the
preferred set), the <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
attribute's value <em class=ct>must</em> be set to the name of that
preferred style sheet set. This does not change the <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code>
attribute.
<p>If the user agent has the preferred style sheet set changed, for example
if it receives a <code>Default-Style</code> HTTP header after it receives
HTTP <code>Link</code> headers implying another preferred style sheet,
then the <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
attribute's value <em class=ct>must</em> be changed appropriately, and, if
the <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code> is
<code>null</code>, the <code
title=documentstyle-enablestylesheetsforset><a
href="#documentstyle-enablestylesheetsforset">enableStylesheetsForSet()</a></code>
method <em class=ct>must</em> be called with the new <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
value. (The <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code>
attribute is, again, not changed.)
<h4 id=examples><span class=secno>3.5.3. </span>Examples</h4>
<div class=example>
<p>Thus, in the following HTML snippet:</p>
<pre><link rel="alternate stylesheet" title="foo" href="a">
<link rel="alternate stylesheet" title="bar" href="b">
<script>
document.selectedStyleSheetSet = 'foo';
document.styleSheets[1].disabled = false;
</script>
<link rel="alternate stylesheet" title="foo" href="c">
<link rel="alternate stylesheet" title="bar" href="d"></pre>
<p>...the style sheets that end up enabled are style sheets "a", "b", and
"c", the <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
attribute would return null, <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code>
would return "foo", and <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
would return "".</p>
<p>Similarly, in the following HTML snippet:</p>
<pre><link rel="alternate stylesheet" title="foo" href="a">
<link rel="alternate stylesheet" title="bar" href="b">
<script>
var before = document.preferredStyleSheetSet;
document.styleSheets[1].disabled = false;
</script>
<link rel="stylesheet" title="foo" href="c">
<link rel="alternate stylesheet" title="bar" href="d">
<script>
var after = document.preferredStyleSheetSet;
</script></pre>
<p>...the "before" variable will be equal to the empty string, the "after"
variable will be equal to "foo", and style sheets "a" and "c" will be
enabled. This is the case even though the first script block sets style
sheet "b" to be enabled, because upon parsing the following
<code><link></code> element, the <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
is set and the <code title=documentstyle-enablestylesheetsforset><a
href="#documentstyle-enablestylesheetsforset">enableStylesheetsForSet()</a></code>
method is called (since <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
was never set explicitly, leaving <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code> at
<code>null</code> throughout), which changes which style sheets are
enabled and which are not.</p>
</div>
<h3 id=interaction><span class=secno>3.6. </span>Interaction with the User
Interface</h3>
<p>The user interface of Web browsers that support style sheets <em
class=ct>should</em> list the style sheet titles given in the <code><a
href="#documentstyle-styleSheetSets">styleSheetSets</a></code> list,
showing the <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
as the selected style sheet set, leaving none selected if it is
<code>null</code> or the empty string, and selecting an extra option
"Basic Page Style" (or similar) if it is the empty string and the <code><a
href="#documentstyle-preferredStyleSheetSet">preferredStyleSheetSet</a></code>
is the empty string as well.
<p>Selecting a style sheet from this list should set the <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
attribute. This (by definition) affects the <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code>
attribute.
<h4 id=persisting><span class=secno>3.6.1. </span>Persisting the selected
style sheet set</h4>
<p>If UAs persist the selected style sheet set, they should use the value
of the <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
attribute, or if that is <code>null</code>, the <code><a
href="#documentstyle-lastStyleSheetSet">lastStyleSheetSet</a></code>
attribute, when leaving the page (or at some other time) to determine the
set name to store. If that is <code>null</code> then the style sheet set
should not be persisted.
<p>When re-setting the style sheet set to the persisted value (which can
happen at any time, typically at the first time the style sheets are
needed for styling the document, after the <code><head></code> of
the document has been parsed, after any scripts that are not dependent on
computed style have executed), the style sheet set should be set by
setting the <code><a
href="#documentstyle-selectedStyleSheetSet">selectedStyleSheetSet</a></code>
attribute as if the user had selected the set manually.
<p class=note>This specification does not give any suggestions on how UAs
should decide to persist the style sheet set or whether or how to persist
the selected set across pages.
<h3 id=forward><span class=secno>3.7. </span>Forward compatibility</h3>
<p>Future versions of CSS may introduce ways of having alternative style
sheets declared at levels lower than the top level, i.e. embedded within
other style sheets. Implementations of this specification that also
support this proposed declaration of alternative style sheets are expected
to perform depth-first traversals of the <code><a
href="#documentstyle-stylesheets">styleSheets</a></code> list, not simply
enumerations of the <code><a
href="#documentstyle-stylesheets">styleSheets</a></code> list that only
contains the top level.
<p class=issue>Would that actually work?!
<h3 id=the-medialist><span class=secno>3.8. </span>The <code><a
href="#medialist">MediaList</a></code> Interface</h3>
<p class=issue>This interface depends on the Media Queries specification
which still has some issues.
<p>The <code><a href="#medialist">MediaList</a></code> object represents a
collection of media queries. It provides various ways to manipulate this
collection.
<p>In bindings that allow it, enumerating a <code><a
href="#medialist">MediaList</a></code> object <em class=ct>must</em>
enumerate through the current collection of media queries.</p>
<!--
<p>The items in the <code>MediaList</code> <em class="ct">must</em> be
accessible via an integral index, starting from 0.</p>
-->
<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.
<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>;
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>
<dl class=members>
<dt><dfn id=medialist-mediatext
title=medialist-mediatext><code>mediaText</code></dfn> of type
<code>DOMString</code>
<dd>
<p>On getting this attribute <em class=ct>must</em> be a comma-separated