inspector: Track updates of node styles

When the CSS style of a node changes, we want to display the new values
in the inspector.

This for example allows to see how styles update on hover or during
animations.
This commit is contained in:
Benjamin Otte 2015-11-01 16:45:11 +01:00
parent f4c30060be
commit 5c53e873b1

View File

@ -135,6 +135,10 @@ gtk_inspector_css_node_tree_unset_node (GtkInspectorCssNodeTree *cnt)
if (priv->node)
{
g_signal_handlers_disconnect_matched (priv->node,
G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL,
cnt);
g_object_unref (priv->node);
priv->node = NULL;
}
@ -353,25 +357,14 @@ gtk_inspector_css_node_tree_set_object (GtkInspectorCssNodeTree *cnt,
}
static void
gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
GtkCssNode *node)
gtk_inspector_css_node_tree_update_style (GtkCssNode *node,
GtkCssStyle *old_style,
GtkCssStyle *new_style,
GtkInspectorCssNodeTree *cnt)
{
GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
GtkCssStyle *style;
gint i;
if (priv->node == node)
return;
if (node)
g_object_ref (node);
gtk_inspector_css_node_tree_unset_node (cnt);
priv->node = node;
style = gtk_css_node_get_style (node);
for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
{
GtkCssStyleProperty *prop;
@ -386,13 +379,21 @@ gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
iter = (GtkTreeIter *)g_hash_table_lookup (priv->prop_iters, name);
value = _gtk_css_value_to_string (gtk_css_style_get_value (style, i));
if (new_style)
{
value = _gtk_css_value_to_string (gtk_css_style_get_value (new_style, i));
section = gtk_css_style_get_section (style, i);
if (section)
location = _gtk_css_section_to_string (section);
section = gtk_css_style_get_section (new_style, i);
if (section)
location = _gtk_css_section_to_string (section);
else
location = NULL;
}
else
location = NULL;
{
value = NULL;
location = NULL;
}
gtk_list_store_set (priv->prop_model,
iter,
@ -405,6 +406,30 @@ gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
}
}
static void
gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
GtkCssNode *node)
{
GtkInspectorCssNodeTreePrivate *priv = cnt->priv;
if (priv->node == node)
return;
if (node)
g_object_ref (node);
gtk_inspector_css_node_tree_update_style (node,
node ? gtk_css_node_get_style (node) : NULL,
priv->node ? gtk_css_node_get_style (priv->node) : NULL,
cnt);
gtk_inspector_css_node_tree_unset_node (cnt);
priv->node = node;
g_signal_connect (node, "style-changed", G_CALLBACK (gtk_inspector_css_node_tree_update_style), cnt);
}
static void
populate_properties (GtkInspectorCssNodeTree *cnt)
{