cssnode: Change style-changed signal

Instead of having old and new style, now have a GtkCssStyleChange opaque
object that will compute the changes you are interested in for you.

This simplifies change signal handlers quite a bit and avoids lots of
repeated computation in every signal handler.
This commit is contained in:
Benjamin Otte
2015-12-12 02:02:04 +01:00
parent 0ad259a178
commit 971a277419
24 changed files with 256 additions and 281 deletions

View File

@ -106,6 +106,11 @@ enum {
NUM_PROPERTIES
};
struct _GtkCssNodeStyleChange {
GtkCssStyle *old_style;
GtkCssStyle *new_style;
};
static guint cssnode_signals[LAST_SIGNAL] = { 0 };
static GParamSpec *cssnode_properties[NUM_PROPERTIES];
@ -577,14 +582,11 @@ gtk_css_node_real_node_added (GtkCssNode *parent,
}
static void
gtk_css_node_real_style_changed (GtkCssNode *cssnode,
GtkCssStyle *old_style,
GtkCssStyle *new_style)
gtk_css_node_real_style_changed (GtkCssNode *cssnode,
GtkCssStyleChange *change)
{
g_object_ref (new_style);
g_object_unref (old_style);
cssnode->style = new_style;
g_object_unref (cssnode->style);
cssnode->style = g_object_ref (gtk_css_style_change_get_new_style (change));
}
static void
@ -638,9 +640,9 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkCssNodeClass, style_changed),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_OBJECT,
G_TYPE_NONE, 2,
GTK_TYPE_CSS_STYLE, GTK_TYPE_CSS_STYLE);
_gtk_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
cssnode_properties[PROP_CLASSES] =
g_param_spec_boxed ("classes", "Classes",
@ -947,10 +949,17 @@ static gboolean
gtk_css_node_set_style (GtkCssNode *cssnode,
GtkCssStyle *style)
{
GtkCssStyleChange change;
if (cssnode->style == style)
return FALSE;
g_signal_emit (cssnode, cssnode_signals[STYLE_CHANGED], 0, cssnode->style, style);
gtk_css_style_change_init (&change, cssnode->style, style);
g_signal_emit (cssnode, cssnode_signals[STYLE_CHANGED], 0, &change);
gtk_css_style_change_finish (&change);
return TRUE;
}