Author: jmb
Date: Sun Jan 25 12:59:53 2009
New Revision: 6267

URL: http://source.netsurf-browser.org?rev=6267&view=rev
Log:
Beginnings of specificity. 
Note that we store the specificity on each simple selector. Thus the total 
specificity for a combinator chain is obtained by summing the specificity of 
each chain member.
TODO: distinguish between pseudo classes and elements.


Modified:
    trunk/libcss/src/stylesheet.c
    trunk/libcss/src/stylesheet.h

Modified: trunk/libcss/src/stylesheet.c
URL: 
http://source.netsurf-browser.org/trunk/libcss/src/stylesheet.c?rev=6267&r1=6266&r2=6267&view=diff
==============================================================================
--- trunk/libcss/src/stylesheet.c (original)
+++ trunk/libcss/src/stylesheet.c Sun Jan 25 12:59:53 2009
@@ -395,8 +395,12 @@
        sel->data.name = name;
        sel->data.value = NULL;
 
-       /** \todo specificity */
-       sel->specificity = 0;
+       /* Initial specificity -- 1 for an element, 0 for universal */
+       if (name->len != 1 || name->data[0] != '*')
+               sel->specificity = CSS_SPECIFICITY_D;
+       else
+               sel->specificity = 0;
+
        sel->data.comb = CSS_COMBINATOR_NONE;
 
        *selector = sel;
@@ -492,6 +496,28 @@
        (&temp->data)[num_details].next = 1;
 
        (*parent) = temp;
+
+       /* Update parent's specificity */
+       switch (detail->type) {
+       case CSS_SELECTOR_CLASS:
+       case CSS_SELECTOR_ATTRIBUTE:
+       case CSS_SELECTOR_ATTRIBUTE_EQUAL:
+       case CSS_SELECTOR_ATTRIBUTE_DASHMATCH:
+       case CSS_SELECTOR_ATTRIBUTE_INCLUDES:
+               (*parent)->specificity += CSS_SPECIFICITY_C;
+               break;
+       case CSS_SELECTOR_ID:
+               (*parent)->specificity += CSS_SPECIFICITY_B;
+               break;
+       case CSS_SELECTOR_PSEUDO:
+               /** \todo distinguish between pseudo classes and elements */
+               /* Assume pseudo class for now */
+               (*parent)->specificity += CSS_SPECIFICITY_C;
+               break;
+       case CSS_SELECTOR_ELEMENT:
+               (*parent)->specificity += CSS_SPECIFICITY_D;
+               break;
+       }
 
        return CSS_OK;
 }

Modified: trunk/libcss/src/stylesheet.h
URL: 
http://source.netsurf-browser.org/trunk/libcss/src/stylesheet.h?rev=6267&r1=6266&r2=6267&view=diff
==============================================================================
--- trunk/libcss/src/stylesheet.h (original)
+++ trunk/libcss/src/stylesheet.h Sun Jan 25 12:59:53 2009
@@ -63,6 +63,10 @@
 
        css_rule *rule;                         /**< Owning rule */
 
+#define CSS_SPECIFICITY_A 0x01000000
+#define CSS_SPECIFICITY_B 0x00010000
+#define CSS_SPECIFICITY_C 0x00000100
+#define CSS_SPECIFICITY_D 0x00000001
        uint32_t specificity;                   /**< Specificity of selector */
 
        css_selector_detail data;               /**< Selector data */


_______________________________________________
netsurf-commits mailing list
[email protected]
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to