css3-conditional/Overview.src.html

Tue, 09 Oct 2012 14:14:55 -0700

author
Tab Atkins Jr. <jackalmage@gmail.com>
date
Tue, 09 Oct 2012 14:14:55 -0700
changeset 6829
2c0ed7c22af3
parent 6793
876e13176c8b
child 6830
eb9aa921aa39
permissions
-rw-r--r--

[css3-conditional] Allow no spaces between @supports and the following supports condition.

dbaron@2974 1 <!DOCTYPE html public '-//W3C//DTD HTML 4.01//EN'
dbaron@2974 2 'http://www.w3.org/TR/html4/strict.dtd'>
dbaron@2974 3 <html lang="en">
dbaron@2974 4 <head profile="http://www.w3.org/2006/03/hcard">
dbaron@2974 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
dbaron@2974 6 <title>CSS Conditional Rules Module Level 3</title>
dbaron@2974 7 <link rel="stylesheet" type="text/css" href="../default.css">
dbaron@2974 8 <link rel="stylesheet" type="text/css"
dbaron@2974 9 href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
dbaron@2974 10 </head>
dbaron@2974 11
dbaron@2974 12 <div class="head">
dbaron@2974 13 <!--logo-->
dbaron@2974 14
dbaron@2974 15 <h1>CSS Conditional Rules Module Level 3</h1>
dbaron@2974 16
dbaron@2974 17 <h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
dbaron@2974 18 <dl>
dbaron@2974 19 <dt>This version:
dbaron@2974 20 <dd><a href="[VERSION]">
dbaron@6731 21 http://www.w3.org/TR/[YEAR]/ED-css3-conditional-[CDATE]/</a>
dbaron@2974 22
dbaron@2974 23 <dt>Latest version:
dbaron@3241 24 <dd><a href="http://www.w3.org/TR/[SHORTNAME]/">http://www.w3.org/TR/[SHORTNAME]/</a>
dbaron@2974 25
dbaron@3245 26 <dt>Editor's draft:
bert@3404 27 <dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a>
dbaron@3245 28
dbaron@2974 29 <dt>Previous version:
dbaron@3421 30 <dd><a href="http://www.w3.org/TR/2011/WD-css3-conditional-20110901/">http://www.w3.org/TR/2011/WD-css3-conditional-20110901/</a></dd>
dbaron@2974 31
dbaron@2974 32 <dt>Editors:
dbaron@2974 33 <dd class=vcard><a class=fn href="http://dbaron.org/">L. David Baron</a>,
dbaron@6308 34 <a class=org href="http://www.mozilla.org/">Mozilla</a>
dbaron@3744 35
dbaron@3744 36 <dt>Issues list:
dbaron@3744 37 <dd>Maintained in document (only editor's draft is current)
dbaron@3744 38
fantasai@6697 39 <dt>Feedback:
fantasai@6697 40
fantasai@6697 41 <dd><a
fantasai@6697 42 href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a>
dbaron@6738 43 with subject line “<kbd>&#x5b;[SHORTNAME]&#x5d; <var>… message topic
fantasai@6697 44 …</var></kbd>”
dbaron@3744 45
dbaron@3744 46 <dt>Test suite:
dbaron@6115 47 <dd><a href="https://test.csswg.org/shepherd/search/spec/css3-conditional/">submitted tests</a>; no built test suite yet
dbaron@3744 48
dbaron@2974 49 </dl>
dbaron@2974 50
dbaron@2974 51 <!--copyright-->
dbaron@2974 52
dbaron@2974 53 <hr title="Separator for header">
dbaron@2974 54 </div>
dbaron@2974 55
jackalmage@6617 56 <h2 class="no-num no-toc" id="abstract">Abstract</h2>
dbaron@2974 57
dbaron@2974 58 <p>CSS is a language for describing the rendering of structured documents
dbaron@2974 59 (such as HTML and XML) on screen, on paper, in speech, etc. This module
dbaron@2974 60 contains the features of CSS for conditional processing of parts of
dbaron@2974 61 style sheets, conditioned on capabilities of the processor or the
dbaron@2974 62 document the style sheet is being applied to.
dbaron@2974 63 It includes and extends the functionality of CSS level&nbsp;2 [[!CSS21]],
dbaron@2974 64 which builds on CSS level&nbsp;1 [[CSS1]].
dbaron@2974 65 The main extensions compared to level&nbsp;2 are
dbaron@2983 66 allowing nesting of certain at-rules inside '@media',
dbaron@2983 67 the addition of the '@supports' and '@document'
dbaron@2974 68 rules for conditional processing.
dbaron@2974 69
jackalmage@6617 70 <h2 class="no-num no-toc" id="status">Status of this document</h2>
dbaron@2974 71
dbaron@2974 72 <!--status-->
dbaron@2974 73
dbaron@2974 74 <p>The following features are at risk:
dbaron@2974 75 <ul>
dbaron@2983 76 <li>The inclusion of '@font-face' rules and
dbaron@2983 77 '@keyframes' rules as allowed within all of the @-rules in
dbaron@2974 78 this specification is at risk, though only because of the relative
dbaron@2974 79 rates of advancement of specifications. If this specification is able
dbaron@2974 80 to advance faster than one or both of the specifications defining
dbaron@2974 81 those rules, then the inclusion of those rules will move from this
dbaron@2974 82 specification to the specification defining those rules.</li>
dbaron@2974 83
dbaron@2974 84 <li>The addition of support for @-rules inside of conditional grouping
dbaron@2974 85 rules is at risk; if interoperable implementations are not found, it
dbaron@2974 86 may be removed to advance the other features in this specification to
dbaron@2974 87 Proposed Recommendation.</li>
dbaron@2974 88
dbaron@2983 89 <li>The '@supports' rule is at risk; if interoperable
dbaron@2974 90 implementations are not found, it may be removed to advance the other
dbaron@2974 91 features in this specification to Proposed Recommendation.</li>
dbaron@2974 92
dbaron@2983 93 <li>The '@document' rule is at risk; if interoperable
dbaron@2974 94 implementations are not found, it may be removed to advance the other
dbaron@2974 95 features in this specification to Proposed Recommendation.</li>
dbaron@2974 96
dbaron@2974 97 </ul>
dbaron@2974 98
jackalmage@6617 99 <h2 class="no-num no-toc" id="contents">Table of contents</h2>
dbaron@2974 100
dbaron@2974 101 <!--toc-->
dbaron@2974 102
jackalmage@6617 103 <h2 id="introduction">Introduction</h2>
dbaron@2974 104
jackalmage@6617 105 <h3 id="context">Background</h3>
dbaron@2974 106
dbaron@2974 107 <p><em>This section is not normative.</em>
dbaron@2974 108
dbaron@2974 109 <p>[[!CSS21]] defines one type of conditional group rule, the
dbaron@2983 110 '@media' rule, and allows only rulesets (not other @-rules)
dbaron@2983 111 inside of it. The '@media' rule provides the ability to
dbaron@2974 112 have media-specific style sheets, which is also provided by style
dbaron@2983 113 sheet linking features such as '@import' and
dbaron@2983 114 <code class="html">&lt;link&gt;</code>. The restrictions on the contents of
dbaron@2983 115 '@media' rules made them less useful; they have forced authors
dbaron@2974 116 using CSS features involving @-rules in media-specific style sheets to
dbaron@2974 117 use separate style sheets for each medium.</p>
dbaron@2974 118
dbaron@2974 119 <p>This specification extends the rules for the contents of
dbaron@2974 120 conditional group rules to allow other @-rules, which enables authors
dbaron@2974 121 to combine CSS features involving @-rules with media specific style
dbaron@2974 122 sheets within a single style sheet.</p>
dbaron@2974 123
dbaron@2974 124 <p>This specification also defines additional types of conditional
dbaron@2983 125 group rules, '@supports' and '@document', to
dbaron@2974 126 address author and user requirements.</p>
dbaron@2974 127
dbaron@2983 128 <p>The '@supports' rule allows CSS to be conditioned on
dbaron@2974 129 implementation support for CSS properties and values. This rule makes
dbaron@2974 130 it much easier for authors to use new CSS features and provide good
dbaron@2974 131 fallback for implementations that do not support those features. This
dbaron@2974 132 is particularly important for CSS features that provide new layout
dbaron@2974 133 mechanisms, and for other cases where a set of related styles needs to
dbaron@2974 134 be conditioned on property support.</p>
dbaron@2974 135
dbaron@2983 136 <p>The '@document' rule allows CSS to be conditioned on the
dbaron@2974 137 page to which the style sheet is being applied. This allows users to
dbaron@2974 138 apply styles to a particular page or group of pages, which greatly
dbaron@2974 139 increases the power of user style sheets.</p>
dbaron@2974 140
jackalmage@6617 141 <h3 id="placement">Module Interactions</h3>
dbaron@2974 142
dbaron@2983 143 <p>This module replaces and extends the '@media' rule
dbaron@2974 144 feature defined in [[!CSS21]] section <var>7.2.1</var> and
dbaron@2974 145 incorporates the modifications previously made non-normatively by
dbaron@2974 146 [[!MEDIAQ]] section <var>1</var>.</p>
dbaron@2974 147
dbaron@3462 148 <p>Its current definition depends on @-rules defined in [[!CSS3-FONTS]]
dbaron@2974 149 and [[!CSS3-ANIMATIONS]], but that dependency is only on the
dbaron@2974 150 assumption that those modules will advance ahead of this one. If this
dbaron@2974 151 module advances faster, then the dependency will be reversed.</p>
dbaron@2974 152
jackalmage@6617 153 <h3 id="conventions">Document Conventions</h3>
dbaron@2974 154
dbaron@2974 155 <p>Conformance requirements are expressed with a combination of
dbaron@2974 156 descriptive assertions and RFC 2119 terminology. The key words “MUST”,
dbaron@2974 157 “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
dbaron@2974 158 “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
dbaron@2974 159 document are to be interpreted as described in RFC 2119.
dbaron@2979 160 However, for readability, these words do not appear in all uppercase
dbaron@2979 161 letters in this specification.
dbaron@2974 162
dbaron@2974 163 <p>All of the text of this specification is normative except sections
dbaron@2974 164 explicitly marked as non-normative, examples, and notes. [[!RFC2119]]</p>
dbaron@2974 165
dbaron@2974 166 <p>Examples in this specification are introduced with the words “for example”
dbaron@2983 167 or are set apart from the normative text with
dbaron@2983 168 <code class="html">class="example"</code>, like this:
dbaron@2974 169
dbaron@2974 170 <div class="example">
dbaron@2974 171 <p>This is an example of an informative example.</p>
dbaron@2974 172 </div>
dbaron@2974 173
dbaron@2974 174 <p>Informative notes begin with the word “Note” and are set apart from the
dbaron@2983 175 normative text with <code class="html">class="note"</code>, like this:
dbaron@2974 176
dbaron@2974 177 <p class="note">Note, this is an informative note.</p>
dbaron@2974 178
jackalmage@6617 179 <h2 id="processing">Processing of conditional group rules</h2>
dbaron@2974 180
dbaron@2974 181 <p>This specification defines some CSS @-rules, called <dfn>conditional
dbaron@2974 182 group rules</dfn>, that associate a condition with a group of other
dbaron@2974 183 CSS rules. These different rules allow testing different types of
dbaron@2974 184 conditions, but share common behavior for how their contents are used
dbaron@2974 185 when the condition is true and when the condition is false.</p>
dbaron@2974 186
dbaron@2974 187 <div class="example">
dbaron@2974 188 <p>For example, this rule:</p>
dbaron@2974 189 <pre>@media print {
dbaron@2974 190 #navigation { display: none }
dbaron@2974 191 }</pre>
dbaron@2974 192 <p>causes a particular CSS rule (making elements with ID "navigation" be
dbaron@2974 193 display:none) apply only when the style sheet is used for a print
dbaron@2974 194 medium. Likewise, this CSS rule:</p>
dbaron@2974 195 <pre>@document url("http://www.example.com/") {
dbaron@2974 196 #example1 { display: none }
dbaron@2974 197 }</pre>
dbaron@2974 198 <p>does the same type of conditional application, but using a different
dbaron@2974 199 condition: whether the style sheet is being applied to the page
dbaron@2974 200 <code>http://www.example.com/</code>.</p>
dbaron@2974 201 </div>
dbaron@2974 202
dbaron@2974 203 <p>Each conditional group rule has a condition, which at any time
dbaron@2974 204 evaluates to true or false. When the condition is true, CSS processors
dbaron@2979 205 <strong>must</strong> apply the rules inside the group rule as though
dbaron@2979 206 they were at the group rule's location; when the condition is false, CSS
dbaron@3948 207 processors <strong>must not</strong> apply any of rules inside the group
dbaron@2979 208 rule. The current state of the condition does not affect the CSS object
dbaron@2979 209 model, in which the contents of the group rule always remain within the
dbaron@2979 210 group rule.</p>
dbaron@2974 211
dbaron@2974 212 <p>This means that when multiple conditional group rules are nested,
dbaron@2974 213 a rule inside of both of them applies only when all of the rules'
dbaron@2974 214 conditions are true.</p>
dbaron@2974 215
dbaron@2974 216 <div class="example">For example, with this set of nested rules:
dbaron@2974 217 <pre>@media print { // rule (1)
dbaron@2974 218 #navigation { display: none }
dbaron@2974 219 @media (max-width: 12cm) { // rule (2)
dbaron@2974 220 .note { float: none }
dbaron@2974 221 }
dbaron@2974 222 }</pre>
dbaron@2974 223 the condition of the rule marked (1) is true for print media, and the
dbaron@2974 224 condition of the rule marked (2) is true when the width of the display
dbaron@2974 225 area (which for print media is the page box) is less than or equal to
dbaron@2983 226 12cm. Thus the rule ''#navigation { display: none }'' applies
dbaron@2974 227 whenever this style sheet is applied to print media, and the rule
dbaron@2983 228 ''.note { float: none }'' is applied only when the style sheet
dbaron@2974 229 is applied to print media <em>and</em> the width of the page box is less
dbaron@2974 230 than or equal to 12 centimeters.</div>
dbaron@2974 231
dbaron@2979 232 <p>When the condition for a conditional group rule changes, CSS
dbaron@2979 233 processors <strong>must</strong> reflect that the rules now apply or no
dbaron@2979 234 longer apply, except for properties whose definitions define effects of
dbaron@2979 235 computed values that persist past the lifetime of that value (such as
dbaron@2979 236 for some properties in [[CSS3-TRANSITIONS]] and
dbaron@2979 237 [[!CSS3-ANIMATIONS]]).</p>
dbaron@2974 238
jackalmage@6617 239 <h2 id="contents-of">Contents of conditional group rules</h2>
dbaron@2974 240
dbaron@2975 241 <p class="issue">There is also likely demand for using these
dbaron@2983 242 conditions with '@import'. We should see if we can
dbaron@2975 243 come up with sensible syntax for that, perhaps functional notation
dbaron@2983 244 at the end of the '@import' rule.</p>
dbaron@2975 245
dbaron@2974 246 <p>The syntax of each conditional group rule consists of some syntax
dbaron@2974 247 specific to the type of rule followed by a <dfn>group rule body</dfn>,
dbaron@2974 248 which is a block (pair of braces) containing a sequence of rules.</p>
dbaron@2974 249
dbaron@2974 250 <p>A group rule body is allowed to contain rulesets and any @-rules that
dbaron@2974 251 are allowed at the top level of a style sheet before and after a
dbaron@2974 252 ruleset. This means that @-rules that must occur at the beginning of
dbaron@3020 253 the style sheet (such as '@charset', '@import',
dbaron@3020 254 and '@namespace' rules) are not allowed inside of conditional group
dbaron@2974 255 rules. Conditional group rules can be nested.</p>
dbaron@2974 256
dbaron@2974 257 <p>In terms of the grammar, this specification defines the following
dbaron@2974 258 productions for use in the grammar of conditional group rules:</p>
dbaron@2974 259
dbaron@2974 260 <pre>nested_statement
dbaron@5294 261 : ruleset | media | page | font_face_rule | keyframes_rule |
dbaron@2974 262 supports_rule | document_rule
dbaron@2974 263 ;
dbaron@2974 264
dbaron@2974 265 group_rule_body
dbaron@2974 266 : '{' S* nested_statement* '}' S*
dbaron@2974 267 ;</pre>
bert@3404 268 <p>
dbaron@2974 269 in which all the productions are defined in that grammar with the
dbaron@2974 270 exception of <code>font_face_rule</code> <span class="issue">not</span>
dbaron@5294 271 defined in [[!CSS3-FONTS]], <code>keyframes_rule</code> defined in
dbaron@2974 272 [[!CSS3-ANIMATIONS]], and <code>media</code>, <code>supports_rule</code>
dbaron@2974 273 and <code>document_rule</code> defined in this specification.</p>
dbaron@2974 274
dbaron@2974 275 <p>In general, future CSS specifications that add new @-rules that are
dbaron@2974 276 not forbidden to occur after some other types of rules should modify
dbaron@2974 277 this <code>nested_statement</code> production to keep the grammar
dbaron@2974 278 accurate.</p>
dbaron@2974 279
dbaron@2979 280 <p>Style sheets <strong>must not</strong> use rules other than the allowed ones inside
dbaron@2974 281 conditional group rules.</p>
dbaron@2974 282
dbaron@3019 283 <p>CSS processors <strong>must</strong> ignore rules that are not
dbaron@3019 284 allowed within a group rule, and <strong>must</strong> handle invalid
dbaron@3019 285 rules inside of group rules as described in <a
dbaron@3019 286 href="http://www.w3.org/TR/CSS21/syndata.html#parsing-errors">section
dbaron@3019 287 4.2 (Rules for handling parsing errors)</a>, <a
dbaron@3019 288 href="http://www.w3.org/TR/CSS21/syndata.html#at-rules">section 4.1.5
dbaron@3019 289 (At-rules)</a>, and <a
dbaron@3019 290 href="http://www.w3.org/TR/CSS21/syndata.html#rule-sets">section 4.1.7
dbaron@3019 291 (Rule sets, declaration blocks, and selectors)</a> of [[!CSS21]].</p>
dbaron@2974 292
jackalmage@6617 293 <h2 id="use">Placement of conditional group rules</h2>
dbaron@2974 294
dbaron@3019 295 <p>Conditional group rules are allowed at the top-level of a style
dbaron@3019 296 sheet, and inside other conditional group rules. CSS processors
dbaron@3019 297 <strong>must</strong> process such rules as <a
dbaron@3019 298 href="#processing">described above</a>.</p>
dbaron@3019 299
dbaron@3020 300 <p>Any rules that are not allowed after a ruleset (e.g., ''@charset'',
dbaron@3020 301 ''@import'', or ''@namespace'' rules) are also not allowed after a
dbaron@3020 302 conditional group rule. Therefore, style sheets <strong>must
dbaron@3019 303 not</strong> place such rules after a conditional group rules, and CSS
dbaron@3019 304 processors <strong>must</strong> ignore such rules.</p>
dbaron@2974 305
jackalmage@6617 306 <h2 id="at-media">Media-specific style sheets: the '@media' rule</h2>
dbaron@2974 307
dbaron@2983 308 <p>The <dfn>'@media' rule</dfn> is a conditional group rule whose
dbaron@2974 309 condition is a media query. It consists of the at-keyword
dbaron@2983 310 '@media' followed by a (possibly empty) media query (as
dbaron@2974 311 defined in [[!MEDIAQ]]), followed by a group rule body. The condition
dbaron@2974 312 of the rule is the result of the media query.</p>
dbaron@2974 313
dbaron@2974 314 <div class="example">
dbaron@2983 315 <p>This '@media' rule:</p>
dbaron@2974 316 <pre>@media print, (max-width: 600px) {
dbaron@2974 317 #extra_navigation { display: none }
dbaron@2974 318 }</pre>
dbaron@2983 319 <p>has the condition ''print, (max-width: 600px)'', which is
dbaron@2974 320 true for print media and for devices whose width is at most 600px. When
dbaron@2979 321 either of these is true, the condition of the rule is true, and the rule
dbaron@2983 322 ''#extra_navigation { display: none }'' is applied.
dbaron@2974 323 </div>
dbaron@2974 324
dbaron@2974 325 <p>In terms of the grammar, this specification extends the
dbaron@2974 326 <code>media</code> production in the
dbaron@2974 327 <a href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
dbaron@2974 328 ([[!CSS21]], Appendix G) into:
dbaron@2974 329 <pre>media
dbaron@6114 330 : MEDIA_SYM S* media_query_list group_rule_body
dbaron@2974 331 ;</pre>
dbaron@2974 332 <p>where the <code>group_rule_body</code> production is defined in this
dbaron@2974 333 specification, the <code>media_query_list</code> production is defined
dbaron@2974 334 in [[!MEDIAQ]], and the others are defined in the <a
dbaron@2974 335 href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
dbaron@2974 336 ([[!CSS21]], Appendix G).
dbaron@2974 337
jackalmage@6617 338 <h2 id="at-supports">Feature queries: the '@supports' rule</h2>
dbaron@2974 339
dbaron@2983 340 <p>The <dfn>'@supports' rule</dfn> is a conditional group
dbaron@2974 341 rule whose condition tests whether the user agent supports CSS
dbaron@2974 342 property:value pairs. Authors can use it to write style sheets that use
dbaron@2974 343 new features when available but degrade gracefully when those features
dbaron@2974 344 are not supported. CSS has existing mechanisms for graceful
dbaron@2974 345 degradation, such as ignoring unsupported properties or values, but
dbaron@2974 346 these are not always sufficient when large groups of styles need to be
dbaron@2974 347 tied to the support for certain features, as is the case for use of new
dbaron@2974 348 layout system features.</p>
dbaron@2974 349
dbaron@2983 350 <p>The syntax of the condition in the '@supports' rule is
dbaron@2974 351 slightly more complicated than for the other conditional group rules
dbaron@2974 352 (though has some similarities to media queries) since:</p>
dbaron@2974 353 <ul>
dbaron@2974 354 <li>negation is needed so that the new-feature styles and the fallback
dbaron@2974 355 styles can be separated (within the forward-compatible grammar's rules
dbaron@2974 356 for the syntax of @-rules), and not required to override each other</li>
dbaron@2974 357 <li>conjunction (and) is needed so that multiple required features can
dbaron@2974 358 be tested</li>
dbaron@2974 359 <li>disjunction (or) is needed when there are multiple alternative
dbaron@2974 360 features for a set of styles, particularly when some of those
dbaron@2974 361 alternatives are vendor-prefixed properties or values</li>
dbaron@2974 362 </ul>
dbaron@2974 363
dbaron@2983 364 <p>Therefore, the syntax of the '@supports' rule allows
dbaron@2974 365 testing for property:value pairs, and arbitrary conjunctions (and),
dbaron@2974 366 disjunctions (or), and negations (not) of them.</p>
dbaron@2974 367
dbaron@2974 368 <p>This extends the lexical scanner in the
dbaron@2974 369 <a href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
dbaron@2974 370 ([[!CSS21]], Appendix G) by adding:
dbaron@2974 371 <pre>@{S}{U}{P}{P}{O}{R}{T}{S} {return SUPPORTS_SYM;}</pre>
dbaron@2974 372 <p>and the grammar by adding</p>
jackalmage@6315 373 <pre><dfn>supports_rule</dfn>
jackalmage@6829 374 : SUPPORTS_SYM S* supports_condition group_rule_body
dbaron@2974 375 ;
dbaron@2974 376
jackalmage@6315 377 <dfn>supports_condition</dfn>
dbaron@2974 378 : supports_negation | supports_conjunction | supports_disjunction |
dbaron@3957 379 supports_condition_in_parens
dbaron@3957 380 ;
dbaron@3957 381
jackalmage@6315 382 <dfn>supports_condition_in_parens</dfn>
dbaron@3958 383 : ( '(' S* supports_condition ')' S* ) | supports_declaration_condition
dbaron@2974 384 ;
dbaron@2974 385
jackalmage@6315 386 <dfn>supports_negation</dfn>
dbaron@2974 387 : 'not' S* supports_condition_in_parens
dbaron@2974 388 ;
dbaron@2974 389
jackalmage@6315 390 <dfn>supports_conjunction</dfn>
dbaron@2974 391 : supports_condition_in_parens ( 'and' S* supports_condition_in_parens )+
dbaron@2974 392 ;
dbaron@2974 393
jackalmage@6315 394 <dfn>supports_disjunction</dfn>
dbaron@2974 395 : supports_condition_in_parens ( 'or' S* supports_condition_in_parens )+
dbaron@2974 396 ;
dbaron@2974 397
jackalmage@6315 398 <dfn>supports_declaration_condition</dfn>
dbaron@3024 399 : '(' S* core_declaration ')' S*
dbaron@2974 400 ;</pre>
dbaron@3024 401 <p>in which <code>core_declaration</code> is the production
dbaron@3024 402 <code>declaration</code> in the core syntax of CSS defined in <a
dbaron@3024 403 href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">section
dbaron@3024 404 4.1.1 (Tokenization)</a> of [[!CSS21]].</p>
dbaron@3024 405
dbaron@3024 406 <p>Any ''@supports'' rule that does not parse according to the grammar
dbaron@3024 407 above is invalid. Style sheets <strong>must not</strong> use such a
dbaron@3024 408 rule and processors <strong>must</strong> ignore such a rule.</p>
dbaron@3024 409
dbaron@3024 410 <p class="note">Note that this means that declarations that meet the
dbaron@3024 411 forward-compatible syntax for declarations are permitted (and support
dbaron@3024 412 for them is then tested by the ''@supports'' rule), but declarations
dbaron@3024 413 that do not meet the forward-compatible syntax for declarations cause
dbaron@3024 414 the entire ''@supports'' rule to be ignored.</p>
dbaron@3024 415
dbaron@3024 416 <p class="issue">Is any further allowance for forward-compatible parsing
dbaron@3024 417 needed, for example, to allow additional features (such as, say,
dbaron@3024 418 selector tests) to be added to the ''@supports'' rule? Or are these
dbaron@3024 419 forward-compatible parsing rules the best solution for such future
dbaron@3024 420 expansion anyway?</p>
dbaron@2974 421
dbaron@3021 422 <p>Each of these grammar terms is associated with a boolean result, as
dbaron@3021 423 follows:</p>
dbaron@2974 424 <dl>
dbaron@2974 425 <dt>supports_condition</dt>
dbaron@2974 426 <dd>
dbaron@3021 427 The result is the result of the single child term.
dbaron@2974 428 </dd>
dbaron@2974 429
dbaron@3957 430 <dt>supports_condition_in_parens</dt>
dbaron@3957 431 <dd>
dbaron@3957 432 The result is the result of the single <code>supports_condition</code>
dbaron@3957 433 or <code>supports_declaration_condition</code> child term.
dbaron@3957 434 </dd>
dbaron@3957 435
dbaron@2974 436 <dt>supports_negation</dt>
dbaron@2974 437 <dd>
dbaron@3021 438 The result is the <em>negation</em> of the result of the
dbaron@3021 439 <code>supports_condition_in_parens</code> child term.
dbaron@2974 440 </dd>
dbaron@2974 441
dbaron@2974 442 <dt>supports_conjunction</dt>
dbaron@2974 443 <dd>
dbaron@3021 444 The result is true if the result of <em>all</em> of the
dbaron@3021 445 <code>supports_condition_in_parens</code> child terms is true;
dbaron@3021 446 otherwise it is false.
dbaron@2974 447 </dd>
dbaron@2974 448
dbaron@2974 449 <dt>supports_disjunction</dt>
dbaron@2974 450 <dd>
dbaron@3021 451 The result is true if the result of <em>any</em> of the
dbaron@3021 452 <code>supports_condition_in_parens</code> child terms is true;
dbaron@3021 453 otherwise it is false.
dbaron@2974 454 </dd>
dbaron@2974 455
dbaron@2974 456 <dt>supports_declaration_condition</dt>
dbaron@2974 457 <dd>
dbaron@3021 458 The result is whether the CSS processor <a
dbaron@3021 459 href="#support-definition">supports</a> the declaration.
dbaron@2974 460 </dd>
dbaron@2974 461 </dl>
dbaron@2974 462
dbaron@3021 463 <p>The condition of the '@supports' rule is the result of the
dbaron@3021 464 <code>supports_condition</code> term that is a child of the
dbaron@3021 465 <code>supports_rule</code> term.</p>
dbaron@2974 466
dbaron@2982 467 <div class="example">
dbaron@2982 468 <p>For example, the following rule</p>
dbaron@2982 469 <pre>@supports ( display: flexbox ) {
dbaron@2982 470 body, #navigation, #content { display: flexbox; }
dbaron@2982 471 #navigation { background: blue; color: white; }
dbaron@2982 472 #article { background: white; color: black; }
dbaron@2982 473 }</pre>
dbaron@2983 474 <p>applies the rules inside the '@supports' rule only when
dbaron@2983 475 ''display: flexbox'' is supported.</p>
dbaron@2982 476 </div>
dbaron@2974 477
dbaron@2982 478 <div class="example">
dbaron@2982 479 <p>The following example shows an additional '@supports' rule that can
dbaron@2982 480 be used to provide an alternative for when ''display: flexbox'' is not
dbaron@2982 481 supported:</p>
dbaron@2982 482 <pre>@supports not ( display: flexbox ) {
dbaron@2982 483 body { width: 100%; height: 100%; background: white; color: black; }
dbaron@2982 484 #navigation { width: 25%; }
dbaron@2982 485 #article { width: 75%; }
dbaron@2974 486 }</pre>
dbaron@2982 487 <p>Note that the 'width' declarations may be harmful to the
dbaron@2982 488 flexbox-based layout, so it is important that they be present only in
dbaron@2982 489 the non-flexbox styles.</p>
dbaron@2982 490 </div>
dbaron@2974 491
dbaron@2982 492 <div class="example">
dbaron@2982 493 <p>The following example checks for support for the 'box-shadow'
dbaron@2982 494 property, including checking for support for vendor-prefixed versions of
dbaron@2982 495 it. When the support is present, it specifies both 'box-shadow' (with
dbaron@2982 496 the prefixed versions) and 'color' in a way what would cause the text to
dbaron@2982 497 become invisible were 'box-shadow' not supported.</p>
dbaron@2982 498 <pre>@supports ( box-shadow: 2px 2px 2px black ) or
dbaron@2982 499 ( -moz-box-shadow: 2px 2px 2px black ) or
dbaron@2974 500 ( -webkit-box-shadow: 2px 2px 2px black ) or
dbaron@2974 501 ( -o-box-shadow: 2px 2px 2px black ) {
dbaron@2982 502 .outline {
dbaron@2982 503 color: white;
dbaron@2982 504 -moz-box-shadow: 2px 2px 2px black;
dbaron@2982 505 -webkit-box-shadow: 2px 2px 2px black;
dbaron@2982 506 -o-box-shadow: 2px 2px 2px black;
dbaron@3960 507 box-shadow: 2px 2px 2px black; /* unprefixed last */
dbaron@2982 508 }
dbaron@2982 509 }</pre></div>
dbaron@2974 510
dbaron@2984 511 <p>To avoid confusion between ''and'' and ''or'', the syntax requires
dbaron@2984 512 that both ''and'' and ''or'' be specified explicitly (rather than, say,
dbaron@2984 513 using commas or spaces for one of them). Likewise, to avoid confusion
dbaron@2984 514 caused by precedence rules, the syntax does not allow ''and'', ''or'',
dbaron@2984 515 and ''not'' operators to be mixed without a layer of parentheses.</p>
dbaron@2974 516
dbaron@2984 517 <div class="example">
dbaron@2984 518 <p>For example, the following rule is not valid:
dbaron@3959 519 <pre class="illegal">@supports (transition-property: color) or
dbaron@2984 520 (animation-name: foo) and
dbaron@2984 521 (transform: rotate(10deg)) {
dbaron@2984 522 // ...
dbaron@2984 523 }</pre>
dbaron@2984 524 <p>Instead, authors must write one of the following:</p>
dbaron@2984 525 <pre>@supports ((transition-property: color) or
dbaron@2984 526 (animation-name: foo)) and
dbaron@2984 527 (transform: rotate(10deg)) {
dbaron@2984 528 // ...
dbaron@2984 529 }</pre>
dbaron@2984 530 <pre>@supports (transition-property: color) or
dbaron@3430 531 ((animation-name: foo) and
dbaron@2984 532 (transform: rotate(10deg))) {
dbaron@2984 533 // ...
dbaron@2984 534 }</pre>
dbaron@2984 535 </div>
dbaron@2974 536
dbaron@3957 537 <p>The declaration being tested must always occur within parentheses,
dbaron@3957 538 when it is the only thing in the expression.<p>
dbaron@3957 539
dbaron@3957 540 <div class="example">
dbaron@3957 541 <p>For example, the following rule is not valid:
dbaron@3959 542 <pre class="illegal">@supports display: flexbox {
dbaron@3957 543 // ...
dbaron@3957 544 }</pre>
dbaron@3957 545 <p>Instead, authors must write:</p>
dbaron@3957 546 <pre>@supports (display: flexbox) {
dbaron@3957 547 // ...
dbaron@3957 548 }</pre>
dbaron@3957 549 </div>
dbaron@3957 550
dbaron@3957 551 <p>The syntax allows extra parentheses when they are not needed. This
dbaron@3957 552 flexibility is sometimes useful for authors (for example, when
dbaron@3957 553 commenting out parts of an expression) and may also be useful for
dbaron@3957 554 authoring tools.</p>
dbaron@3957 555
dbaron@3957 556 <div class="example">
dbaron@3957 557 <p>For example, authors may write:</p>
dbaron@3957 558 <pre>@supports ((display: flexbox)) {
dbaron@3957 559 // ...
dbaron@3957 560 }</pre>
dbaron@3957 561 </div>
dbaron@3957 562
jackalmage@6793 563 <p>A trailing ''!important'' on a declaration being tested is allowed,
jackalmage@6793 564 though it won't change the validity of the declaration.
jackalmage@6793 565
jackalmage@6793 566 <div class="example">
jackalmage@6793 567 <p>For example, the following rule is valid:
jackalmage@6793 568 <pre>@supports (display: flexbox !important) {
jackalmage@6793 569 // ...
jackalmage@6793 570 }</pre>
jackalmage@6793 571 </div>
dbaron@6306 572
jackalmage@6617 573 <h3 id="support-definition">Definition of support</h3>
dbaron@3021 574
dbaron@6741 575 <p>For forward-compatibility,
dbaron@6741 576 <a href="http://www.w3.org/TR/CSS21/syndata.html#declaration">section 4.1.8
dbaron@6741 577 (Declarations and properties)</a> of [[!CSS21]]
dbaron@6741 578 defines rules for handling invalid properties and values.
dbaron@6741 579 CSS processors that
dbaron@6741 580 do not implement or partially implement a specification
dbaron@6741 581 <strong>must</strong> treat any part of a value that they
dbaron@6741 582 do not implement, or
dbaron@6741 583 do not have a usable level of support for,
dbaron@6741 584 as invalid according to this rule
dbaron@6741 585 for handling invalid properties and values,
dbaron@6741 586 and therefore <strong>must</strong> discard the declaration as a parse error.</p>
dbaron@6741 587
jackalmage@6617 588 <p>A CSS processor is considered to <dfn id="dfn-support">support</dfn>
dbaron@6741 589 a declaration (consisting of a property and value) if it accepts that
dbaron@6741 590 declaration (rather than discarding it as a parse error).
dbaron@6741 591 If a processor does not implement, with a usable level of support,
dbaron@6741 592 the value given,
dbaron@6741 593 then it <strong>must not</strong>
dbaron@6741 594 accept the declaration or claim support for it.</p>
dbaron@3021 595
dbaron@6742 596 <p>These rules (and the equivalence between them) allow
dbaron@3021 597 authors to use fallback (either in the [[CSS1]] sense of declarations
dbaron@3021 598 that are overridden by later declarations or with the new capabilities
dbaron@3021 599 provided by the ''@supports'' rule in this specification) that works
dbaron@3021 600 correctly for the features implemented. This applies especially to
dbaron@3021 601 compound values; implementations must implement all parts of the value
dbaron@3021 602 in order to consider the declaration supported, either inside a ruleset
dbaron@3021 603 or in the declaration condition of an ''@supports'' rule.</p>
dbaron@3021 604
jackalmage@6617 605 <h2 id="at-document">Document queries: the '@document' rule</h2>
dbaron@2974 606
dbaron@2983 607 <p>The <dfn>'@document' rule</dfn> is a conditional group
dbaron@3027 608 rule whose condition depends on the
dbaron@3027 609 <a href="#url-of-doc">URL of the document being styled</a>.
dbaron@2974 610 This allows style sheets, particularly user style sheets, to have styles
dbaron@2974 611 that only apply to a set of pages rather than to all pages using the
dbaron@2974 612 style sheet.</p>
dbaron@2974 613
dbaron@2974 614 <p class="issue">Given that this @-rule is intended primarily for user
dbaron@2974 615 style sheets, what should this specification say about its use in author
dbaron@2974 616 style sheets? Should it be forbidden? Should use instead be
dbaron@2974 617 discouraged? Or should this specification remain neutral on the
dbaron@2986 618 topic, since there are valid uses in author style sheets?</p>
dbaron@2974 619
jackalmage@6617 620 <p id="url-of-doc">The <dfn>URL of the document being styled</dfn> is
dbaron@3027 621 the URI at which the document is located, excluding any fragment
dbaron@3027 622 identifiers. (This means, for example, that HTTP redirects have been
dbaron@3027 623 followed.) If the styles are being applied inside a complete document
dbaron@3246 624 embedded into the presentation of another (e.g., [[HTML5]]&#39;s <code
dbaron@3027 625 class="html">iframe</code>, <code class="html">object</code>, or <code
dbaron@3027 626 class="html">img</code> elements), the relevant URI is that of the
dbaron@3027 627 frame, not of its container. However, if content from other documents
dbaron@3027 628 is mixed in via mechanisms that mix content from one document into
dbaron@3246 629 another (e.g., [[SVG11]]&#39;s <code>use</code> element), then the
dbaron@3027 630 address of the container document is used.</p>
dbaron@3027 631
dbaron@3027 632 <p class="note">Note: In [[HTML5]], this is the
fantasai@6697 633 <a href="http://dev.w3.org/html5/spec/dom.html#documents">document's address</a>
dbaron@3027 634 of a document in a
dbaron@3027 635 <a href="http://dev.w3.org/html5/spec/browsers.html#browsing-context">browsing context</a>.</p>
dbaron@3027 636
dbaron@3240 637 <div class="issue">What form of normalization is done on URLs and domains
dbaron@3240 638 before matching? In particular, this specification needs to describe:
dbaron@3240 639 <ul>
dbaron@3240 640 <li>what form is used for the <a href="#url-of-doc">URL of the document
dbaron@3240 641 being styled</a> (and what has been normalized in that form)</li>
dbaron@3240 642 <li>what normalization (if any) happens to the argument of each of the match
dbaron@3240 643 functions before the comparison that they describe and</li>
dbaron@3240 644 <li>whether the
dbaron@3240 645 comparison algorithm used is string comparison or some other URL
dbaron@3240 646 comparison algorithm.</li></ul></div>
dbaron@3027 647
dbaron@2983 648 <p>The '@document' rule's condition is written as a
dbaron@2974 649 comma-separated list of <dfn>URL matching functions</dfn>, and the
dbaron@2974 650 condition evaluates to true whenever any one of those functions
dbaron@2974 651 evaluates to true. The following URL matching functions are
dbaron@2974 652 permitted:</p>
dbaron@2974 653
dbaron@2974 654 <dl>
jackalmage@6617 655 <dt><dfn id="url-exact" title="url()|URL matching functions::exact">&lt;url&gt;</dfn></dt>
dbaron@2974 656
dbaron@2974 657 <dd>
dbaron@2983 658 <p>The 'url()' function is the <dfn>exact url matching
dbaron@3027 659 function</dfn>. It evaluates to true whenever the <a
dbaron@3027 660 href="#url-of-doc">URL of the document being styled</a> is exactly
dbaron@3027 661 the URL given.</p>
dbaron@2974 662
dbaron@2983 663 <p class="Note">The 'url()' function, since it is a core syntax
dbaron@2974 664 element in CSS, is allowed (subject to different character
dbaron@2974 665 limitations and thus escaping requirements) to contain an unquoted
dbaron@2974 666 value (in addition to the string values that are allowed as
dbaron@2974 667 arguments for all four functions).</p>
dbaron@2974 668
dbaron@2974 669 <div class="example">
dbaron@2974 670 <p>For example, this rule:</p>
dbaron@2974 671 <pre>@document url("http://www.w3.org/Style/CSS/") {
dbaron@2974 672 #summary { background: yellow; color: black}
dbaron@2974 673 }</pre>
dbaron@2983 674 <p>styles the <code class="html">summary</code> element on the page
dbaron@2974 675 <code>http://www.w3.org/Style/CSS/</code>, but not on any other
dbaron@2974 676 pages.</p>
dbaron@2974 677 </div>
dbaron@2974 678 </dd>
dbaron@2974 679
jackalmage@6617 680 <dt><dfn id="url-prefix" title="url-prefix()|URL matching functions::prefix">url-prefix(&lt;string&gt;)</dfn></dt>
dbaron@2974 681
dbaron@2974 682 <dd>
dbaron@2983 683 <p>The 'url-prefix()' function is the <dfn>url prefix
dbaron@3027 684 matching function</dfn>. It evaluates to true whenever the
dbaron@3027 685 <a href="#url-of-doc">URL of the document being styled</a>
dbaron@3027 686 has the argument to the function as an
dbaron@2974 687 initial substring (which is true when the two strings are equal).
dbaron@2974 688 When the argument is the empty string, it evaluates to true for all
dbaron@2974 689 documents.</p>
dbaron@2974 690 <div class="example">
dbaron@2974 691 <p>For example, this rule:</p>
dbaron@2974 692 <pre>@document url-prefix("http://www.w3.org/Style/CSS/") {
dbaron@2974 693 #summary { background: yellow; color: black}
dbaron@2974 694 }</pre>
dbaron@2983 695 <p>styles the <code class="html">summary</code> element on the page
dbaron@2974 696 <code>http://www.w3.org/Style/CSS/</code> and on the page
dbaron@2974 697 <code>http://www.w3.org/Style/CSS/Test</code>, but it does not
dbaron@2974 698 affect the page <code>http://www.w3.org/</code> or the page
dbaron@2974 699 <code>http://www.example.com/Style/CSS/</code>.</p>
dbaron@2974 700 </div>
dbaron@2974 701 </dd>
dbaron@2974 702
jackalmage@6617 703 <dt><dfn id="url-domain" title="domain()|URL matching functions::domain">domain(&lt;string&gt;)</dfn></dt>
dbaron@2974 704
dbaron@2974 705 <dd>
dbaron@2983 706 <p>The 'domain()' function is the <dfn>domain
dbaron@2974 707 matching function</dfn>. It evaluates to true whenever
dbaron@3027 708 the <a href="#url-of-doc">URL of the document being styled</a>
dbaron@3027 709 has a host subcomponent (as defined in [[!URI]])
dbaron@2974 710 and that host subcomponent is exactly the argument to the
dbaron@2983 711 'domain()' function or a final substring of the host
dbaron@2974 712 component is a period (U+002E) immediately followed by the argument
dbaron@2983 713 to the 'domain()' function.</p>
dbaron@2974 714 <div class="example">
dbaron@2974 715 <p>For example, this rule:</p>
dbaron@2974 716 <pre>@document domain("w3.org") {
dbaron@2974 717 body { font-size: 16px ! important }
dbaron@2974 718 }</pre>
dbaron@2974 719 <p>changes the font size of the body element for pages such as
dbaron@2974 720 <code>http://www.w3.org/Style/CSS/</code> and
dbaron@2974 721 <code>http://w3.org/Style/CSS/</code> and
dbaron@2974 722 <code>http://lists.w3.org/Archives/Public/www-style/</code>
dbaron@2974 723 but it does not affect the page
dbaron@2974 724 <code>http://www.example.com/Style/CSS/</code>.</p>
dbaron@2974 725 </div>
dbaron@2974 726 </dd>
dbaron@2974 727
jackalmage@6617 728 <dt><dfn id="url-regexp" title="regexp()|URL matching functions::regular expression">regexp(&lt;string&gt;)</dfn></dt>
dbaron@2974 729
dbaron@2974 730 <dd>
dbaron@2986 731 <p>The contents of the &lt;string&gt; argument <strong>must</strong>
dbaron@3068 732 match the JavaScript <code>Pattern</code> production
dbaron@3068 733 ([[!ECMA-262-5.1]], section 15.10.1). However,
dbaron@2986 734 failing to do so is not a CSS syntax error and does not trigger any
dbaron@2986 735 error handling for CSS syntax errors.</p>
dbaron@2986 736
dbaron@2986 737 <p>The ''regexp()'' function evaluates to true whenever the string
dbaron@2986 738 argument compiled as a JavaScript regular expression with the
dbaron@2986 739 <code>global</code>, <code>ignoreCase</code> and
dbaron@2986 740 <code>multiline</code> flags <em>disabled</em>
dbaron@3068 741 (see [[!ECMA-262-5.1]], sections 15.10.7.2 through 15.10.7.4)
dbaron@2986 742 compiles successfully and the resulting regular expression matches
dbaron@3027 743 the entirety of the
dbaron@3027 744 <a href="#url-of-doc">URL of the document being styled</a>.</p>
dbaron@2986 745
dbaron@2986 746 <p class="note">Note that regular expression must match the entire
dbaron@2986 747 URL, not just a part of it.</p>
dbaron@2974 748
dbaron@3018 749 <p class="note">Note that this definition intentionally matches the
dbaron@3018 750 behavior of the <a
dbaron@2983 751 href="http://dev.w3.org/html5/spec/common-input-element-attributes.html#attr-input-pattern"><code class="html">pattern</code>
dbaron@2983 752 attribute</a> on the <code class="html">input</code> element
dbaron@2983 753 in [[HTML5]].</p>
dbaron@2986 754
dbaron@2986 755 <div class="example">
dbaron@2986 756 <p>For example, this rule:</p>
dbaron@2986 757 <pre>@document regexp("http://www.w3.org/TR/\\d{4}/[^/]*-CSS2-\\d{8}/") {
dbaron@2986 758 body { font-size: 20px ! important }
dbaron@2986 759 }</pre>
dbaron@2986 760 <p>changes the font size of the body element for pages such as
dbaron@2986 761 <code>http://www.w3.org/TR/2011/PR-CSS2-20110412/</code>.</p>
dbaron@2986 762 <p class="note">Note that the backslashes in the regular
dbaron@2986 763 expression require CSS escaping as ''\\''.</p>
dbaron@2986 764 </div>
dbaron@2974 765 </dd>
dbaron@2974 766
dbaron@2974 767 </dl>
dbaron@2974 768
dbaron@2979 769 <p>Implementations <strong>must</strong> treat any unknown URL matching
dbaron@3045 770 functions as a syntax error, and thus ignore the '@document' rule.
dbaron@3045 771 <span class="issue">Should we instead have more complicated error
dbaron@3045 772 handling rules to make forward-compatibility work differently, or is
dbaron@3045 773 this rule the best solution for such future expansion anyway?</span></p>
dbaron@2974 774
dbaron@5293 775 <div class="issue">This syntax doesn't offer any ability to do negations,
dbaron@5293 776 which has been requested in <a
jackalmage@6617 777 href="https://bugzilla.mozilla.org/show_bug.cgi?id=349813">Mozilla bug
dbaron@5293 778 349813</a>. Use cases that people have wanted negations for
dbaron@5293 779 include:
dbaron@5293 780 <ul>
dbaron@5293 781 <li>User style sheets that want a particular rule in general, but know
dbaron@5293 782 that that rule does more harm than good on specific sites.</li>
dbaron@5293 783 <li>Authors who have a rule that they want to apply to most of their
dbaron@5293 784 pages, but wish to make a few exceptions for.</li>
dbaron@5293 785 </ul>
dbaron@5293 786 </div>
dbaron@5293 787
dbaron@2974 788 <p>This extends the lexical scanner in the
dbaron@2974 789 <a href="http://www.w3.org/TR/CSS21/grammar.html">Grammar of CSS 2.1</a>
dbaron@2974 790 ([[!CSS21]], Appendix G) by adding:
dbaron@2974 791 <pre>@{D}{O}{C}{U}{M}{E}{N}{T} {return DOCUMENT_SYM;}</pre>
dbaron@2974 792 <p>and the grammar by adding</p>
dbaron@2974 793 <pre>document_rule
dbaron@2974 794 : DOCUMENT_SYM S+ url_match_fn ( "," S* url_match_fn )* group_rule_body
dbaron@2974 795 ;
dbaron@2974 796
dbaron@2974 797 url_match_fn
dbaron@6740 798 : (URI | FUNCTION S* STRING S* ')' ) S*
dbaron@2974 799 ;</pre>
dbaron@2974 800
jackalmage@6617 801 <h2 id="apis">APIs</h2>
dbaron@3416 802
jackalmage@6617 803 <h3 id='extentions-to-cssrule-interface'>
jackalmage@6315 804 Extensions to the <code>CSSRule</code> interface</h3>
dbaron@3416 805
jackalmage@6315 806 <p>The <code>CSSRule</code> interface is extended as follows:
jackalmage@6315 807
jackalmage@6315 808 <pre class='idl'>partial interface CSSRule {
jackalmage@6315 809 const unsigned short SUPPORTS_RULE = 12;
jackalmage@6315 810 const unsigned short DOCUMENT_RULE = 13;
jackalmage@6315 811 }</pre>
jackalmage@6315 812
jackalmage@6315 813
jackalmage@6655 814 <h3 id='the-cssgroupingrule-interface'>
jackalmage@6655 815 The <code>CSSGroupingRule</code> interface</h3>
jackalmage@6655 816
jackalmage@6655 817 <p>The <dfn><code>CSSGroupingRule</code></dfn> interface represents an at-rule that contains other rules nested inside itself.
jackalmage@6655 818
jackalmage@6655 819 <pre class='idl'>interface CSSGroupingRule : CSSRule {
jackalmage@6655 820 readonly attribute CSSRuleList cssRules;
jackalmage@6655 821 unsigned long insertRule (DOMString rule, unsigned long index);
jackalmage@6655 822 void deleteRule (unsigned long index);
jackalmage@6655 823 }</pre>
jackalmage@6655 824
jackalmage@6655 825 <dl class='idl-attributes'>
jackalmage@6655 826 <dt><code>cssRules</code> of type <code>CSSRuleList</code>, readonly
jackalmage@6655 827 <dd>The <code>cssRules</code> attribute must return a <code>CSSRuleList</code>
jackalmage@6655 828 object for the list of CSS rules nested inside the grouping rule.
jackalmage@6655 829 </dl>
jackalmage@6655 830
jackalmage@6655 831 <dl class='idl-methods'>
jackalmage@6655 832 <dt><code>insertRule(DOMString rule, unsigned long index)</code>, returns
jackalmage@6655 833 <code>unsigned long</code>
jackalmage@6655 834 <dd>The <code>insertRule</code> operation must insert a CSS rule <var>rule</var>
jackalmage@6655 835 into the CSS rule list returned by <code>cssRules</code> at <var>index</var>.
jackalmage@6655 836
jackalmage@6655 837 <dt><code>deleteRule (unsigned long index)</code>, return <code>void</code>
jackalmage@6655 838 <dd>The <code>deleteRule</code> operation must remove a CSS rule from the
jackalmage@6655 839 CSS rule list returned by <code>cssRules</code> at <var>index</var>.
jackalmage@6655 840 </dl>
jackalmage@6655 841
jackalmage@6655 842
jackalmage@6618 843 <h3 id="the-cssconditionrule-interface">
jackalmage@6618 844 The <code>CSSConditionRule</code> interface</h3>
jackalmage@6315 845
jackalmage@6620 846 <p>The <dfn><code>CSSConditionRule</code></dfn> interface represents all the "conditional" at-rules,
jackalmage@6620 847 which consist of a condition and a statement block.
dbaron@6323 848
jackalmage@6655 849 <pre class='idl'>interface CSSConditionRule : CSSGroupingRule {
dbaron@6324 850 attribute DOMString conditionText;
jackalmage@6315 851 }</pre>
jackalmage@6315 852
jackalmage@6315 853 <dl class='idl-attributes'>
dbaron@6732 854
jackalmage@6619 855 <dt><code>conditionText</code> of type <code>DOMString</code>
dbaron@6732 856 <dd>
dbaron@6732 857 <p>The <code>conditionText</code> attribute represents
dbaron@6732 858 the condition of the rule.
dbaron@6732 859 Since what this condition does
dbaron@6732 860 varies between the derived interfaces of <code>CSSConditionRule</code>,
dbaron@6732 861 those derived interfaces
dbaron@6732 862 may specify different behavior for this attribute
dbaron@6732 863 (see, for example, <code>CSSMediaRule</code> below).
dbaron@6732 864 In the absence of such rule-specific behavior,
dbaron@6732 865 the following rules apply:</p>
dbaron@6732 866
dbaron@6732 867 <p>The <code>conditionText</code> attribute, on getting, must return
jackalmage@6618 868 the result of serializing the associated condition.
jackalmage@6315 869
dbaron@6324 870 <p>On setting the <code>conditionText</code> attribute these steps
jackalmage@6315 871 must be run:
jackalmage@6315 872
jackalmage@6315 873 <ol>
jackalmage@6315 874 <li>Trim the given value of white space.
jackalmage@6315 875 <li>If the given value matches the grammar of the
jackalmage@6618 876 appropriate condition production for the given rule,
jackalmage@6618 877 replace the associated CSS condition with the given value.
jackalmage@6315 878 <li>Otherwise, do nothing.
jackalmage@6315 879 </ol>
jackalmage@6315 880 </dl>
jackalmage@6315 881
jackalmage@6618 882
jackalmage@6618 883 <h3 id="the-cssmediarule-interface">
jackalmage@6618 884 The <code>CSSMediaRule</code> interface</h3>
jackalmage@6618 885
jackalmage@6618 886 <p>The <dfn><code>CSSMediaRule</code></dfn> interface represents a ''@media'' rule:
jackalmage@6618 887
jackalmage@6618 888 <pre class='idl'>interface CSSMediaRule : CSSConditionRule {
jackalmage@6618 889 readonly attribute MediaList media;
jackalmage@6618 890 }</pre>
jackalmage@6618 891
jackalmage@6618 892 <dl class='idl-attributes'>
jackalmage@6618 893 <dt><code>media</code> of type <code>MediaList</code>, readonly
jackalmage@6618 894 <dd>The <code>media</code> attribute must return a <code>MediaList</code> object
jackalmage@6618 895 for the list of media queries specified with the ''@media'' rule.
jackalmage@6618 896
jackalmage@6619 897 <dt><code>conditionText</code> of type <code>DOMString</code>
jackalmage@6618 898 <dd>The <code>conditionText</code> attribute (defined on the <code>CSSConditionRule</code> parent rule),
jackalmage@6618 899 on getting, must return the value of <code>media.mediaText</code> on the rule.
jackalmage@6618 900
jackalmage@6621 901 <p>Setting the <code>conditionText</code> attribute
jackalmage@6621 902 must set the <code>media.mediaText</code> attribute on the rule.
jackalmage@6621 903 </dl>
jackalmage@6618 904
jackalmage@6618 905
jackalmage@6618 906 <h3 id="the-csssupportsrule-interface">
jackalmage@6618 907 The <code>CSSSupportsRule</code> interface</h3>
jackalmage@6618 908
jackalmage@6618 909 <p>The <dfn><code>CSSSupportsRule</code></dfn> interface represents a ''@supports'' rule.</p>
jackalmage@6618 910
jackalmage@6621 911 <pre class='idl'>interface CSSSupportsRule : CSSConditionRule {
jackalmage@6618 912 }</pre>
jackalmage@6618 913
jackalmage@6618 914
jackalmage@6618 915 <h3 id="the-cssdocumentrule-interface">
jackalmage@6618 916 The <code>CSSDocumentRule</code> interface</h3>
jackalmage@6618 917
jackalmage@6618 918 <p>The <dfn><code>CSSDocumentRule</code></dfn> interface represents a ''@document'' rule.</p>
jackalmage@6618 919
jackalmage@6621 920 <pre class='idl'>interface CSSDocumentRule : CSSConditionRule {
jackalmage@6618 921 }</pre>
jackalmage@6315 922
jackalmage@6315 923
jackalmage@6620 924 <h3 id='the-css-interface'>
jackalmage@6620 925 The <code>CSS</code> interface, and the <code title=''>supports()</code> function</h3>
jackalmage@6315 926
jackalmage@6620 927 <p>The <dfn id='CSS-interface'><code>CSS</code></dfn> interface holds useful CSS-related functions that do not belong elsewhere.
jackalmage@6315 928
jackalmage@6620 929 <pre class='idl'>interface CSS {
jackalmage@6620 930 boolean supports(DOMString property, DOMString value);
jackalmage@6620 931 boolean supports(DOMString declaration);
jackalmage@6620 932 }</pre>
jackalmage@6620 933
jackalmage@6620 934 <dl class='idl-methods'>
jackalmage@6620 935 <dt><code>supports(DOMString property, DOMString value)</code>,
jackalmage@6620 936 returns <code>boolean</code>
jackalmage@6625 937 <dt><code>supports(DOMString conditionText)</code>,
jackalmage@6620 938 returns <code>boolean</code>
jackalmage@6620 939 <dd>
jackalmage@6620 940 When the <code title=''>supports()</code> method is invoked with two arguments <var>property</var> and <var>value</var>,
jackalmage@6620 941 it must return <code>true</code> if <var>property</var> is a literal match for the name of a CSS property that the UA supports,
jackalmage@6620 942 and <var>value</var> would be successfully parsed as a supported value for that property.
jackalmage@6620 943 Otherwise, it must return <code>false</code>.
jackalmage@6620 944
jackalmage@6620 945 <p>
jackalmage@6625 946 When invoked with a single <var>conditionText</var> argument,
jackalmage@6625 947 it must return <code>true</code> if <var>conditionText</var>,
jackalmage@6625 948 when parsed and evaluated as a <code>supports_condition</code>,
jackalmage@6625 949 would return true.
jackalmage@6620 950 Otherwise, it must return <code>false</code>.
jackalmage@6620 951 </dl>
jackalmage@6620 952
dbaron@3417 953
jackalmage@6617 954 <h2 id="conformance">Conformance</h2>
dbaron@2974 955
jackalmage@6617 956 <h3 id="base-modules">Base Modules</h3>
dbaron@3022 957
dbaron@3022 958 <p>This specification defines conformance in terms of base modules,
dbaron@3022 959 which are modules that this specification builds on top of. The base
dbaron@3022 960 modules of this module are:</p>
dbaron@3022 961
dbaron@3022 962 <ul>
dbaron@3022 963 <li>[[!CSS21]]</li>
dbaron@3022 964 </ul>
dbaron@3022 965
dbaron@3022 966 <p>All of the conformance requirements of all base modules are
dbaron@3022 967 incorporated as conformance requirements of this module, except where
dbaron@3022 968 overridden by this module.</p>
dbaron@3022 969
dbaron@3022 970 <p>Additionally, all conformance requirements related to validity of
dbaron@3022 971 syntax in this module and all of its base modules are to be interpreted
dbaron@3022 972 as though all syntax in all of those modules is valid.</p>
dbaron@3022 973
dbaron@3022 974 <div class="example"><p>For example, this means that grammar presented
dbaron@3022 975 in modules other than [[!CSS21]] must obey the requirements that
dbaron@3022 976 [[!CSS21]] defines for the parsing of properties, and that requirements
dbaron@3022 977 for handling invalid syntax in [[!CSS21]] do not treat syntax added by
dbaron@3022 978 other modules as invalid.</p></div>
dbaron@3022 979
dbaron@3022 980 <p>Additionally, the set of valid syntax can be increased by the
dbaron@3022 981 conformance of a style sheet or processor to additional modules; use of
dbaron@3022 982 such syntax does not make a style sheet nonconformant and failure to
dbaron@3022 983 treat such syntax as invalid does not make a processor
dbaron@3022 984 nonconformant.</p>
dbaron@3022 985
jackalmage@6617 986 <h3 id="conformance-classes">Conformance Classes</h3>
dbaron@2974 987
dbaron@2974 988 <p>Conformance to the CSS Conditional Rules Module is defined for three
dbaron@2974 989 conformance classes:
dbaron@2974 990 <dl>
jackalmage@6617 991 <dt><dfn title="conformance::style sheet" id="conform-style-sheet">style sheet</dfn>
dbaron@2974 992 <dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS
dbaron@3022 993 style sheet</a>.</dd>
jackalmage@6617 994 <dt><dfn title="conformance::processor" id="conform-processor">processor</dfn></dt>
dbaron@3022 995 <dd>A tool that reads CSS style sheets: it may be a renderer or
dbaron@3022 996 <a
dbaron@3022 997 href="http://www.w3.org/TR/CSS21/conform.html#user-agent">user-agent</a>
dbaron@2974 998 that interprets the semantics of a style sheet and renders
dbaron@3022 999 documents that use style sheets, or it may be a validator that
dbaron@3022 1000 checks style sheets.</dd>
jackalmage@6617 1001 <dt><dfn title="conformance::authoring tool" id="conform-authoring-tool">authoring tool</dfn></dt>
dbaron@3022 1002 <dd>A tool that writes a style sheet.</dd>
dbaron@2974 1003 </dl>
dbaron@3022 1004
dbaron@3022 1005 <p>A style sheet is conformant to the CSS Conditional Rules Module
dbaron@3022 1006 if it meets all of the conformance requirements in the module that are
dbaron@3022 1007 described as requirements of style sheets.</p>
dbaron@3022 1008
dbaron@3022 1009 <p>A processor is conformant to the CSS Conditional Rules Module if it
dbaron@3022 1010 meets all applicable conformance requirements in the module that are
dbaron@3022 1011 described as requirements of processors. In general, all requirements
dbaron@3022 1012 are applicable to renderers. Requirements concerning a part of CSS
dbaron@3022 1013 not performed by a processor are not applicable, e.g., requirements
dbaron@3022 1014 related to rendering are not applicable to a validator. The inability
dbaron@3022 1015 of a processor to correctly render a document due to limitations of
dbaron@3022 1016 the device does not make it non-conformant. (For example, a renderer
dbaron@3022 1017 is not required to render color on a monochrome monitor.)</p>
dbaron@3022 1018
dbaron@3022 1019 <p>An authoring tool is conformant to the CSS Conditional Rules Module
dbaron@3022 1020 if it writes style sheets that conform to the module and (if it reads
dbaron@3022 1021 CSS) it is a conformant processor.</p>
dbaron@2974 1022
jackalmage@6617 1023 <h3 id="partial">
dbaron@2974 1024 Partial Implementations</h3>
dbaron@2974 1025
dbaron@2974 1026 <p>So that authors can exploit the forward-compatible parsing rules to
dbaron@2974 1027 assign fallback values, CSS renderers <strong>must</strong>
dbaron@2974 1028 treat as invalid (and <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignore
dbaron@2974 1029 as appropriate</a>) any at-rules, properties, property values, keywords,
dbaron@2974 1030 and other syntactic constructs for which they have no usable level of
dbaron@2974 1031 support. In particular, user agents <strong>must not</strong> selectively
dbaron@2974 1032 ignore unsupported component values and honor supported values in a single
dbaron@2974 1033 multi-value property declaration: if any value is considered invalid
dbaron@2974 1034 (as unsupported values must be), CSS requires that the entire declaration
dbaron@2974 1035 be ignored.</p>
dbaron@2974 1036
jackalmage@6617 1037 <h3 id="experimental">Experimental Implementations</h3>
dbaron@2974 1038
dbaron@2974 1039 <p>To avoid clashes with future CSS features, the CSS specifications
dbaron@2974 1040 reserve a <a href="http://www.w3.org/TR/CSS21/syndata.html#vendor-keywords">prefixed
dbaron@2974 1041 syntax</a> for proprietary property and value extensions to CSS. The CSS
dbaron@2974 1042 Working Group recommends that experimental implementations of features in
dbaron@2974 1043 CSS Working Drafts also use vendor-prefixed property or value names. This
dbaron@2974 1044 avoids any incompatibilities with future changes in the draft. Once a
dbaron@2974 1045 specification reaches the Candidate Recommendation stage, implementors
dbaron@2974 1046 should implement the non-prefixed syntax for any feature they consider to
dbaron@2974 1047 be correctly implemented according to spec.</p>
dbaron@2974 1048
jackalmage@6617 1049 <h3 id="cr-exit-criteria">CR Exit Criteria</h3>
dbaron@2974 1050
dbaron@3244 1051 <p>For this specification to be advanced to Proposed Recommendation,
dbaron@2974 1052 there must be at least two independent, interoperable implementations
dbaron@2974 1053 of each feature. Each feature may be implemented by a different set of
dbaron@2974 1054 products, there is no requirement that all features be implemented by
dbaron@2974 1055 a single product. For the purposes of this criterion, we define the
dbaron@2974 1056 following terms:
dbaron@2974 1057
dbaron@2974 1058 <dl>
dbaron@2974 1059 <dt>independent <dd>each implementation must be developed by a
dbaron@2974 1060 different party and cannot share, reuse, or derive from code
dbaron@2974 1061 used by another qualifying implementation. Sections of code that
dbaron@2974 1062 have no bearing on the implementation of this specification are
dbaron@2974 1063 exempt from this requirement.
dbaron@2974 1064
dbaron@2974 1065 <dt>interoperable <dd>passing the respective test case(s) in the
dbaron@2974 1066 official CSS test suite, or, if the implementation is not a Web
dbaron@2974 1067 browser, an equivalent test. Every relevant test in the test
dbaron@2974 1068 suite should have an equivalent test created if such a user
dbaron@2974 1069 agent (UA) is to be used to claim interoperability. In addition
dbaron@2974 1070 if such a UA is to be used to claim interoperability, then there
dbaron@2974 1071 must one or more additional UAs which can also pass those
dbaron@2974 1072 equivalent tests in the same way for the purpose of
dbaron@2974 1073 interoperability. The equivalent tests must be made publicly
dbaron@2974 1074 available for the purposes of peer review.
dbaron@2974 1075
dbaron@2974 1076 <dt>implementation <dd>a user agent which:
dbaron@2974 1077
dbaron@2974 1078 <ol class=inline>
dbaron@2974 1079 <li>implements the specification.
dbaron@2974 1080
dbaron@2974 1081 <li>is available to the general public. The implementation may
dbaron@2974 1082 be a shipping product or other publicly available version
dbaron@2974 1083 (i.e., beta version, preview release, or “nightly build”).
dbaron@2974 1084 Non-shipping product releases must have implemented the
dbaron@2974 1085 feature(s) for a period of at least one month in order to
dbaron@2974 1086 demonstrate stability.
dbaron@2974 1087
dbaron@2974 1088 <li>is not experimental (i.e., a version specifically designed
dbaron@2974 1089 to pass the test suite and is not intended for normal usage
dbaron@2974 1090 going forward).
dbaron@2974 1091 </ol>
dbaron@2974 1092 </dl>
dbaron@2974 1093
dbaron@2974 1094 <p>The specification will remain Candidate Recommendation for at least
dbaron@2974 1095 six months.
dbaron@2974 1096
jackalmage@6617 1097 <h2 class=no-num id="grammar">Grammar</h2>
dbaron@2974 1098
dbaron@2974 1099 <p>In order to allow these new @-rules in CSS style sheets, this
dbaron@2974 1100 specification modifies the <code>stylesheet</code> production in the <a
dbaron@2974 1101 href="http://www.w3.org/TR/CSS21/grammar.html">Appendix G</a> grammar of
dbaron@2974 1102 [[!CSS21]] by replacing the <code>media</code> production defined in
dbaron@2974 1103 [[!CSS21]] with the <code>media</code> production defined in this one,
dbaron@2974 1104 and additionally inserting <code>| supports_rule | document_rule</code>
dbaron@2974 1105 alongside <code>ruleset | media | page</code>.</p>
dbaron@2974 1106
jackalmage@6617 1107 <h2 class=no-num id="acknowledgments">Acknowledgments</h2>
dbaron@2974 1108
dbaron@2974 1109 <p>
dbaron@2974 1110 Thanks to the ideas and feedback from
dbaron@3418 1111 Tab Atkins,
dbaron@2974 1112 <span lang="tr">Tantek Çelik</span>,
dbaron@3418 1113 Alex Danilo,
dbaron@2974 1114 Elika Etemad,
dbaron@2974 1115 Pascal Germroth,
dbaron@2974 1116 <span lang="de">Björn Höhrmann</span>,
dbaron@3417 1117 Paul Irish,
dbaron@3418 1118 Vitor Menezes,
dbaron@2977 1119 Alex Mogilevsky,
dbaron@2974 1120 Chris Moschini,
dbaron@6740 1121 Simon Sapin,
dbaron@2974 1122 Ben Ward,
dbaron@2974 1123 Zack Weinberg,
dbaron@3430 1124 Estelle Weyl,
dbaron@2974 1125 Boris Zbarsky,
dbaron@2974 1126 and all the rest of the <a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a> community.
dbaron@2974 1127
dbaron@2974 1128 </p>
dbaron@2974 1129
jackalmage@6617 1130 <h2 class=no-num id="references">References</h2>
dbaron@2974 1131
dbaron@2974 1132
jackalmage@6617 1133 <h3 class="no-num" id="normative-references">Normative references</h3>
dbaron@2974 1134 <!--normative-->
dbaron@2974 1135
jackalmage@6617 1136 <h3 class="no-num" id="other-references">Other references</h3>
dbaron@2974 1137 <!--informative-->
dbaron@2974 1138
jackalmage@6617 1139 <h2 class="no-num" id="index">Index</h2>
dbaron@2974 1140 <!--index-->
dbaron@2974 1141
dbaron@2974 1142 </body>
dbaron@2974 1143 </html>
dbaron@2974 1144 <!-- Keep this comment at the end of the file
dbaron@2974 1145 Local variables:
dbaron@2974 1146 mode: sgml
dbaron@2974 1147 sgml-declaration:"~/SGML/HTML4.decl"
dbaron@2974 1148 sgml-default-doctype-name:"html"
dbaron@2974 1149 sgml-minimize-attributes:t
dbaron@2974 1150 sgml-nofill-elements:("pre" "style" "br")
dbaron@2974 1151 sgml-live-element-indicator:t
dbaron@2974 1152 sgml-omittag:nil
dbaron@2974 1153 sgml-shorttag:nil
dbaron@2974 1154 sgml-namecase-general:t
dbaron@2974 1155 sgml-general-insert-case:lower
dbaron@2974 1156 sgml-always-quote-attributes:t
dbaron@2974 1157 sgml-indent-step:nil
dbaron@2974 1158 sgml-indent-data:t
dbaron@2974 1159 sgml-parent-document:nil
dbaron@2974 1160 sgml-exposed-tags:nil
dbaron@2974 1161 sgml-local-catalogs:nil
dbaron@2974 1162 sgml-local-ecat-files:nil
dbaron@2974 1163 End:
dbaron@2974 1164 -->
dbaron@2974 1165

mercurial