[gtk/matthiasc/css-change: 1/3] css: Track disabled state separately



commit 1e69a4cf37275005f9fce18424bfd471ab7a4ab6
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 15 19:19:38 2020 -0500

    css: Track disabled state separately
    
    Significantly reduces the number of nodes that react to
    parent-state changes.
    
    Before (numbers from widget-factory with Adwaita):
    2247 nodes
    class 612
    name 2246
    id 2
    first-child 148
    last-child 156
    state 2247
    hover 2247
    sibling-name 63
    sibling-state 51
    parent-class 586
    parent-name 788
    parent-id 2
    parent-first-child 78
    parent-last-child 78
    parent-state 2226
    parent-hover 5
    
    After:
    2247 nodes
    class 612
    name 2246
    id 2
    first-child 148
    last-child 156
    state 2247
    hover 562
    disabled 859
    sibling-name 63
    sibling-disabled 51
    parent-class 586
    parent-name 788
    parent-id 2
    parent-first-child 78
    parent-last-child 78
    parent-state 236
    parent-hover 5
    parent-disabled 91

 gtk/gtkcssmatcher.c      |  3 ++-
 gtk/gtkcssnode.c         |  2 ++
 gtk/gtkcssselector.c     | 12 ++++++++-
 gtk/gtkcsstypes.c        | 11 ++++++--
 gtk/gtkcsstypesprivate.h | 69 ++++++++++++++++++++++++++----------------------
 5 files changed, 61 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index d9cfc30567..f5d0bfa3ef 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -537,6 +537,7 @@ _gtk_css_matcher_superset_init (GtkCssMatcher       *matcher,
                                   GTK_CSS_CHANGE_ID |
                                   GTK_CSS_CHANGE_POSITION |
                                   GTK_CSS_CHANGE_STATE |
+                                  GTK_CSS_CHANGE_DISABLED |
                                   GTK_CSS_CHANGE_HOVER)) == 0);
 
   switch (subset->klass->type)
@@ -565,7 +566,7 @@ _gtk_css_matcher_superset_init (GtkCssMatcher       *matcher,
     klass->has_id = subset->klass->has_id;
   if (relevant & GTK_CSS_CHANGE_POSITION)
     klass->has_position = subset->klass->has_position;
-  if (relevant & (GTK_CSS_CHANGE_STATE|GTK_CSS_CHANGE_HOVER))
+  if (relevant & (GTK_CSS_CHANGE_STATE|GTK_CSS_CHANGE_HOVER|GTK_CSS_CHANGE_DISABLED))
     klass->get_state = subset->klass->get_state;
 
   matcher->klass = klass;
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index b61b70f822..bace3960eb 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -1154,6 +1154,8 @@ gtk_css_node_set_state (GtkCssNode    *cssnode,
 
       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_PRELIGHT)
         change |= GTK_CSS_CHANGE_STATE;
 
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 3ed6eeac26..8232c4d558 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -736,6 +736,12 @@ DEFINE_SIMPLE_SELECTOR(pseudoclass_hover, PSEUDOCLASS_HOVER, print_pseudoclass_s
                        FALSE, TRUE, FALSE)
 #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)
+#undef GTK_CSS_CHANGE_PSEUDOCLASS_DISABLED
+
 #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,
@@ -1300,7 +1306,11 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser   *parser,
                     selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_HOVER
                                                             : &GTK_CSS_SELECTOR_PSEUDOCLASS_HOVER,
                                                      selector);
-                  else
+                  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 
                     selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_STATE
                                                             : &GTK_CSS_SELECTOR_PSEUDOCLASS_STATE,
                                                      selector);
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index 7f42e1514e..636bdd83bd 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -75,7 +75,8 @@ _gtk_css_change_for_sibling (GtkCssChange match)
                     | GTK_CSS_CHANGE_NTH_CHILD \
                     | GTK_CSS_CHANGE_NTH_LAST_CHILD \
                     | GTK_CSS_CHANGE_STATE \
-                    | GTK_CSS_CHANGE_HOVER)
+                    | GTK_CSS_CHANGE_HOVER \
+                    | GTK_CSS_CHANGE_DISABLED)
 
 #define KEEP_STATES ( ~(BASE_STATES|GTK_CSS_CHANGE_SOURCE|GTK_CSS_CHANGE_PARENT_STYLE) \
                     | GTK_CSS_CHANGE_NTH_CHILD \
@@ -99,6 +100,7 @@ _gtk_css_change_for_child (GtkCssChange match)
                     | GTK_CSS_CHANGE_NTH_LAST_CHILD \
                     | GTK_CSS_CHANGE_STATE \
                     | GTK_CSS_CHANGE_HOVER \
+                    | GTK_CSS_CHANGE_DISABLED \
                     | GTK_CSS_CHANGE_SIBLING_CLASS \
                     | GTK_CSS_CHANGE_SIBLING_NAME \
                     | GTK_CSS_CHANGE_SIBLING_ID \
@@ -107,7 +109,8 @@ _gtk_css_change_for_child (GtkCssChange match)
                     | GTK_CSS_CHANGE_SIBLING_NTH_CHILD \
                     | GTK_CSS_CHANGE_SIBLING_NTH_LAST_CHILD \
                     | GTK_CSS_CHANGE_SIBLING_STATE \
-                    | GTK_CSS_CHANGE_SIBLING_HOVER)
+                    | GTK_CSS_CHANGE_SIBLING_HOVER \
+                    | GTK_CSS_CHANGE_SIBLING_DISABLED)
 
 #define KEEP_STATES (~(BASE_STATES|GTK_CSS_CHANGE_SOURCE|GTK_CSS_CHANGE_PARENT_STYLE))
 
@@ -134,6 +137,7 @@ gtk_css_change_print (GtkCssChange  change,
     { GTK_CSS_CHANGE_NTH_LAST_CHILD, "nth-last-child" },
     { GTK_CSS_CHANGE_STATE, "state" },
     { GTK_CSS_CHANGE_HOVER, "hover" },
+    { GTK_CSS_CHANGE_DISABLED, "disabled" },
 
     { GTK_CSS_CHANGE_SIBLING_CLASS, "sibling-class" },
     { GTK_CSS_CHANGE_SIBLING_NAME, "sibling-name" },
@@ -144,6 +148,7 @@ gtk_css_change_print (GtkCssChange  change,
     { GTK_CSS_CHANGE_SIBLING_NTH_LAST_CHILD, "sibling-nth-last-child" },
     { GTK_CSS_CHANGE_SIBLING_STATE, "sibling-state" },
     { GTK_CSS_CHANGE_SIBLING_HOVER, "sibling-hover" },
+    { GTK_CSS_CHANGE_SIBLING_DISABLED, "sibling-disabled" },
 
     { GTK_CSS_CHANGE_PARENT_CLASS, "parent-class" },
     { GTK_CSS_CHANGE_PARENT_NAME, "parent-name" },
@@ -154,6 +159,7 @@ gtk_css_change_print (GtkCssChange  change,
     { GTK_CSS_CHANGE_PARENT_NTH_LAST_CHILD, "parent-nth-last-child" },
     { GTK_CSS_CHANGE_PARENT_STATE, "parent-state" },
     { GTK_CSS_CHANGE_PARENT_HOVER, "parent-hover" },
+    { GTK_CSS_CHANGE_PARENT_DISABLED, "parent-disabled" },
 
     { GTK_CSS_CHANGE_PARENT_SIBLING_CLASS, "parent-sibling-" },
     { GTK_CSS_CHANGE_PARENT_SIBLING_NAME, "parent-sibling-name" },
@@ -164,6 +170,7 @@ gtk_css_change_print (GtkCssChange  change,
     { GTK_CSS_CHANGE_PARENT_SIBLING_NTH_LAST_CHILD, "parent-sibling-nth-last-child" },
     { GTK_CSS_CHANGE_PARENT_SIBLING_STATE, "parent-sibling-state" },
     { GTK_CSS_CHANGE_PARENT_SIBLING_HOVER, "parent-sibling-hover" },
+    { GTK_CSS_CHANGE_PARENT_SIBLING_DISABLED, "parent-sibling-disabled" },
 
     { GTK_CSS_CHANGE_SOURCE, "source" },
     { GTK_CSS_CHANGE_PARENT_STYLE, "parent-style" },
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index a4f6dd01d1..323b4f77a3 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -37,48 +37,52 @@ typedef struct _GtkCssStyle GtkCssStyle;
 #define GTK_CSS_CHANGE_NTH_LAST_CHILD                 (1ULL <<  6)
 #define GTK_CSS_CHANGE_STATE                          (1ULL <<  7)
 #define GTK_CSS_CHANGE_HOVER                          (1ULL <<  8)
+#define GTK_CSS_CHANGE_DISABLED                       (1ULL <<  9)
 
-#define GTK_CSS_CHANGE_SIBLING_SHIFT 9
+#define GTK_CSS_CHANGE_SIBLING_SHIFT 10 
 
-#define GTK_CSS_CHANGE_SIBLING_CLASS                  (1ULL <<  9)
-#define GTK_CSS_CHANGE_SIBLING_NAME                   (1ULL << 10)
-#define GTK_CSS_CHANGE_SIBLING_ID                     (1ULL << 11)
-#define GTK_CSS_CHANGE_SIBLING_FIRST_CHILD            (1ULL << 12)
-#define GTK_CSS_CHANGE_SIBLING_LAST_CHILD             (1ULL << 13)
-#define GTK_CSS_CHANGE_SIBLING_NTH_CHILD              (1ULL << 14)
-#define GTK_CSS_CHANGE_SIBLING_NTH_LAST_CHILD         (1ULL << 15)
-#define GTK_CSS_CHANGE_SIBLING_STATE                  (1ULL << 16)
-#define GTK_CSS_CHANGE_SIBLING_HOVER                  (1ULL << 17)
+#define GTK_CSS_CHANGE_SIBLING_CLASS                  (1ULL << 10)
+#define GTK_CSS_CHANGE_SIBLING_NAME                   (1ULL << 11)
+#define GTK_CSS_CHANGE_SIBLING_ID                     (1ULL << 12)
+#define GTK_CSS_CHANGE_SIBLING_FIRST_CHILD            (1ULL << 13)
+#define GTK_CSS_CHANGE_SIBLING_LAST_CHILD             (1ULL << 14)
+#define GTK_CSS_CHANGE_SIBLING_NTH_CHILD              (1ULL << 15)
+#define GTK_CSS_CHANGE_SIBLING_NTH_LAST_CHILD         (1ULL << 16)
+#define GTK_CSS_CHANGE_SIBLING_STATE                  (1ULL << 17)
+#define GTK_CSS_CHANGE_SIBLING_HOVER                  (1ULL << 18)
+#define GTK_CSS_CHANGE_SIBLING_DISABLED               (1ULL << 19)
 
 #define GTK_CSS_CHANGE_PARENT_SHIFT (GTK_CSS_CHANGE_SIBLING_SHIFT + GTK_CSS_CHANGE_SIBLING_SHIFT)
 
-#define GTK_CSS_CHANGE_PARENT_CLASS                   (1ULL << 18)
-#define GTK_CSS_CHANGE_PARENT_NAME                    (1ULL << 19)
-#define GTK_CSS_CHANGE_PARENT_ID                      (1ULL << 20)
-#define GTK_CSS_CHANGE_PARENT_FIRST_CHILD             (1ULL << 21)
-#define GTK_CSS_CHANGE_PARENT_LAST_CHILD              (1ULL << 22)
-#define GTK_CSS_CHANGE_PARENT_NTH_CHILD               (1ULL << 23)
-#define GTK_CSS_CHANGE_PARENT_NTH_LAST_CHILD          (1ULL << 24)
-#define GTK_CSS_CHANGE_PARENT_STATE                   (1ULL << 25)
-#define GTK_CSS_CHANGE_PARENT_HOVER                   (1ULL << 26)
+#define GTK_CSS_CHANGE_PARENT_CLASS                   (1ULL << 20)
+#define GTK_CSS_CHANGE_PARENT_NAME                    (1ULL << 21)
+#define GTK_CSS_CHANGE_PARENT_ID                      (1ULL << 22)
+#define GTK_CSS_CHANGE_PARENT_FIRST_CHILD             (1ULL << 23)
+#define GTK_CSS_CHANGE_PARENT_LAST_CHILD              (1ULL << 24)
+#define GTK_CSS_CHANGE_PARENT_NTH_CHILD               (1ULL << 25)
+#define GTK_CSS_CHANGE_PARENT_NTH_LAST_CHILD          (1ULL << 26)
+#define GTK_CSS_CHANGE_PARENT_STATE                   (1ULL << 27)
+#define GTK_CSS_CHANGE_PARENT_HOVER                   (1ULL << 28)
+#define GTK_CSS_CHANGE_PARENT_DISABLED                (1ULL << 29)
 
 #define GTK_CSS_CHANGE_PARENT_SIBLING_SHIFT (GTK_CSS_CHANGE_PARENT_SHIFT + GTK_CSS_CHANGE_SIBLING_SHIFT)
 
-#define GTK_CSS_CHANGE_PARENT_SIBLING_CLASS           (1ULL << 27)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_ID              (1ULL << 28)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_NAME            (1ULL << 29)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_FIRST_CHILD     (1ULL << 30)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_LAST_CHILD      (1ULL << 31)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_NTH_CHILD       (1ULL << 32)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_NTH_LAST_CHILD  (1ULL << 33)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_STATE           (1ULL << 34)
-#define GTK_CSS_CHANGE_PARENT_SIBLING_HOVER           (1ULL << 35)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_CLASS           (1ULL << 30)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_ID              (1ULL << 31)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_NAME            (1ULL << 32)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_FIRST_CHILD     (1ULL << 33)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_LAST_CHILD      (1ULL << 34)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_NTH_CHILD       (1ULL << 35)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_NTH_LAST_CHILD  (1ULL << 36)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_STATE           (1ULL << 37)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_HOVER           (1ULL << 38)
+#define GTK_CSS_CHANGE_PARENT_SIBLING_DISABLED        (1ULL << 39)
 
 /* add more */
-#define GTK_CSS_CHANGE_SOURCE                         (1ULL << 36)
-#define GTK_CSS_CHANGE_PARENT_STYLE                   (1ULL << 37)
-#define GTK_CSS_CHANGE_TIMESTAMP                      (1ULL << 38)
-#define GTK_CSS_CHANGE_ANIMATIONS                     (1ULL << 39)
+#define GTK_CSS_CHANGE_SOURCE                         (1ULL << 40)
+#define GTK_CSS_CHANGE_PARENT_STYLE                   (1ULL << 41)
+#define GTK_CSS_CHANGE_TIMESTAMP                      (1ULL << 42)
+#define GTK_CSS_CHANGE_ANIMATIONS                     (1ULL << 43)
 
 #define GTK_CSS_CHANGE_RESERVED_BIT                   (1ULL << 62) /* Used internally in gtkcssselector.c */
 
@@ -95,6 +99,7 @@ typedef guint64 GtkCssChange;
                                  GTK_CSS_CHANGE_ID       | \
                                  GTK_CSS_CHANGE_POSITION | \
                                  GTK_CSS_CHANGE_STATE    | \
+                                 GTK_CSS_CHANGE_DISABLED | \
                                  GTK_CSS_CHANGE_HOVER)
 #define GTK_CSS_CHANGE_ANY_SIBLING (GTK_CSS_CHANGE_ANY_SELF << GTK_CSS_CHANGE_SIBLING_SHIFT)
 #define GTK_CSS_CHANGE_ANY_PARENT (GTK_CSS_CHANGE_ANY_SELF << GTK_CSS_CHANGE_PARENT_SHIFT)


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