[gtk+/wip/cssnode3: 25/91] cssnode: Automatically recreate style on get_style() call
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssnode3: 25/91] cssnode: Automatically recreate style on get_style() call
- Date: Mon, 9 Mar 2015 14:07:36 +0000 (UTC)
commit ae0a35f843d727af291db846f163c510bf61d832
Author: Benjamin Otte <otte redhat com>
Date: Wed Feb 4 04:43:55 2015 +0100
cssnode: Automatically recreate style on get_style() call
When the style is invalid, redo it.
Make this a vfunc, so the widget nodes can opt out.
gtk/gtkcssnode.c | 31 ++++++++++++++++++++++++++++---
gtk/gtkcssnodeprivate.h | 6 ++++--
gtk/gtkcsspathnode.c | 5 +----
gtk/gtkcsstransientnode.c | 8 --------
gtk/gtkcsswidgetnode.c | 9 +++++++++
gtk/gtkstylecontext.c | 21 ++-------------------
6 files changed, 44 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index b4ea530..b331f26 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -222,9 +222,16 @@ gtk_css_node_create_style (GtkCssNode *cssnode)
return style;
}
+static GtkCssStyle *
+gtk_css_node_real_update_style (GtkCssNode *cssnode,
+ GtkCssChange pending_change,
+ GtkCssStyle *old_style)
+{
+ return gtk_css_node_create_style (cssnode);
+}
+
static void
-gtk_css_node_real_invalidate (GtkCssNode *cssnode,
- GtkCssChange change)
+gtk_css_node_real_invalidate (GtkCssNode *node)
{
}
@@ -276,6 +283,7 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
object_class->dispose = gtk_css_node_dispose;
object_class->finalize = gtk_css_node_finalize;
+ klass->update_style = gtk_css_node_real_update_style;
klass->invalidate = gtk_css_node_real_invalidate;
klass->validate = gtk_css_node_real_validate;
klass->set_invalid = gtk_css_node_real_set_invalid;
@@ -288,6 +296,8 @@ static void
gtk_css_node_init (GtkCssNode *cssnode)
{
cssnode->decl = gtk_css_node_declaration_new ();
+
+ cssnode->style = g_object_ref (gtk_css_static_style_get_default ());
}
void
@@ -402,6 +412,21 @@ gtk_css_node_set_style (GtkCssNode *cssnode,
GtkCssStyle *
gtk_css_node_get_style (GtkCssNode *cssnode)
{
+ GtkCssStyle *new_style;
+
+ if (cssnode->pending_changes)
+ {
+ new_style = GTK_CSS_NODE_GET_CLASS (cssnode)->update_style (cssnode,
+ cssnode->pending_changes,
+ cssnode->style);
+ if (new_style)
+ {
+ gtk_css_node_set_style (cssnode, new_style);
+ g_object_unref (new_style);
+ cssnode->pending_changes = 0;
+ }
+ }
+
return cssnode->style;
}
@@ -533,7 +558,7 @@ gtk_css_node_invalidate (GtkCssNode *cssnode,
{
cssnode->pending_changes |= change;
- GTK_CSS_NODE_GET_CLASS (cssnode)->invalidate (cssnode, change);
+ GTK_CSS_NODE_GET_CLASS (cssnode)->invalidate (cssnode);
gtk_css_node_set_invalid (cssnode, TRUE);
}
diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h
index 7d6cbed..d368a50 100644
--- a/gtk/gtkcssnodeprivate.h
+++ b/gtk/gtkcssnodeprivate.h
@@ -59,8 +59,10 @@ 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);
+ GtkCssStyle * (* update_style) (GtkCssNode *cssnode,
+ GtkCssChange pending_changes,
+ GtkCssStyle *old_style);
+ void (* invalidate) (GtkCssNode *node);
void (* set_invalid) (GtkCssNode *node,
gboolean invalid);
GtkBitmask * (* validate) (GtkCssNode *cssnode,
diff --git a/gtk/gtkcsspathnode.c b/gtk/gtkcsspathnode.c
index b3588ea..aeecc4d 100644
--- a/gtk/gtkcsspathnode.c
+++ b/gtk/gtkcsspathnode.c
@@ -24,13 +24,10 @@
G_DEFINE_TYPE (GtkCssPathNode, gtk_css_path_node, GTK_TYPE_CSS_NODE)
static void
-gtk_css_path_node_invalidate (GtkCssNode *node,
- GtkCssChange change)
+gtk_css_path_node_invalidate (GtkCssNode *node)
{
GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
- gtk_css_node_set_style (node, NULL);
-
if (path_node->context)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
diff --git a/gtk/gtkcsstransientnode.c b/gtk/gtkcsstransientnode.c
index ef553f6..f2602e5 100644
--- a/gtk/gtkcsstransientnode.c
+++ b/gtk/gtkcsstransientnode.c
@@ -23,13 +23,6 @@
G_DEFINE_TYPE (GtkCssTransientNode, gtk_css_transient_node, GTK_TYPE_CSS_NODE)
static void
-gtk_css_transient_node_invalidate (GtkCssNode *node,
- GtkCssChange change)
-{
- gtk_css_node_set_style (node, NULL);
-}
-
-static void
gtk_css_transient_node_set_invalid (GtkCssNode *node,
gboolean invalid)
{
@@ -71,7 +64,6 @@ gtk_css_transient_node_class_init (GtkCssTransientNodeClass *klass)
{
GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass);
- node_class->invalidate = gtk_css_transient_node_invalidate;
node_class->set_invalid = gtk_css_transient_node_set_invalid;
node_class->create_widget_path = gtk_css_transient_node_create_widget_path;
node_class->get_widget_path = gtk_css_transient_node_get_widget_path;
diff --git a/gtk/gtkcsswidgetnode.c b/gtk/gtkcsswidgetnode.c
index 0f7e870..f3a91a7 100644
--- a/gtk/gtkcsswidgetnode.c
+++ b/gtk/gtkcsswidgetnode.c
@@ -31,6 +31,14 @@
G_DEFINE_TYPE (GtkCssWidgetNode, gtk_css_widget_node, GTK_TYPE_CSS_NODE)
+static GtkCssStyle *
+gtk_css_widget_node_update_style (GtkCssNode *cssnode,
+ GtkCssChange pending_change,
+ GtkCssStyle *old_style)
+{
+ return NULL;
+}
+
static void
gtk_css_widget_node_set_invalid (GtkCssNode *node,
gboolean invalid)
@@ -206,6 +214,7 @@ gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
{
GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass);
+ node_class->update_style = gtk_css_widget_node_update_style;
node_class->validate = gtk_css_widget_node_validate;
node_class->set_invalid = gtk_css_widget_node_set_invalid;
node_class->create_widget_path = gtk_css_widget_node_create_widget_path;
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 2314036..968974f 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -608,24 +608,8 @@ gtk_style_context_has_custom_cascade (GtkStyleContext *context)
GtkCssStyle *
gtk_style_context_lookup_style (GtkStyleContext *context)
{
- GtkStyleContextPrivate *priv;
- GtkCssStyle *values;
- GtkCssNode *cssnode;
-
- priv = context->priv;
- cssnode = priv->cssnode;
-
- /* Current data in use is cached, just return it */
- values = gtk_css_node_get_style (cssnode);
- if (values)
- return values;
-
- values = gtk_css_node_create_style (cssnode);
-
- gtk_css_node_set_style (cssnode, values);
- g_object_unref (values);
-
- return values;
+ /* Code will recreate style if it was changed */
+ return gtk_css_node_get_style (context->priv->cssnode);
}
static GtkCssStyle *
@@ -702,7 +686,6 @@ _gtk_style_context_set_widget (GtkStyleContext *context,
g_object_unref (priv->cssnode);
priv->cssnode = gtk_css_widget_node_new (widget);
gtk_css_node_set_state (priv->cssnode, GTK_STATE_FLAG_DIR_LTR);
- gtk_css_node_set_style (priv->cssnode, gtk_css_static_style_get_default ());
}
if (widget)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]