summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2014-10-12 23:43:48 +0200
committerBenjamin Otte <otte@redhat.com>2014-10-13 04:47:18 +0200
commit8ab798951e4db962bee18296731dfb390fbba4bf (patch)
treef3a2913ed0be43d925809c62b7b8a4548301bd56
parentbeee00beb4dd88ab168eed0c10717ccf937983c3 (diff)
downloadgtk+-wip/save-is-child.tar.gz
stylecontext: Make save/restore create a child CSS nodewip/save-is-child
This is a change for how CSS is applied. Previously, subelements (I'll take GtkEntry icons as an example) were treated as having the same parent as the regular elements. So a selector such as .entry would match an entry inside a window. But it'd also match the icon image inside the entry. So CSS like .entry { padding: 10px; } would add 10px of padding to both the entry itself and to the icon image inside the entry, so the icon would effective have 20px padding. To get around that, one would have to unset it again like so: .entry { padding: 10px; } .entry.image { padding: unset; } This is getting more and more of a problem as we make subelements respect more properties that aren't inherited by default anyway, like backgrounds and padding/margin/border. This patch has one caveat though: It makes calling gtk_style_context_save() the first time have an important side effect. It's important to audit code to make sure it is only used for subelements. And last but not least, this patch is only useful if code unsets parent's style classes that it doesn't want to apply any longer. Because style classes are inherited by default (and I don't think we want to change that), the example will still apply until the subelements no longer contain the .entry style class.
-rw-r--r--gtk/gtkstylecontext.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 7eb8d44638..97785f326e 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -762,8 +762,21 @@ create_query_path (GtkStyleContext *context,
priv = context->priv;
path = priv->widget ? _gtk_widget_create_path (priv->widget) : gtk_widget_path_copy (priv->widget_path);
length = gtk_widget_path_length (path);
- if (length > 0)
- style_info_add_to_widget_path (info, path, length - 1);
+ if (gtk_style_context_is_saved (context))
+ {
+ GtkStyleInfo *root = g_slist_last (context->priv->saved_nodes)->data;
+
+ if (length > 0)
+ style_info_add_to_widget_path (root, path, length - 1);
+
+ gtk_widget_path_append_type (path, length > 0 ?gtk_widget_path_iter_get_object_type (path, length - 1) : G_TYPE_NONE);
+ style_info_add_to_widget_path (info, path, length);
+ }
+ else
+ {
+ if (length > 0)
+ style_info_add_to_widget_path (info, path, length - 1);
+ }
return path;
}