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.
This commit is contained in:
Benjamin Otte 2015-01-10 00:47:32 +01:00
parent 99c4f2dd39
commit be596f3967
4 changed files with 142 additions and 63 deletions

View File

@ -397,6 +397,7 @@ gtk_private_h_sources = \
gtkcsskeyframesprivate.h \ gtkcsskeyframesprivate.h \
gtkcsslookupprivate.h \ gtkcsslookupprivate.h \
gtkcssmatcherprivate.h \ gtkcssmatcherprivate.h \
gtkcssnodeprivate.h \
gtkcssnodedeclarationprivate.h \ gtkcssnodedeclarationprivate.h \
gtkcssnumbervalueprivate.h \ gtkcssnumbervalueprivate.h \
gtkcssparserprivate.h \ gtkcssparserprivate.h \
@ -627,6 +628,7 @@ gtk_base_c_sources = \
gtkcsskeyframes.c \ gtkcsskeyframes.c \
gtkcsslookup.c \ gtkcsslookup.c \
gtkcssmatcher.c \ gtkcssmatcher.c \
gtkcssnode.c \
gtkcssnodedeclaration.c \ gtkcssnodedeclaration.c \
gtkcssnumbervalue.c \ gtkcssnumbervalue.c \
gtkcssparser.c \ gtkcssparser.c \

69
gtk/gtkcssnode.c Normal file
View File

@ -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;
}

47
gtk/gtkcssnodeprivate.h Normal file
View File

@ -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__ */

View File

@ -31,6 +31,7 @@
#include "gtkcssimagebuiltinprivate.h" #include "gtkcssimagebuiltinprivate.h"
#include "gtkcssimagevalueprivate.h" #include "gtkcssimagevalueprivate.h"
#include "gtkcssnodedeclarationprivate.h" #include "gtkcssnodedeclarationprivate.h"
#include "gtkcssnodeprivate.h"
#include "gtkcssnumbervalueprivate.h" #include "gtkcssnumbervalueprivate.h"
#include "gtkcssrgbavalueprivate.h" #include "gtkcssrgbavalueprivate.h"
#include "gtkcssshadowsvalueprivate.h" #include "gtkcssshadowsvalueprivate.h"
@ -134,7 +135,6 @@
* things go faster. */ * things go faster. */
#define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE) #define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
typedef struct GtkCssNode GtkCssNode;
typedef struct PropertyValue PropertyValue; typedef struct PropertyValue PropertyValue;
struct PropertyValue struct PropertyValue
@ -144,13 +144,6 @@ struct PropertyValue
GValue value; GValue value;
}; };
struct GtkCssNode
{
GtkCssNodeDeclaration *decl;
GtkCssNode *parent;
GtkCssStyle *values;
};
struct _GtkStyleContextPrivate struct _GtkStyleContextPrivate
{ {
GdkScreen *screen; GdkScreen *screen;
@ -294,52 +287,19 @@ gtk_style_context_clear_property_cache (GtkStyleContext *context)
g_array_set_size (priv->property_cache, 0); 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 * static GtkCssStyle *
gtk_css_node_get_parent_style (GtkStyleContext *context, gtk_css_node_get_parent_style (GtkStyleContext *context,
GtkCssNode *cssnode) GtkCssNode *cssnode)
{ {
GtkStyleContextPrivate *priv; GtkStyleContextPrivate *priv;
GtkCssNode *parent;
g_assert (cssnode->parent == NULL || cssnode->parent->values != NULL); parent = gtk_css_node_get_parent (cssnode);
if (cssnode->parent) g_assert (parent == NULL || gtk_css_node_get_style (parent) != NULL);
return cssnode->parent->values;
if (parent)
return gtk_css_node_get_style (parent);
priv = context->priv; priv = context->priv;
@ -880,8 +840,9 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
cssnode = priv->cssnode; cssnode = priv->cssnode;
/* Current data in use is cached, just return it */ /* Current data in use is cached, just return it */
if (cssnode->values) values = gtk_css_node_get_style (cssnode);
return cssnode->values; if (values)
return values;
if (!gtk_style_context_is_saved (context)) 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); values = g_hash_table_lookup (priv->style_values, cssnode->decl);
if (values) if (values)
{ {
gtk_css_node_set_values (cssnode, values); gtk_css_node_set_style (cssnode, values);
return values; return values;
} }
@ -902,7 +863,7 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
g_object_ref (values)); g_object_ref (values));
} }
gtk_css_node_set_values (cssnode, values); gtk_css_node_set_style (cssnode, values);
g_object_unref (values); g_object_unref (values);
return values; return values;
@ -965,7 +926,7 @@ gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
if (gtk_style_context_is_saved (context)) if (gtk_style_context_is_saved (context))
{ {
gtk_css_node_set_values (cssnode, NULL); gtk_css_node_set_style (cssnode, NULL);
} }
else else
{ {
@ -2842,7 +2803,7 @@ gtk_style_context_clear_cache (GtkStyleContext *context)
for (l = priv->saved_nodes; l; l = l->next) 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); g_hash_table_remove_all (priv->style_values);
@ -2903,7 +2864,7 @@ gtk_style_context_update_cache (GtkStyleContext *context,
return; return;
priv = context->priv; 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); g_hash_table_iter_init (&iter, priv->style_values);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
@ -3000,7 +2961,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
priv->pending_changes = 0; priv->pending_changes = 0;
gtk_style_context_set_invalid (context, FALSE); gtk_style_context_set_invalid (context, FALSE);
current = cssnode->values; current = gtk_css_node_get_style (cssnode);
if (current == NULL) if (current == NULL)
current = gtk_css_static_style_get_default (); current = gtk_css_static_style_get_default ();
g_object_ref (current); g_object_ref (current);
@ -3019,7 +2980,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
gtk_style_context_clear_cache (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 (static_style);
g_object_unref (style); g_object_unref (style);
@ -3055,7 +3016,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
parent_changes); parent_changes);
} }
gtk_css_node_set_values (cssnode, new_values); gtk_css_node_set_style (cssnode, new_values);
g_object_unref (new_values); g_object_unref (new_values);
} }
else if (change & GTK_CSS_CHANGE_ANIMATE && else if (change & GTK_CSS_CHANGE_ANIMATE &&
@ -3063,17 +3024,17 @@ _gtk_style_context_validate (GtkStyleContext *context,
{ {
GtkCssStyle *new_values; GtkCssStyle *new_values;
new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (cssnode->values), new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (current),
GTK_CSS_ANIMATED_STYLE (cssnode->values)->style, GTK_CSS_ANIMATED_STYLE (current)->style,
timestamp); timestamp);
gtk_css_node_set_values (cssnode, new_values); gtk_css_node_set_style (cssnode, new_values);
g_object_unref (new_values); g_object_unref (new_values);
} }
} }
_gtk_style_context_update_animating (context); _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); g_object_unref (current);
if (!_gtk_bitmask_is_empty (changes)) 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)); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_style_context_clear_cache (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); root = gtk_style_context_get_root (context);
style = build_properties (context, style = build_properties (context,
root->decl, root->decl,
TRUE, TRUE,
gtk_css_node_get_parent_style (context, root)); 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); g_object_unref (style);
if (!gtk_style_context_is_saved (context)) if (!gtk_style_context_is_saved (context))