[gtk+/wip/save-is-child: 4/4] stylecontext: Make save/restore create a child CSS node
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/save-is-child: 4/4] stylecontext: Make save/restore create a child CSS node
- Date: Sun, 12 Oct 2014 23:19:38 +0000 (UTC)
commit ca88020f416abbd655f47a05c3421a8b233a953c
Author: Benjamin Otte <otte redhat com>
Date: Sun Oct 12 23:43:48 2014 +0200
stylecontext: Make save/restore create a child CSS node
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.
gtk/gtkstylecontext.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 7eb8d44..97785f3 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]