cssnode: Add gtk_style_context_get_style_provider()
authorBenjamin Otte <otte@redhat.com>
Sat, 31 Jan 2015 15:30:05 +0000 (16:30 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 Mar 2015 14:23:29 +0000 (15:23 +0100)
... and use it when looking up properties.

gtk/gtkcssnode.c
gtk/gtkcssnodeprivate.h
gtk/gtkcsspathnode.c
gtk/gtkcsswidgetnode.c
gtk/gtkstylecontext.c
gtk/gtkstylecontextprivate.h

index 9ff83aa6f7413c6e20baa1988a07c80fc7394325..1f846d93417b31a1ffc5df389b8baae9587fe5ff 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "gtkcsstransientnodeprivate.h"
 #include "gtkdebug.h"
+#include "gtksettingsprivate.h"
 
 G_DEFINE_TYPE (GtkCssNode, gtk_css_node, G_TYPE_OBJECT)
 
@@ -96,6 +97,15 @@ gtk_css_node_real_get_widget_path (GtkCssNode *cssnode)
   return NULL;
 }
 
+static GtkStyleProviderPrivate *
+gtk_css_node_real_get_style_provider (GtkCssNode *cssnode)
+{
+  if (cssnode->parent)
+    return gtk_css_node_get_style_provider (cssnode->parent);
+
+  return GTK_STYLE_PROVIDER_PRIVATE (_gtk_settings_get_style_cascade (gtk_settings_get_default (), 1));
+}
+
 static void
 gtk_css_node_class_init (GtkCssNodeClass *klass)
 {
@@ -109,6 +119,7 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
   klass->set_invalid = gtk_css_node_real_set_invalid;
   klass->create_widget_path = gtk_css_node_real_create_widget_path;
   klass->get_widget_path = gtk_css_node_real_get_widget_path;
+  klass->get_style_provider = gtk_css_node_real_get_style_provider;
 }
 
 static void
@@ -424,3 +435,8 @@ gtk_css_node_get_widget_path (GtkCssNode *cssnode)
   return GTK_CSS_NODE_GET_CLASS (cssnode)->get_widget_path (cssnode);
 }
 
+GtkStyleProviderPrivate *
+gtk_css_node_get_style_provider (GtkCssNode *cssnode)
+{
+  return GTK_CSS_NODE_GET_CLASS (cssnode)->get_style_provider (cssnode);
+}
index 66ac247abb407934c4b511ff0011bf7905e7adf1..9687830caaccb57254037b5785ba488db6bbb6d8 100644 (file)
@@ -56,6 +56,7 @@ struct _GtkCssNodeClass
 
   GtkWidgetPath *       (* create_widget_path)          (GtkCssNode            *cssnode);
   const GtkWidgetPath * (* get_widget_path)             (GtkCssNode            *cssnode);
+  GtkStyleProviderPrivate *(* get_style_provider)       (GtkCssNode            *cssnode);
   void                  (* invalidate)                  (GtkCssNode            *cssnode,
                                                          GtkCssChange           change);
   void                  (* set_invalid)                 (GtkCssNode            *node,
@@ -124,6 +125,7 @@ void                    gtk_css_node_set_invalid        (GtkCssNode            *
                                                          gboolean               invalid);
 GtkWidgetPath *         gtk_css_node_create_widget_path (GtkCssNode            *cssnode);
 const GtkWidgetPath *   gtk_css_node_get_widget_path    (GtkCssNode            *cssnode);
+GtkStyleProviderPrivate *gtk_css_node_get_style_provider(GtkCssNode            *cssnode);
 
 G_END_DECLS
 
index 52c5a4a9c07039eaa64342ea9e760b572355ef77..b3588ea54c5d36268aefc4f9685f4d05746de931 100644 (file)
@@ -77,6 +77,17 @@ gtk_css_path_node_real_get_widget_path (GtkCssNode *node)
   return path_node->path;
 }
 
+static GtkStyleProviderPrivate *
+gtk_css_path_node_get_style_provider (GtkCssNode *node)
+{
+  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
+
+  if (path_node->context == NULL)
+    return GTK_CSS_NODE_CLASS (gtk_css_path_node_parent_class)->get_style_provider (node);
+
+  return gtk_style_context_get_style_provider (path_node->context);
+}
+
 static void
 gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
 {
@@ -86,6 +97,7 @@ gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
   node_class->set_invalid = gtk_css_path_node_set_invalid;
   node_class->create_widget_path = gtk_css_path_node_real_create_widget_path;
   node_class->get_widget_path = gtk_css_path_node_real_get_widget_path;
+  node_class->get_style_provider = gtk_css_path_node_get_style_provider;
 }
 
 static void
index 66e08c11852d41a3a76da08f1c06879cf57b9628..c0ae58a05298ce2d644809f5c4a533ebb46bc19e 100644 (file)
@@ -108,6 +108,17 @@ gtk_css_widget_node_get_widget_path (GtkCssNode *node)
   return gtk_widget_get_path (widget_node->widget);
 }
 
+static GtkStyleProviderPrivate *
+gtk_css_widget_node_get_style_provider (GtkCssNode *node)
+{
+  GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
+
+  if (widget_node->widget == NULL)
+    return GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->get_style_provider (node);
+
+  return gtk_style_context_get_style_provider (gtk_widget_get_style_context (widget_node->widget));
+}
+
 static void
 gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
 {
@@ -118,6 +129,7 @@ gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
   node_class->set_invalid = gtk_css_widget_node_set_invalid;
   node_class->create_widget_path = gtk_css_widget_node_create_widget_path;
   node_class->get_widget_path = gtk_css_widget_node_get_widget_path;
+  node_class->get_style_provider = gtk_css_widget_node_get_style_provider;
 }
 
 static void
index d8b357755c7938680abc30978cdccef791da7732..91f001182b09e4a2267dbfd7a6fb17d988a758ad 100644 (file)
@@ -611,6 +611,12 @@ gtk_style_context_get_root (GtkStyleContext *context)
     return priv->cssnode;
 }
 
+GtkStyleProviderPrivate *
+gtk_style_context_get_style_provider (GtkStyleContext *context)
+{
+  return GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade);
+}
+
 static gboolean
 gtk_style_context_has_custom_cascade (GtkStyleContext *context)
 {
@@ -710,14 +716,12 @@ update_properties (GtkStyleContext             *context,
                    GtkCssStyle                 *style,
                    const GtkBitmask            *parent_changes)
 {
-  GtkStyleContextPrivate *priv;
   const GtkCssNodeDeclaration *decl;
   GtkCssMatcher matcher;
   GtkWidgetPath *path;
   GtkCssStyle *parent;
   GtkCssStyle *result;
 
-  priv = context->priv;
   parent = gtk_css_node_get_parent_style (context, cssnode);
   decl = gtk_css_node_get_declaration (cssnode);
 
@@ -734,7 +738,7 @@ update_properties (GtkStyleContext             *context,
 
   result = gtk_css_static_style_new_update (GTK_CSS_STATIC_STYLE (style),
                                             parent_changes,
-                                            GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+                                            gtk_css_node_get_style_provider (cssnode),
                                             &matcher,
                                             parent);
 
@@ -751,14 +755,12 @@ build_properties (GtkStyleContext             *context,
                   gboolean                     override_state,
                   GtkStateFlags                state)
 {
-  GtkStyleContextPrivate *priv;
   const GtkCssNodeDeclaration *decl;
   GtkCssMatcher matcher;
   GtkWidgetPath *path;
   GtkCssStyle *parent;
   GtkCssStyle *style;
 
-  priv = context->priv;
   decl = gtk_css_node_get_declaration (cssnode);
   parent = gtk_css_node_get_parent_style (context, cssnode);
 
@@ -771,11 +773,11 @@ build_properties (GtkStyleContext             *context,
     gtk_widget_path_iter_set_state (path, -1, state);
 
   if (_gtk_css_matcher_init (&matcher, path))
-    style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+    style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
                                               &matcher,
                                               parent);
   else
-    style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+    style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
                                               NULL,
                                               parent);
 
@@ -2823,7 +2825,7 @@ _gtk_style_context_validate (GtkStyleContext  *context,
       style = gtk_css_animated_style_new (static_style,
                                           priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL,
                                           timestamp,
-                                          GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+                                          gtk_css_node_get_style_provider (cssnode),
                                           gtk_style_context_should_create_transitions (context, current) ? current : NULL);
   
       gtk_style_context_clear_cache (context);
index 8e616a07d4b01c4c0953b954abe70f205ce1a690..cbaefc5e677d657fcd74b50e841eba635a705e1d 100644 (file)
@@ -34,6 +34,8 @@ GtkCssNode *    gtk_style_context_get_root                   (GtkStyleContext *c
 void            gtk_style_context_set_id                     (GtkStyleContext *context,
                                                               const char      *id);
 const char *    gtk_style_context_get_id                     (GtkStyleContext *context);
+GtkStyleProviderPrivate *
+                gtk_style_context_get_style_provider         (GtkStyleContext *context);
 
 const GtkBitmask *
                 _gtk_style_context_get_changes               (GtkStyleContext *context);