[gtk/matthiasc/for-master] css: Redo the pseudoclass selectors



commit 7cea7a365b404f60c23fda06fd8a2c8cb64cffbd
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jan 18 18:19:23 2020 -0500

    css: Redo the pseudoclass selectors
    
    There is no need to duplicate the classes, we can make
    do with a single class for all the states.

 gtk/gtkcssselector.c | 64 +++++++++++++++++++---------------------------------
 1 file changed, 23 insertions(+), 41 deletions(-)
---
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index dc35d839db..00ea559a4a 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -726,31 +726,30 @@ comp_pseudoclass_state (const GtkCssSelector *a,
   return a->state.state - b->state.state;
 }
 
-#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, TRUE)
-#undef GTK_CSS_CHANGE_PSEUDOCLASS_HOVER
+static GtkCssChange
+change_pseudoclass_state (const GtkCsSSelector *selector)
+{
+  GtkStateFlags states = selector->state.state;
+  GtkCssChange change = 0;
 
-#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, TRUE)
-#undef GTK_CSS_CHANGE_PSEUDOCLASS_DISABLED
+  if (states & GTK_STATE_FLAG_PRELIGHT)
+    change |= GTK_CSS_CHANGE_HOVER;
+  if (states & GTK_STATE_FLAG_INSENSITIVE)
+    change |= GTK_CSS_CHANGE_DISABLED;
+  if (states & GTK_STATE_FLAG_BACKDROP)
+    change |= GTK_CSS_CHANGE_BACKDROP;
+  if (states & GTK_STATE_FLAG_SELECTED)
+    change |= GTK_CSS_CHANGE_SELECTED;
+  if (states & ~(GTK_STATE_FLAG_PRELIGHT |
+                 GTK_STATE_FLAG_INSENSITIVE |
+                 GTK_STATE_FLAG_BACKDROP |
+                 GTK_STATE_FLAG_SELECTED))
+  change |= GTK_CSS_CHANGE_STATE;
 
-#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, 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, TRUE)
-#undef GTK_CSS_CHANGE_PSEUDOCLASS_SELECTED
+  return change;
+}
 
-#define GTK_CSS_CHANGE_PSEUDOCLASS_STATE GTK_CSS_CHANGE_STATE
+#define GTK_CSS_CHANGE_PSEUDOCLASS_STATE change_pseudoclass_state (selector)
 DEFINE_SIMPLE_SELECTOR(pseudoclass_state, PSEUDOCLASS_STATE, print_pseudoclass_state,
                        match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
                        FALSE, TRUE, FALSE, TRUE)
@@ -1310,26 +1309,9 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser   *parser,
             {
               if (pseudo_classes[i].state_flag)
                 {
-                  if (pseudo_classes[i].state_flag == GTK_STATE_FLAG_PRELIGHT)
-                    selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_HOVER
-                                                            : &GTK_CSS_SELECTOR_PSEUDOCLASS_HOVER,
-                                                     selector);
-                  else if (pseudo_classes[i].state_flag == GTK_STATE_FLAG_INSENSITIVE)
-                    selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_DISABLED
-                                                            : &GTK_CSS_SELECTOR_PSEUDOCLASS_DISABLED,
-                                                     selector);
-                  else if (pseudo_classes[i].state_flag == GTK_STATE_FLAG_BACKDROP)
-                    selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_BACKDROP
-                                                            : &GTK_CSS_SELECTOR_PSEUDOCLASS_BACKDROP,
-                                                     selector);
-                  else if (pseudo_classes[i].state_flag == GTK_STATE_FLAG_SELECTED)
-                    selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_SELECTED
-                                                            : &GTK_CSS_SELECTOR_PSEUDOCLASS_SELECTED,
-                                                     selector);
-                  else 
-                    selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_STATE
+                  selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_STATE
                                                             : &GTK_CSS_SELECTOR_PSEUDOCLASS_STATE,
-                                                     selector);
+                                                   selector);
                   selector->state.state = pseudo_classes[i].state_flag;
                 }
               else


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