[gtk+] GtkCssProvider: Make selectors applying from the topmost widget rank higher



commit 618b1a8b33398213541888d81ee5788017415f42
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Dec 13 12:44:29 2010 +0100

    GtkCssProvider: Make selectors applying from the topmost widget rank higher
    
    For example, for an entry within a notebook, previously these 2 rules would
    have the same weight:
    
    .entry {}
    .notebook {}
    
    Now ".entry" will rank higher than ".notebook" for the GtkEntry, further
    specific selectors such as:
    
    .notebook .entry {}
    
    still get a higher score than the previous ones.

 gtk/gtkcssprovider.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 0e1f8af..02356f4 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1150,7 +1150,7 @@ compare_selector (GtkWidgetPath *path,
                   SelectorPath  *selector)
 {
   GSList *elements = selector->elements;
-  gboolean match = TRUE;
+  gboolean match = TRUE, first = TRUE, first_match = FALSE;
   guint64 score = 0;
   gint i;
 
@@ -1165,6 +1165,9 @@ compare_selector (GtkWidgetPath *path,
 
       match = compare_selector_element (path, i, elem, &elem_score);
 
+      if (match && first)
+        first_match = TRUE;
+
       /* Only move on to the next index if there is no match
        * with the current element (whether to continue or not
        * handled right after in the combinator check), or a
@@ -1197,6 +1200,8 @@ compare_selector (GtkWidgetPath *path,
           score <<= 4;
           score |= elem_score;
         }
+
+      first = FALSE;
     }
 
   /* If there are pending selector
@@ -1208,6 +1213,13 @@ compare_selector (GtkWidgetPath *path,
 
   if (!match)
     score = 0;
+  else if (first_match)
+    {
+      /* Assign more weight to these selectors 
+       * that matched right from the first element.
+       */
+      score <<= 4;
+    }
 
   return score;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]