# HG changeset patch # User Simon Sapin # Date 1361406412 -3600 # Node ID 0dff950123a28944291f53fdd73408964ef54bf0 # Parent b3accb3444d839d4d035938868bae8c4068f9e59 [css3-page] Rewrite page selector specificity for multiple pseudo-classes. Update to Selectors 4 language, while we’re at it. diff -r b3accb3444d8 -r 0dff950123a2 css3-page/Overview.html --- a/css3-page/Overview.html Wed Feb 20 16:24:59 2013 -0800 +++ b/css3-page/Overview.html Thu Feb 21 01:26:52 2013 +0100 @@ -9,7 +9,7 @@ rel=dcterms.rights> - + @@ -99,14 +99,14 @@

CSS Paged Media Module Level 3

-

Editor's Draft 20 February 2013

+

Editor's Draft 21 February 2013

This version:
http://dev.w3.org/csswg/css3-page/
- +
Latest version: @@ -194,7 +194,7 @@

This document contains the CSS3 Paged Media Module W3C Last Call Working Draft - of 20 February 2013. The Last Call period ends on TBD.

Expected next revision to this document is another LCWD, due to the @@ -1068,28 +1068,46 @@ the computations defined in the Selectors module: +

Each comma-separated selectors in the same ‘@page’ rule match pages with its own specificity. + ‘@page’ rules without selectors are considered + to have a single, empty selector (whose specificity is zero.) +

    -
  • if the page selector has a named page, f=1; else f=0 - -
  • if the page selector has a ‘:first’ or - ‘:blank’ pseudo-class, g=1; else g=0 - -
  • if the page selector has a ‘:left’ or - ‘:right’ pseudo-class, h=1; else h=0 +
  • Count the number of page names (= f) +

    This is 0 or 1. + +

  • Count the number of ‘:first’ or ‘:blank’ pseudo-classes (= g) + +
  • Count the number of ‘:left’ or ‘:right’ pseudo-classes (= h)
-

Concatenating the three numbers f-g-h gives the specificity. +

Specificities are compared by comparing the three components in order: + the specificity with f larger a value is more specific; if the + two f values are tied, then the specificity with a larger + g value is more specific; if the two g values are + also tied, then the specificity with a larger h value is more + specific; if all the values are tied, the two specifities are equal. + +

Due to storage limitations, implementations may have limitations on + the size of f, g, or h. If so, values + higher than the limit must be clamped to that limit, and not overflow. + +

Note: Repeated occurrances of the same pseudo-classes are + allowed and do increase specificity.

Some page specificity calculation examples follow:

-      @page { } /* f=0 g=0 h=0 -> specificity = 000 */
-      @page :left { } /* f=0 g=0 h=1 -> specificity = 001 */
-      @page :first { } /* f=0 g=1 h=0 -> specificity = 010 */
-      @page artsy { } /* f=1 g=0 h=0 -> specificity = 100 */
-      @page artsy:left { } /* f=1 g=0 h=1 -> specificity = 101 */
-      @page artsy:first { } /* f=1 g=1 h=0 -> specificity = 110 */
+@page { } /* specificity = (0,0,0) */
+@page :left { } /* specificity = (0,0,1) */
+@page :first { } /* specificity = (0,1,0) */
+@page artsy { } /* specificity = (1,0,0) */
+@page artsy:left { } /* specificity = (1,0,1) */
+@page artsy:first { } /* specificity = (1,1,0) */
 
@@ -1098,11 +1116,11 @@
 @page {
-margin-left: 3cm;
+  margin-left: 3cm;
 }
 
 @page :left {
-margin-left: 4cm;
+  margin-left: 4cm;
 }
 
@@ -1119,20 +1137,20 @@
 @page :first {
-color: green;
-
-@top-left {
-  content: "foo";
-  color: blue;
+  color: green;
+
+  @top-left {
+    content: "foo";
+    color: blue;
+  }
+  @top-right {
+    content: "bar";
+  }
 }
-@top-right {
-  content: "bar";
-}
-}
 
 @page { color: red;
-@top-center {
-  content: "Page " counter(page);
+  @top-center {
+    content: "Page " counter(page);
   }
 }
 
diff -r b3accb3444d8 -r 0dff950123a2 css3-page/Overview.src.html --- a/css3-page/Overview.src.html Wed Feb 20 16:24:59 2013 -0800 +++ b/css3-page/Overview.src.html Thu Feb 21 01:26:52 2013 +0100 @@ -769,24 +769,48 @@ computations defined in the Selectors module:

+

Each comma-separated selectors in the same ''@page'' rule + match pages with its own specificity. + ''@page'' rules without selectors are considered to have a single, + empty selector (whose specificity is zero.) +

    -
  • if the page selector has a named page, f=1; else f=0
  • -
  • if the page selector has a ':first' or ':blank' pseudo-class, g=1; else g=0
  • -
  • if the page selector has a ':left' or ':right' pseudo-class, h=1; else h=0
  • +
  • Count the number of page names (= f) +

    This is 0 or 1. +

  • Count the number of ':first' or ':blank' pseudo-classes (= g) +
  • Count the number of ':left' or ':right' pseudo-classes (= h)
-

Concatenating the three numbers f-g-h gives the specificity.

+

+ Specificities are compared by comparing the three components in order: + the specificity with f larger a value is more specific; + if the two f values are tied, + then the specificity with a larger g value is more specific; + if the two g values are also tied, + then the specificity with a larger h value is more specific; + if all the values are tied, the two specifities are equal. + +

+ Due to storage limitations, + implementations may have limitations on + the size of f, g, or h. + If so, values higher than the limit must be clamped to that limit, + and not overflow. + +

+Note: Repeated occurrances of the same pseudo-classes are allowed + and do increase specificity.

Some page specificity calculation examples follow:

-      @page { } /* f=0 g=0 h=0 -> specificity = 000 */
-      @page :left { } /* f=0 g=0 h=1 -> specificity = 001 */
-      @page :first { } /* f=0 g=1 h=0 -> specificity = 010 */
-      @page artsy { } /* f=1 g=0 h=0 -> specificity = 100 */
-      @page artsy:left { } /* f=1 g=0 h=1 -> specificity = 101 */
-      @page artsy:first { } /* f=1 g=1 h=0 -> specificity = 110 */
+@page { } /* specificity = (0,0,0) */
+@page :left { } /* specificity = (0,0,1) */
+@page :first { } /* specificity = (0,1,0) */
+@page artsy { } /* specificity = (1,0,0) */
+@page artsy:left { } /* specificity = (1,0,1) */
+@page artsy:first { } /* specificity = (1,1,0) */
 
@@ -795,21 +819,20 @@

Consider the following usage example:

 @page {
-margin-left: 3cm;
+  margin-left: 3cm;
 }
 
 @page :left {
-margin-left: 4cm;
+  margin-left: 4cm;
 }
 
-

Due to the higher specificity of the pseudo-class selector, the left margin on -left pages will be 4cm and all other pages -(the right-facing pages) will have a left margin of 3cm.

+

Due to the higher specificity of the pseudo-class selector, +the left margin on left pages will be 4cm and all other pages +(the right-facing pages) will have a left margin of 3cm.

-

In this example, the higher specificity of the green rules wins over the red rule. Therefore the first page will have blue text in the top-left page-margin box @@ -817,20 +840,20 @@ while subsequent pages will have red text in the page-margin boxes.

 @page :first {
-color: green;
+  color: green;
 
-@top-left {
-  content: "foo";
-  color: blue;
-}
-@top-right {
-  content: "bar";
-}
+  @top-left {
+    content: "foo";
+    color: blue;
+  }
+  @top-right {
+    content: "bar";
+  }
 }
 
 @page { color: red;
-@top-center {
-  content: "Page " counter(page);
+  @top-center {
+    content: "Page " counter(page);
   }
 }