[gtk+/wip/cssnode3: 1/102] stylecontext: Split out GtkCssNode into own file
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssnode3: 1/102] stylecontext: Split out GtkCssNode into own file
- Date: Wed, 11 Mar 2015 00:16:29 +0000 (UTC)
commit 5ac1e7a2dbd7bca683da8bb975a2c3f49aead6c6
Author: Benjamin Otte <otte redhat com>
Date: Sat Jan 10 00:47:32 2015 +0100
stylecontext: Split out GtkCssNode into own file
The functionality of it is supposed to grow, so better put it in a
custom file early.
This is just a naive split so far, the next patches will split things
further.
gtk/Makefile.am | 2 +
gtk/gtkcssnode.c | 69 +++++++++++++++++++++++++++++++++++++
gtk/gtkcssnodeprivate.h | 47 +++++++++++++++++++++++++
gtk/gtkstylecontext.c | 87 +++++++++++++----------------------------------
4 files changed, 142 insertions(+), 63 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 9a82859..32ed9f3 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -397,6 +397,7 @@ gtk_private_h_sources = \
gtkcsskeyframesprivate.h \
gtkcsslookupprivate.h \
gtkcssmatcherprivate.h \
+ gtkcssnodeprivate.h \
gtkcssnodedeclarationprivate.h \
gtkcssnumbervalueprivate.h \
gtkcssparserprivate.h \
@@ -626,6 +627,7 @@ gtk_base_c_sources = \
gtkcsskeyframes.c \
gtkcsslookup.c \
gtkcssmatcher.c \
+ gtkcssnode.c \
gtkcssnodedeclaration.c \
gtkcssnumbervalue.c \
gtkcssparser.c \
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
new file mode 100644
index 0000000..5a3c4fe
--- /dev/null
+++ b/gtk/gtkcssnode.c
@@ -0,0 +1,69 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2014 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkcssnodeprivate.h"
+
+GtkCssNode *
+gtk_css_node_new (void)
+{
+ GtkCssNode *cssnode;
+
+ cssnode = g_slice_new0 (GtkCssNode);
+ cssnode->decl = gtk_css_node_declaration_new ();
+
+ return cssnode;
+}
+
+void
+gtk_css_node_free (GtkCssNode *cssnode)
+{
+ if (cssnode->style)
+ g_object_unref (cssnode->style);
+ gtk_css_node_declaration_unref (cssnode->decl);
+ g_slice_free (GtkCssNode, cssnode);
+}
+
+GtkCssNode *
+gtk_css_node_get_parent (GtkCssNode *cssnode)
+{
+ return cssnode->parent;
+}
+
+void
+gtk_css_node_set_style (GtkCssNode *cssnode,
+ GtkCssStyle *style)
+{
+ if (cssnode->style == style)
+ return;
+
+ if (style)
+ g_object_ref (style);
+
+ if (cssnode->style)
+ g_object_unref (cssnode->style);
+
+ cssnode->style = style;
+}
+
+GtkCssStyle *
+gtk_css_node_get_style (GtkCssNode *cssnode)
+{
+ return cssnode->style;
+}
+
diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h
new file mode 100644
index 0000000..c8f2ff8
--- /dev/null
+++ b/gtk/gtkcssnodeprivate.h
@@ -0,0 +1,47 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2014 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_CSS_NODE_PRIVATE_H__
+#define __GTK_CSS_NODE_PRIVATE_H__
+
+#include "gtkcssnodedeclarationprivate.h"
+#include "gtkcssstyleprivate.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GtkCssNode GtkCssNode;
+
+struct _GtkCssNode
+{
+ GtkCssNodeDeclaration *decl;
+ GtkCssNode *parent;
+ GtkCssStyle *style;
+};
+
+GtkCssNode * gtk_css_node_new (void);
+
+void gtk_css_node_free (GtkCssNode *cssnode);
+
+GtkCssNode * gtk_css_node_get_parent (GtkCssNode *cssnode);
+
+GtkCssStyle * gtk_css_node_get_style (GtkCssNode *cssnode);
+void gtk_css_node_set_style (GtkCssNode *cssnode,
+ GtkCssStyle *style);
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_NODE_PRIVATE_H__ */
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 4810486..ec1ffeb 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -31,6 +31,7 @@
#include "gtkcssimagebuiltinprivate.h"
#include "gtkcssimagevalueprivate.h"
#include "gtkcssnodedeclarationprivate.h"
+#include "gtkcssnodeprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssrgbavalueprivate.h"
#include "gtkcssshadowsvalueprivate.h"
@@ -134,7 +135,6 @@
* things go faster. */
#define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
-typedef struct GtkCssNode GtkCssNode;
typedef struct PropertyValue PropertyValue;
struct PropertyValue
@@ -144,13 +144,6 @@ struct PropertyValue
GValue value;
};
-struct GtkCssNode
-{
- GtkCssNodeDeclaration *decl;
- GtkCssNode *parent;
- GtkCssStyle *values;
-};
-
struct _GtkStyleContextPrivate
{
GdkScreen *screen;
@@ -294,52 +287,19 @@ gtk_style_context_clear_property_cache (GtkStyleContext *context)
g_array_set_size (priv->property_cache, 0);
}
-static GtkCssNode *
-gtk_css_node_new (void)
-{
- GtkCssNode *cssnode;
-
- cssnode = g_slice_new0 (GtkCssNode);
- cssnode->decl = gtk_css_node_declaration_new ();
-
- return cssnode;
-}
-
-static void
-gtk_css_node_set_values (GtkCssNode *cssnode,
- GtkCssStyle *values)
-{
- if (cssnode->values == values)
- return;
-
- if (values)
- g_object_ref (values);
-
- if (cssnode->values)
- g_object_unref (cssnode->values);
-
- cssnode->values = values;
-}
-
-static void
-gtk_css_node_free (GtkCssNode *cssnode)
-{
- if (cssnode->values)
- g_object_unref (cssnode->values);
- gtk_css_node_declaration_unref (cssnode->decl);
- g_slice_free (GtkCssNode, cssnode);
-}
-
static GtkCssStyle *
gtk_css_node_get_parent_style (GtkStyleContext *context,
GtkCssNode *cssnode)
{
GtkStyleContextPrivate *priv;
+ GtkCssNode *parent;
- g_assert (cssnode->parent == NULL || cssnode->parent->values != NULL);
+ parent = gtk_css_node_get_parent (cssnode);
- if (cssnode->parent)
- return cssnode->parent->values;
+ g_assert (parent == NULL || gtk_css_node_get_style (parent) != NULL);
+
+ if (parent)
+ return gtk_css_node_get_style (parent);
priv = context->priv;
@@ -880,8 +840,9 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
cssnode = priv->cssnode;
/* Current data in use is cached, just return it */
- if (cssnode->values)
- return cssnode->values;
+ values = gtk_css_node_get_style (cssnode);
+ if (values)
+ return values;
if (!gtk_style_context_is_saved (context))
{
@@ -892,7 +853,7 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
values = g_hash_table_lookup (priv->style_values, cssnode->decl);
if (values)
{
- gtk_css_node_set_values (cssnode, values);
+ gtk_css_node_set_style (cssnode, values);
return values;
}
@@ -902,7 +863,7 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
g_object_ref (values));
}
- gtk_css_node_set_values (cssnode, values);
+ gtk_css_node_set_style (cssnode, values);
g_object_unref (values);
return values;
@@ -965,7 +926,7 @@ gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
if (gtk_style_context_is_saved (context))
{
- gtk_css_node_set_values (cssnode, NULL);
+ gtk_css_node_set_style (cssnode, NULL);
}
else
{
@@ -2842,7 +2803,7 @@ gtk_style_context_clear_cache (GtkStyleContext *context)
for (l = priv->saved_nodes; l; l = l->next)
{
- gtk_css_node_set_values (l->data, NULL);
+ gtk_css_node_set_style (l->data, NULL);
}
g_hash_table_remove_all (priv->style_values);
@@ -2903,7 +2864,7 @@ gtk_style_context_update_cache (GtkStyleContext *context,
return;
priv = context->priv;
- parent = gtk_style_context_get_root (context)->values;
+ parent = gtk_css_node_get_style (gtk_style_context_get_root (context));
g_hash_table_iter_init (&iter, priv->style_values);
while (g_hash_table_iter_next (&iter, &key, &value))
@@ -3000,7 +2961,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
priv->pending_changes = 0;
gtk_style_context_set_invalid (context, FALSE);
- current = cssnode->values;
+ current = gtk_css_node_get_style (cssnode);
if (current == NULL)
current = gtk_css_static_style_get_default ();
g_object_ref (current);
@@ -3019,7 +2980,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
gtk_style_context_clear_cache (context);
- gtk_css_node_set_values (cssnode, style);
+ gtk_css_node_set_style (cssnode, style);
g_object_unref (static_style);
g_object_unref (style);
@@ -3055,7 +3016,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
parent_changes);
}
- gtk_css_node_set_values (cssnode, new_values);
+ gtk_css_node_set_style (cssnode, new_values);
g_object_unref (new_values);
}
else if (change & GTK_CSS_CHANGE_ANIMATE &&
@@ -3063,17 +3024,17 @@ _gtk_style_context_validate (GtkStyleContext *context,
{
GtkCssStyle *new_values;
- new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (cssnode->values),
- GTK_CSS_ANIMATED_STYLE (cssnode->values)->style,
+ new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (current),
+ GTK_CSS_ANIMATED_STYLE (current)->style,
timestamp);
- gtk_css_node_set_values (cssnode, new_values);
+ gtk_css_node_set_style (cssnode, new_values);
g_object_unref (new_values);
}
}
_gtk_style_context_update_animating (context);
- changes = gtk_css_style_get_difference (cssnode->values, current);
+ changes = gtk_css_style_get_difference (gtk_css_node_get_style (cssnode), current);
g_object_unref (current);
if (!_gtk_bitmask_is_empty (changes))
@@ -3137,14 +3098,14 @@ gtk_style_context_invalidate (GtkStyleContext *context)
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_style_context_clear_cache (context);
- gtk_css_node_set_values (context->priv->cssnode, NULL);
+ gtk_css_node_set_style (context->priv->cssnode, NULL);
root = gtk_style_context_get_root (context);
style = build_properties (context,
root->decl,
TRUE,
gtk_css_node_get_parent_style (context, root));
- gtk_css_node_set_values (root, style);
+ gtk_css_node_set_style (root, style);
g_object_unref (style);
if (!gtk_style_context_is_saved (context))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]