[gtk+/wip/cssnode3: 19/91] cssnode: Add gtk_style_context_get_style_provider()



commit 6285d6cddf52c99d8d354bcbdbecf774ffd3998b
Author: Benjamin Otte <otte redhat com>
Date:   Sat Jan 31 16:30:05 2015 +0100

    cssnode: Add gtk_style_context_get_style_provider()
    
    ... and use it when looking up properties.

 gtk/gtkcssnode.c             |   16 ++++++++++++++++
 gtk/gtkcssnodeprivate.h      |    2 ++
 gtk/gtkcsspathnode.c         |   12 ++++++++++++
 gtk/gtkcsswidgetnode.c       |   12 ++++++++++++
 gtk/gtkstylecontext.c        |   18 ++++++++++--------
 gtk/gtkstylecontextprivate.h |    2 ++
 6 files changed, 54 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 9ff83aa..1f846d9 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -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);
+}
diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h
index 66ac247..9687830 100644
--- a/gtk/gtkcssnodeprivate.h
+++ b/gtk/gtkcssnodeprivate.h
@@ -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
 
diff --git a/gtk/gtkcsspathnode.c b/gtk/gtkcsspathnode.c
index 52c5a4a..b3588ea 100644
--- a/gtk/gtkcsspathnode.c
+++ b/gtk/gtkcsspathnode.c
@@ -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
diff --git a/gtk/gtkcsswidgetnode.c b/gtk/gtkcsswidgetnode.c
index 66e08c1..c0ae58a 100644
--- a/gtk/gtkcsswidgetnode.c
+++ b/gtk/gtkcsswidgetnode.c
@@ -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
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 7cd9130..bb9c645 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -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);
diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h
index 9eaa9de..c6b57f3 100644
--- a/gtk/gtkstylecontextprivate.h
+++ b/gtk/gtkstylecontextprivate.h
@@ -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);


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