[gtk/matthiasc/css-change-tracking-4: 17/20] Redo the way we compute change



commit 0c53eaebd3949443ddc92fc7244fdad88da4a314
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 17 11:10:14 2020 -0500

    Redo the way we compute change
    
    Instead of expecting a superset matcher, call
    gtk_css_selector_match_for_change while walking the tree with the
    original matcher. This fixes the handling of :not while determining
    changes.

 gtk/gtkcssselector.c | 56 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 37 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 9844e2ea65..6909d86f6d 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -62,7 +62,8 @@ struct _GtkCssSelectorClass {
   int               (* compare_one) (const GtkCssSelector       *a,
                                     const GtkCssSelector       *b);
 
-  guint         is_simple :1;
+  guint         is_simple         : 1;
+  guint         ignore_for_change : 1;
 };
 
 typedef enum {
@@ -319,7 +320,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_DESCENDANT = {
   gtk_css_selector_default_add_specificity,
   gtk_css_selector_default_hash_one,
   gtk_css_selector_default_compare_one,
-  FALSE
+  FALSE,
+  TRUE
 };
 
 /* CHILD */
@@ -360,7 +362,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_CHILD = {
   gtk_css_selector_default_add_specificity,
   gtk_css_selector_default_hash_one,
   gtk_css_selector_default_compare_one,
-  FALSE
+  FALSE,
+  TRUE
 };
 
 /* SIBLING */
@@ -411,7 +414,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_SIBLING = {
   gtk_css_selector_default_add_specificity,
   gtk_css_selector_default_hash_one,
   gtk_css_selector_default_compare_one,
-  FALSE
+  FALSE,
+  TRUE
 };
 
 /* ADJACENT */
@@ -452,7 +456,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_ADJACENT = {
   gtk_css_selector_default_add_specificity,
   gtk_css_selector_default_hash_one,
   gtk_css_selector_default_compare_one,
-  FALSE
+  FALSE,
+  TRUE
 };
 
 /* SIMPLE SELECTOR DEFINE */
@@ -465,7 +470,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_ADJACENT = {
                                comp_func, \
                                increase_id_specificity, \
                                increase_class_specificity, \
-                               increase_element_specificity) \
+                               increase_element_specificity, \
+                               ignore_for_change) \
 static void \
 gtk_css_selector_ ## n ## _print (const GtkCssSelector *selector, \
                                     GString              *string) \
@@ -524,7 +530,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_ ## c = { \
   gtk_css_selector_ ## n ## _add_specificity, \
   hash_func, \
   comp_func, \
-  TRUE \
+  TRUE, \
+  ignore_for_change \
 };\
 \
 static const GtkCssSelectorClass GTK_CSS_SELECTOR_NOT_ ## c = { \
@@ -536,7 +543,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_NOT_ ## c = { \
   gtk_css_selector_ ## n ## _add_specificity, \
   hash_func, \
   comp_func, \
-  TRUE \
+  TRUE, \
+  ignore_for_change \
 };
 
 /* ANY */
@@ -559,7 +567,7 @@ match_any (const GtkCssSelector *selector,
 #define GTK_CSS_CHANGE_ANY 0
 DEFINE_SIMPLE_SELECTOR(any, ANY, print_any, match_any, 
                        gtk_css_selector_default_hash_one, gtk_css_selector_default_compare_one,
-                       FALSE, FALSE, FALSE)
+                       FALSE, FALSE, FALSE, TRUE)
 #undef GTK_CSS_CHANGE_ANY
 
 /* NAME */
@@ -592,7 +600,7 @@ comp_name (const GtkCssSelector *a,
                 b->name.name);
 }
 
-DEFINE_SIMPLE_SELECTOR(name, NAME, print_name, match_name, hash_name, comp_name, FALSE, FALSE, TRUE)
+DEFINE_SIMPLE_SELECTOR(name, NAME, print_name, match_name, hash_name, comp_name, FALSE, FALSE, TRUE, FALSE)
 
 /* CLASS */
 
@@ -629,7 +637,7 @@ comp_class (const GtkCssSelector *a,
     return 0;
 }
 
-DEFINE_SIMPLE_SELECTOR(class, CLASS, print_class, match_class, hash_class, comp_class, FALSE, TRUE, FALSE)
+DEFINE_SIMPLE_SELECTOR(class, CLASS, print_class, match_class, hash_class, comp_class, FALSE, TRUE, FALSE, 
FALSE)
 
 /* ID */
 
@@ -666,7 +674,7 @@ comp_id (const GtkCssSelector *a,
     return 0;
 }
 
-DEFINE_SIMPLE_SELECTOR(id, ID, print_id, match_id, hash_id, comp_id, TRUE, FALSE, FALSE)
+DEFINE_SIMPLE_SELECTOR(id, ID, print_id, match_id, hash_id, comp_id, TRUE, FALSE, FALSE, FALSE)
 
 const gchar *
 gtk_css_pseudoclass_name (GtkStateFlags state)
@@ -731,31 +739,31 @@ comp_pseudoclass_state (const GtkCssSelector *a,
 #define GTK_CSS_CHANGE_PSEUDOCLASS_HOVER GTK_CSS_CHANGE_HOVER
 DEFINE_SIMPLE_SELECTOR(pseudoclass_hover, PSEUDOCLASS_HOVER, print_pseudoclass_state,
                        match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
-                       FALSE, TRUE, FALSE)
+                       FALSE, TRUE, FALSE, TRUE)
 #undef GTK_CSS_CHANGE_PSEUDOCLASS_HOVER
 
 #define GTK_CSS_CHANGE_PSEUDOCLASS_DISABLED GTK_CSS_CHANGE_DISABLED
 DEFINE_SIMPLE_SELECTOR(pseudoclass_disabled, PSEUDOCLASS_DISABLED, print_pseudoclass_state,
                        match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
-                       FALSE, TRUE, FALSE)
+                       FALSE, TRUE, FALSE, TRUE)
 #undef GTK_CSS_CHANGE_PSEUDOCLASS_DISABLED
 
 #define GTK_CSS_CHANGE_PSEUDOCLASS_BACKDROP GTK_CSS_CHANGE_BACKDROP
 DEFINE_SIMPLE_SELECTOR(pseudoclass_backdrop, PSEUDOCLASS_BACKDROP, print_pseudoclass_state,
                        match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
-                       FALSE, TRUE, FALSE)
+                       FALSE, TRUE, FALSE, TRUE)
 #undef GTK_CSS_CHANGE_PSEUDOCLASS_BACKDROP
 
 #define GTK_CSS_CHANGE_PSEUDOCLASS_SELECTED GTK_CSS_CHANGE_SELECTED
 DEFINE_SIMPLE_SELECTOR(pseudoclass_selected, PSEUDOCLASS_SELECTED, print_pseudoclass_state,
                        match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
-                       FALSE, TRUE, FALSE)
+                       FALSE, TRUE, FALSE, TRUE)
 #undef GTK_CSS_CHANGE_PSEUDOCLASS_SELECTED
 
 #define GTK_CSS_CHANGE_PSEUDOCLASS_STATE GTK_CSS_CHANGE_STATE
 DEFINE_SIMPLE_SELECTOR(pseudoclass_state, PSEUDOCLASS_STATE, print_pseudoclass_state,
                        match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
-                       FALSE, TRUE, FALSE)
+                       FALSE, TRUE, FALSE, TRUE)
 #undef GTK_CSS_CHANGE_PSEUDOCLASS_STATE
 
 /* PSEUDOCLASS FOR POSITION */
@@ -909,7 +917,7 @@ change_pseudoclass_position (const GtkCssSelector *selector)
 #define GTK_CSS_CHANGE_PSEUDOCLASS_POSITION change_pseudoclass_position(selector)
 DEFINE_SIMPLE_SELECTOR(pseudoclass_position, PSEUDOCLASS_POSITION, print_pseudoclass_position,
                        match_pseudoclass_position, hash_pseudoclass_position, comp_pseudoclass_position,
-                       FALSE, TRUE, FALSE)
+                       FALSE, TRUE, FALSE, TRUE)
 #undef GTK_CSS_CHANGE_PSEUDOCLASS_POSITION
 /* API */
 
@@ -1728,6 +1736,16 @@ _gtk_css_selector_matches (const GtkCssSelector *selector,
   return gtk_css_selector_foreach (selector, matcher, gtk_css_selector_foreach_match, NULL);
 }
 
+static gboolean
+gtk_css_selector_match_for_change (const GtkCssSelector *selector,
+                                   const GtkCssMatcher  *matcher)
+{
+  if (selector->class->ignore_for_change)
+    return TRUE;
+
+  return selector->class->match_one (selector, matcher);
+}
+
 /* Computes specificity according to CSS 2.1.
  * The arguments must be initialized to 0 */
 static void
@@ -1911,7 +1929,7 @@ gtk_css_selector_tree_get_change (const GtkCssSelectorTree *tree,
   GtkCssChange change = 0;
   const GtkCssSelectorTree *prev;
 
-  if (!gtk_css_selector_match (&tree->selector, matcher))
+  if (!gtk_css_selector_match_for_change (&tree->selector, matcher))
     return 0;
 
   if (!tree->selector.class->is_simple)


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