[gtk+/wip/cssnode3: 79/91] csswidgetnode: Avoid creating a stylecontext



commit 74394bcade696e1429950ebe39c144bb2ad8645c
Author: Benjamin Otte <otte redhat com>
Date:   Thu Mar 5 06:23:35 2015 +0100

    csswidgetnode: Avoid creating a stylecontext
    
    If the widget doesn't have a style context, don't create one. Instead,
    call functions on the widget directly.

 gtk/gtkcsswidgetnode.c |   19 +++++++++++++++----
 gtk/gtkwidget.c        |    7 +++++++
 gtk/gtkwidgetprivate.h |    1 +
 3 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcsswidgetnode.c b/gtk/gtkcsswidgetnode.c
index 668f6c2..a23db5f 100644
--- a/gtk/gtkcsswidgetnode.c
+++ b/gtk/gtkcsswidgetnode.c
@@ -22,6 +22,7 @@
 #include "gtkcontainerprivate.h"
 #include "gtkcssanimatedstyleprivate.h"
 #include "gtkprivate.h"
+#include "gtksettingsprivate.h"
 #include "gtkstylecontextprivate.h"
 #include "gtkwidgetprivate.h"
 /* widgets for special casing go here */
@@ -112,9 +113,11 @@ gtk_css_widget_node_validate (GtkCssNode *node)
   if (widget_node->widget == NULL)
     return;
 
-  context = gtk_widget_get_style_context (widget_node->widget);
-
-  gtk_style_context_validate (context, widget_node->accumulated_changes);
+  context = _gtk_widget_peek_style_context (widget_node->widget);
+  if (context)
+    gtk_style_context_validate (context, widget_node->accumulated_changes);
+  else
+    _gtk_widget_style_context_invalidated (widget_node->widget);
   _gtk_bitmask_free (widget_node->accumulated_changes);
   widget_node->accumulated_changes = _gtk_bitmask_new ();
 }
@@ -207,11 +210,19 @@ static GtkStyleProviderPrivate *
 gtk_css_widget_node_get_style_provider (GtkCssNode *node)
 {
   GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
+  GtkStyleContext *context;
+  GtkStyleCascade *cascade;
 
   if (widget_node->widget == NULL)
     return NULL;
 
-  return gtk_style_context_get_style_provider (gtk_widget_get_style_context (widget_node->widget));
+  context = _gtk_widget_peek_style_context (widget_node->widget);
+  if (context)
+    return gtk_style_context_get_style_provider (context);
+
+  cascade = _gtk_settings_get_style_cascade (gtk_widget_get_settings (widget_node->widget),
+                                             gtk_widget_get_scale_factor (widget_node->widget));
+  return GTK_STYLE_PROVIDER_PRIVATE (cascade);
 }
 
 static GdkFrameClock *
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 62b2f59..282dc96 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -16414,6 +16414,13 @@ gtk_widget_get_css_node (GtkWidget *widget)
   return widget->priv->cssnode;
 }
 
+GtkStyleContext *
+_gtk_widget_peek_style_context (GtkWidget *widget)
+{
+  return widget->priv->context;
+}
+
+
 /**
  * gtk_widget_get_style_context:
  * @widget: a #GtkWidget
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index c6adae3..2851ac5 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -131,6 +131,7 @@ gpointer          _gtk_widget_peek_request_cache           (GtkWidget *widget);
 void              _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
                                                             GtkWidget *toplevel,
                                                             gpointer   user_data);
+GtkStyleContext * _gtk_widget_peek_style_context           (GtkWidget *widget);
 GtkStyle *        _gtk_widget_get_style                    (GtkWidget *widget);
 void              _gtk_widget_set_style                    (GtkWidget *widget,
                                                             GtkStyle  *style);


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