-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.src.html
More file actions
executable file
·1855 lines (1378 loc) · 79.4 KB
/
Overview.src.html
File metadata and controls
executable file
·1855 lines (1378 loc) · 79.4 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 rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS]">
</head>
<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="">[LONGSTATUS] [DATE: 3 August 2002]</h2>
<dl>
<dt>This version:</dt>
<dd><a href="http://dev.w3.org/csswg/cssom/">http://dev.w3.org/csswg/cssom/</a></dd>
<!--<dd><a href="[VERSION]/">http://www.w3.org/TR/[YEAR]/WD-cssom-[CDATE]/</a></dd>-->
<dt>Latest version:</dt>
<dd><a href="http://www.w3.org/TR/cssom/">http://www.w3.org/TR/cssom/</a></dd>
<dt>Previous version:</dt>
<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></dd>
<dt>Editor:</dt>
<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>></dd>
</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).</p>
<h2 class="no-num no-toc" id="sotd">Status of this Document</h2>
<!--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.</p>
<h2 class="no-num no-toc" id="toc">Table of Contents</h2>
<!--toc-->
<h2 id="introduction">Introduction</h2>
<p class="issue">...</p>
<h3 id="history">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.</p>
<h2 id="conformance">Conformance Requirements</h2>
<p>Everything in this specification is normative except for diagrams,
examples, notes and sections marked non-normative.</p>
<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>
<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="terminology">Terminology</h3>
<p>A <dfn>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>
<p>A <dfn>color component separator</dfn> is a literal U+002C COMMA followed
by a U+0020 SPACE.</p>
<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>
<p>A <dfn id="css-style-sheet">CSS style sheet</dfn> is a <span>style
sheet</span> that conforms to the CSS syntax rules.</p>
<!-- XXX: "Cascading Style Sheet style sheet" is just a joke... -->
<h2>Style Sheets and the DOM</h2>
<h3>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>StyleSheet</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.</p>
<dl>
<dt><dfn id="style-sheet-type">style sheet type</dfn></dt>
<dd><p>A string that is the MIME type of the style sheet.
[RFC2046].</p></dd>
<dt><dfn id="style-sheet-location">style sheet location</dfn></dt>
<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.</p></dd>
<dt><dfn id="style-sheet-media">style sheet media</dfn></dt>
<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.</p></dd>
<dt><dfn id="style-sheet-title">style sheet title</dfn></dt>
<dd>
<p>A string that is the title of the style sheet. A style sheet is said
to <dfn>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>
</dd>
<dt><dfn id="style-sheet-alternate-flag">style sheet alternate
flag</dfn></dt>
<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>
</dd>
<dt><dfn>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>
</dd>
</dl>
<p>Specifications <em class="ct">must not</em> allow the creation of
<span title="style sheet">style sheets</span> with the <span>style sheet
alternate flag</span> set to <i>true</i> and the <span>style sheet
title</span> set to the empty string. In addition they <em class="ct">must
not</em> allow the creation of <span title="style sheet">style
sheets</span> for which the user agent does not support the style sheet
language.</p>
<h4>The <code title="">StyleSheet</code> Interface</h4>
<pre class="idl">interface <dfn id="stylesheet">StyleSheet</dfn> {
readonly attribute DOMString <span title="stylesheet-type">type</span>;
attribute boolean <span title="stylesheet-disabled">disabled</span>;
readonly attribute Node <span title="stylesheet-ownernode">ownerNode</span>;
readonly attribute <span>StyleSheet</span> <span title="stylesheet-parentstylesheet">parentStyleSheet</span>;
readonly attribute DOMString <span title="stylesheet-href">href</span>;
readonly attribute DOMString <span title="stylesheet-title">title</span>;
[PutForwards=mediaText] readonly attribute <span>MediaList</span> <span title="stylesheet-media">media</span>;
};</pre>
<p class="note">CSS style sheets objects implement the
<code>CSSStyleSheet</code> interface which inherits from the
<code>StyleSheet</code> interface.</p>
<p>The
<dfn id="stylesheet-type" title="stylesheet-type"><code>type</code></dfn>
attribute, on getting, <em class="ct">must</em> return the <span>style
sheet type</span>.</p>
<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 <span>style sheet disabled flag</span> 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 <span>style sheet disabled flag</span> 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>
<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>
<p class="note">The aformentioned <code>Node</code> has implemented the
<code>LinkStyle</code> interface.</p>
<p>The
<dfn id="stylesheet-parentstylesheet" title="stylesheet-parentstylesheet"><code>parentStyleSheet</code></dfn>
attribute, on getting, <em class="ct">must</em> return the
<code>StyleSheet</code> object that caused the inclusion of the current
style sheet or <code>null</code> if there is no such object.</p>
<p>The
<dfn id="stylesheet-href" title="stylesheet-href"><code>href</code></dfn>
attribute, on getting, <em class="ct">must</em> return the <span>style
sheet location</span>.</p>
<p>The
<dfn id="stylesheet-title" title="stylesheet-title"><code>title</code></dfn>
attribute, on getting, <em class="ct">must</em> return the <span>style
sheet title</span>.</p>
<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>MediaList</code> interface that represents the
<span>style sheet media</span>.</p>
<h4>The <code title="">StyleSheetList</code> Interface</h4>
<p>The object implementing this interface represents an ordered collection
of objects implementing the <code>StyleSheet</code> interface. Items in
this collection are accessible through an integral index, starting from
zero.</p>
<pre class="idl">interface <dfn>StyleSheetList</dfn> {
readonly attribute unsigned long <span title="stylesheetlist-length">length</span>;
[IndexGetter] <span>StyleSheet</span> <span title="stylesheetlist-item">item</span>(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>
<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>StyleSheet</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.</p>
<h3>Media Queries</h3>
<p>creating a MediaList object?</p>
<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>
<p>The <dfn id="parsing-media-queries" title="parsing media queries">rules for parsing a list of media queries</dfn> ...</p>
<p>The
<dfn id="serializing-media-query" title="serializing media query">rules
for serializing a media query</dfn> are as follows:</p>
<ol>
<li><p>Let <var>s</var> be the empty string.</p></li>
<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>.</p></li>
<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.</p></li>
<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>.</p></li>
<li><p>Remove all duplicate media features.</p></li>
<li><p>Convert each media feature name and media feature value to its
canonical form (as specified in the syntax).</p></li>
<li><p>Sort the media features in lexicographical order.</p></li>
<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>.</p></li>
<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>.</p></li>
<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>
<li><p>Return <var>s</var>.</p></li>
</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:</p>
<ol>
<li><p>Let <var>s</var> be the empty string.</p></li>
<li><p>If the list is empty return <var>s</var> and terminate this
algorithm.</p></li>
<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>.</p></li>
<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>.</p></li>
</ol>
</li>
<li><p>Return <var>s</var>.</p></li>
</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 <span title="serializing media query">serialize</span> them both and
if they are equal return <i>true</i> and <i>false</i> otherwise.</p>
<h4>The <code>MediaList</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>MediaList</code> interface represent an
ordered collection of media queries. Items in this collection are
accessible through an integral index, starting from zero.</p>
<pre class="idl">interface <dfn>MediaList</dfn> {
attribute DOMString <span title="medialist-mediatext">mediaText</span>;
readonly attribute unsigned long <span title="medialist-length">length</span>;
[IndexGetter] DOMString <span title="medialist-item">item</span>(in unsigned long <var title="">index</var>);
void <span title="medialist-appendmedium">appendMedium</span>(in DOMString <var title="">medium</var>)
void <span title="medialist-deletemedium">deleteMedium</span>(in DOMString <var title="">medium</var>)
};</pre>
<p>In bindings that allow it, such as ECMAScript, <code>MediaList</code>
objects <em class="ct">must</em> stringify to their
<code title="medialist-mediatext">mediaText</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
<span title="serializing media queries">serialization of the media
qeuries</span>. On setting, setting <em class="ct">must</em> be ignored if
the return value of <span title="parsing media queries">parsing</span> 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>
<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>
<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>
<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.</p>
<h3>Style Sheet Types</h3>
<p>A <dfn id="persistent-style-sheet">persistent style sheet</dfn> is a
<span>style sheet</span> whose <span>style sheet title</span> is the empty
string.</p>
<p>A <dfn id="style-sheet-set">style sheet set</dfn> is a collection of
one or more <span title="style sheet">style sheets</span> which have an
identical <span>style sheet title</span> that is not the empty string.</p>
<p>An <dfn id="alternative-style-sheet-set">alternative style sheet
set</dfn> is a <span>style sheet set</span> of which the <span>style sheet
alternate flag</span> is <i>true</i>.</p>
<p class="issue"><dfn>preferred style sheet set</dfn></p>
<h3>Accessing Style Sheets</h3>
<h4>The <code title="">LinkStyle</code> Interface</h4>
<p>The <code>LinkStyle</code> interface provides a bridge between the node
that takes care of the embedding or inclusion of a <span>style
sheet</span> and the <code>StyleSheet</code> object representing the style
sheet.</p>
<p class="note">The <code>style</code> content attribute found in various
markup languages does not embed, or represent, a style sheet.</p>
<pre class="idl">interface <dfn>LinkStyle</dfn> {
readonly attribute <span>StyleSheet</span> <span title="linkstyle-sheet">sheet</span>;
};</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>StyleSheet</code> object, or <code>null</code>, if there is no
associated <code>StyleSheet</code> object.</p>
<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>StyleSheet</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.</p>
<h5>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>LinkStyle</code> interface. These specifications
<em class="ct">should</em> also define how the various properties of a
<span>style sheet</span> are set when
<code title="linkstyle-sheet">sheet</code> is not <code>null</code>.</p>
<p class="note">This specification defines it for SVG,
<code><?xml-stylesheet?></code>, and the HTTP <code>Link</code> header
for the time being.</p>
<h4>Requirements User Agents Implementing SVG</h4>
<p><em>This section applies to user agents implementing SVG.</em></p>
<p>SVG user agents <em class="ct">must</em> implement the
<code>LinkStyle</code> interfaces on objects implementing the
<code>SVGStyleElement</code> interface.</p>
<p class="issue">...</p>
<h4>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>
<p>User agents supporting supporting <code><?xml-stylesheet?></code>
<em class="ct">must</em> implement the <code>LinkStyle</code> on objects
implementing <code>ProcessingInstruction</code>.</p>
<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">sheet</code> attribute of the node's
<code>LinkStyle</code> interface <em class="ct">must</em> return
<code>null</code>.</p>
<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">sheet</code> attribute of the node's
<code>LinkStyle</code> interface <em class="ct">must</em> return
<code>null</code>.</p>
<p>Otherwise, a new <span>style sheet</span> <em class="ct">must</em> be
created with <span>style sheet type</span> set to the canonical type,
<span>style sheet location</span> to the location of the style sheet,
<span>style sheet title</span> to the value of the <code title="">title</code>
pseudo-attribute, <span>style sheet media</span> to the value of the
<code title="">media</code> pseudo-attribute, the <span>style sheet alternate
flag</span> to <i>true</i> if the <code title="">alternate</code> pseudo-attribute
is "<code>yes</code>" and <i>false</i> otherwise, and the <span>style
sheet disabled flag</span> to <i>false</i>.</p>
<h4>Requirements on User Agents Implementing the HTTP
<code title="">Link</code> Header</h4>
<p class="issue">...</p>
<h4>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>DocumentStyle</code>
interface.</p>
<!-- https://bugzilla.mozilla.org/show_bug.cgi?id=200930 (FIXED) -->
<pre class="idl">interface <dfn>DocumentStyle</dfn> {
readonly attribute <span>StyleSheetList</span> <span>styleSheets</span>;
attribute DOMString <span>selectedStyleSheetSet</span>;
readonly attribute DOMString <span>lastStyleSheetSet</span>;
readonly attribute DOMString <span>preferredStyleSheetSet</span>;
readonly attribute DOMStringList <span>styleSheetSets</span>;
void <span title="documentstyle-enablestylesheetsforset">enableStylesheetsForSet</span>(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>
<dl class="members">
<dt><dfn id="documentstyle-stylesheets"><code>styleSheets</code></dfn> of
type <code>StyleSheetList</code></dt>
<dd><p>This attribute <em class="ct">must</em> be a
<code>StyleSheetList</code> object containing a collection of all
<code>StyleSheet</code> objects in document order (those returned by
<code title="linkstyle-sheet">sheet</code> attribute on objects implementing
the <code>LinkStyle</code> interface) preceded by style sheets introduced through
the HTTP <code>Link</code> header.</p></dd>
<dt><dfn id="documentstyle-selectedStyleSheetSet"><code>selectedStyleSheetSet</code></dfn>
of type <code>DOMString</code></dt>
<dd>
<p>This attribute indicates which <span>style sheet set</span> is in use.
This attribute is <span>live</span>; changing the
<code title="stylesheet-disabled">disabled</code> attribute on style sheets
directly will change the value of this attribute.</p>
<p>If all the sheets that are enabled and <span>have a title</span> 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>styleSheets</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 <span>have a title</span> are disabled, or there are no alternative style
sheets, and <code>selectedStyleSheetSet</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">enableStylesheetsForSet()</code>
with that value as the method's argument, and set
<code>lastStyleSheetSet</code> to that value.</p>
<p>From the DOM's perspective, all views have the same
<code>selectedStyleSheetSet</code>. If a user agent supports multiple views
with different selected alternative style sheets, then this attribute (and the
<code>StyleSheet</code> interface's <code>disabled</code> attribute)
<em class="ct">must</em> return and set the value for the default view.</p>
</dd>
<dt><dfn id="documentstyle-lastStyleSheetSet"><code>lastStyleSheetSet</code></dfn>
of type <code>DOMString</code>, readonly</dt>
<dd>
<p>This attribute <em class="ct">must</em> initially have the value
<code>null</code>. Its value changes when the
<code>selectedStyleSheetSet</code> attribute is set.</p>
</dd>
<dt><dfn id="documentstyle-preferredStyleSheetSet"><code>preferredStyleSheetSet</code></dfn>
of type <code>DOMString</code>, readonly</dt>
<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>
</dd>
<dt><dfn id="documentstyle-styleSheetSets"><code>styleSheetSets</code></dfn>
of type <code>DOMStringList</code>, readonly</dt>
<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>styleSheets</code>
attribute, adding the title of each style sheet
<span title="have a title">with a title</span> to the list, avoiding
duplicates by dropping titles that match (<span>case-sensitively</span>)
titles that have already been added to the list.</p>
</dd>
<dt><dfn id="documentstyle-enablestylesheetsforset" title="documentstyle-enablestylesheetsforset"><code>enableStylesheetsForSet(<var title="">name</var>)</code></dfn>,
method</dt>
<dd>
<p>Invoking this method <em class="ct">must</em> change the
<code title="stylesheet-disabled">disabled</code> attribute on each
<code>StyleSheet</code> object
<span title="have a title">with a title</span> in the
<code>styleSheets</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 <span>have a title</span> are never affected by
this method. This method does not change the values of the
<code>lastStyleSheetSet</code> or <code>preferredStyleSheetSet</code>
attributes.</p>
</dd>
</dl>
<h3>Dynamically adding new style sheets</h3>
<p>If new style sheets <span title="have a title">with titles</span> 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.</p>
<h4>Adding style sheets</h4>
<p>First, if the style sheet is a preferred style sheet (it
<span title="have a title">has a title</span>, but is not marked as
alternative), and there is no
current preferred style sheet (the <code>preferredStyleSheetSet</code>
attribute is equal to the empty string) then the
<code>preferredStyleSheetSet</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>
<p>Then, for all sheets, if any of the following is true, then the style sheet
<em class="ct">must</em> be enabled:</p>
<ul>
<li>The style sheet has an empty title.</li>
<li>The <code>lastStyleSheetSet</code> is <code>null</code>, and the style
sheet's title matches (by <span>case-sensitive</span> match) the value of
the <code>preferredStyleSheetSet</code> attribute.</li>
<li>The style sheet's title matches (by <span>case-sensitive</span> match)
the value of the <code>lastStyleSheetSet</code> attribute.</li>
</ul>
<p>Otherwise, the style sheet <em class="ct">must</em> be disabled.</p>
<h4>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>preferredStyleSheetSet</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>lastStyleSheetSet</code> attribute.</p>
<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>preferredStyleSheetSet</code> attribute's value
<em class="ct">must</em> be changed appropriately, and, if the
<code>lastStyleSheetSet</code> is <code>null</code>, the
<code title="documentstyle-enablestylesheetsforset">enableStylesheetsForSet()</code>
method <em class="ct">must</em> be called with the new
<code>preferredStyleSheetSet</code> value. (The
<code>lastStyleSheetSet</code> attribute is, again, not changed.)</p>
<h4>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>selectedStyleSheetSet</code> attribute would
return null, <code>lastStyleSheetSet</code> would return "foo", and
<code>preferredStyleSheetSet</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>preferredStyleSheetSet</code> is set and the
<code title="documentstyle-enablestylesheetsforset">enableStylesheetsForSet()</code>
method is called (since <code>selectedStyleSheetSet</code> was never set
explicitly, leaving <code>lastStyleSheetSet</code> at <code>null</code>
throughout), which changes which style sheets are enabled and which are
not.</p>
</div>
<h3>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>styleSheetSets</code> list, showing the
<code>selectedStyleSheetSet</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>preferredStyleSheetSet</code> is the
empty string as well.</p>
<p>Selecting a style sheet from this list should set the
<code>selectedStyleSheetSet</code> attribute. This (by definition)
affects the <code>lastStyleSheetSet</code> attribute.</p>
<h4>Persisting the selected style sheet set</h4>
<p>If UAs persist the selected style sheet set, they should use the
value of the <code>selectedStyleSheetSet</code> attribute, or if
that is <code>null</code>, the <code>lastStyleSheetSet</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>
<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>selectedStyleSheetSet</code> attribute as if the user had selected the set
manually.</p>
<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.</p>
<h3>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>styleSheets</code> list, not simply enumerations of
the <code>styleSheets</code> list that only contains the top level.</p>
<p class="issue">Would that actually work?!</p>
<h2>Cascading Style Sheets APIs</h2>
<p><em>This section (and its subsections) are only applicable to user agents
implementing CSS.</em></p>
<p>The previous section provided a way of getting access to style sheets in a
generic way. This section provides a way for getting access to the individual
style rules within a Cascading Style Sheet as defined by the CSS
specifications. [CSS]</p>
<h3>Parsing and Serializing CSS Constructs</h3>
<!--
statement "[S|CDO|CDC]* [ import [S|CDO|CDC]* ]* [ [ ruleset | media | page ] [S|CDO|CDC]* ]*" ??
selectors "*"
page selectors "S* pseudo_page? S*"
declaration "S* declaration" (properties, property values, property priority)
property value "S* expr"
-->
<p>This section (and its subsections) define rules for parsing and
serialization of CSS constructs.</p>
<h4>CSS Value Rules</h4>
<p>The rules for <dfn title="CSS value parsing">parsing a CSS value</dfn> for
a given <var title="">property</var> are as given in the following algorithm.
The result is either a CSS value or "null" if the operation failed.</p>
<ol>
<li>Parse the value using the <code>S* expr</code> production in combination
with the allowed values for the given <var title="">property</var>. If this
fails return "null". Otherwise return the parsed value.</li>
</ol>
<p>The aforementioned production is defined in the CSS 2.1 specification.
[CSS]</p>
<p>The rules for <dfn title="CSS value serializing">serializing a CSS
value</dfn> are as given in the following algorithm:</p>
<ol>
<li><p>Relative lengths (<code>em</code>, <code>ex</code>, <code>px</code>,
all the font-size keywords and <code>%</code>) do not have their units
changed. However, absolute lengths must be given in millimeters. For example,
the canonical version of <code>+012.0pt</code> is <code>4.2333mm</code> (give
or take a few significant figures). <span class="note"><em>Computed</em>
values may well be in different units than the specified value. User agents
are to use <code>px</code> as their final units for computed length
values.</span></p></li>
<li><p>When a <code><length></code> of zero is given, then any specified
units <em class="ct">must</em> be removed.</p></li>
<!-- apparently "0px" is better for interop -->
<li>
<p>A <code><color></code> value is canonicalized as follows:</p>
<dl>
<dt>It is a system color</dt>
<dd>See below (you use the representation given in the specification that
defines the keyword).</dd>
<dt>Alpha component is equal to 1.0</dt>
<dd>The color is an uppercase six-digit hexadecimal value, prefixed with a
<code>#</code> character (U+0023 NUMBER SIGN), with the first two digits
representing the red component, the next two digits representing the green
component, and the last two digits representing the blue component, the
digits being in the range 0-9 A-F (U+0030 to U+0039 and U+0041 to
U+0046).</dd>
<dt>Alpha component is less than 1.0</dt>
<dd>The color is in the CSS <code>rgba()</code> functional-notation format:
the literal string <code>rgba</code> (U+0072 U+0067 U+0062 U+0061) followed