[gtk+/wip/cssstyle: 25/27] stylecontext: Use correct parent style for lookups
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssstyle: 25/27] stylecontext: Use correct parent style for lookups
- Date: Wed, 24 Dec 2014 02:21:30 +0000 (UTC)
commit 273dd48c624ff7deecfa81c75433f20e3edc2da7
Author: Benjamin Otte <otte redhat com>
Date: Sun Dec 21 21:30:51 2014 +0100
stylecontext: Use correct parent style for lookups
After 3a337156d11a86c7a88f1f30a09276fdf6f63008 style lookups still used
the parent context's style as the parent style, even though after a
gtk_style_context_save() the root style of the style context is the
proper parent.
Testcase attached.
gtk/gtkstylecontext.c | 26 +++++++++++++-------
testsuite/reftests/Makefile.am | 3 ++
.../reftests/style-context-save-inheritance.css | 18 +++++++++++++
.../reftests/style-context-save-inheritance.ref.ui | 19 ++++++++++++++
.../reftests/style-context-save-inheritance.ui | 18 +++++++++++++
5 files changed, 75 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 7e18c5a..94f7c3f 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -640,8 +640,9 @@ gtk_style_context_is_saved (GtkStyleContext *context)
}
static GtkWidgetPath *
-create_query_path (GtkStyleContext *context,
- const GtkCssNodeDeclaration *decl)
+create_query_path (GtkStyleContext *context,
+ const GtkCssNodeDeclaration *decl,
+ GtkCssStyle **out_parent)
{
GtkStyleContextPrivate *priv;
GtkWidgetPath *path;
@@ -659,11 +660,13 @@ create_query_path (GtkStyleContext *context,
gtk_widget_path_append_type (path, length > 0 ? gtk_widget_path_iter_get_object_type (path, length -
1) : G_TYPE_NONE);
gtk_css_node_declaration_add_to_widget_path (decl, path, length);
+ *out_parent = root->values;
}
else
{
if (length > 0)
gtk_css_node_declaration_add_to_widget_path (decl, path, length - 1);
+ *out_parent = priv->parent ? style_values_lookup (priv->parent) : NULL;
}
return path;
@@ -678,11 +681,11 @@ update_properties (GtkStyleContext *context,
GtkStyleContextPrivate *priv;
GtkCssMatcher matcher;
GtkWidgetPath *path;
- GtkCssStyle *result;
+ GtkCssStyle *result, *parent;
priv = context->priv;
- path = create_query_path (context, decl);
+ path = create_query_path (context, decl, &parent);
if (!_gtk_css_matcher_init (&matcher, path))
{
@@ -694,7 +697,7 @@ update_properties (GtkStyleContext *context,
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
&matcher,
priv->scale,
- priv->parent ? style_values_lookup (priv->parent) : NULL);
+ parent);
gtk_widget_path_free (path);
@@ -709,23 +712,23 @@ build_properties (GtkStyleContext *context,
GtkStyleContextPrivate *priv;
GtkCssMatcher matcher;
GtkWidgetPath *path;
- GtkCssStyle *style;
+ GtkCssStyle *style, *parent;
priv = context->priv;
- path = create_query_path (context, decl);
+ path = create_query_path (context, decl, &parent);
if (_gtk_css_matcher_init (&matcher, path))
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
&matcher,
priv->scale,
- priv->parent ? style_values_lookup (priv->parent) : NULL,
+ parent,
out_change);
else
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
NULL,
priv->scale,
- priv->parent ? style_values_lookup (priv->parent) : NULL,
+ parent,
out_change);
gtk_widget_path_free (path);
@@ -1492,6 +1495,11 @@ gtk_style_context_save (GtkStyleContext *context)
priv = context->priv;
+ /* Make sure we have the style existing. It is the
+ * parent of the new saved node after all. */
+ if (!gtk_style_context_is_saved (context))
+ style_values_lookup (context);
+
priv->saved_nodes = g_slist_prepend (priv->saved_nodes, priv->info);
priv->info = style_info_copy (priv->info);
diff --git a/testsuite/reftests/Makefile.am b/testsuite/reftests/Makefile.am
index 7479dae..d88b924 100644
--- a/testsuite/reftests/Makefile.am
+++ b/testsuite/reftests/Makefile.am
@@ -397,6 +397,9 @@ testdata = \
sizegroups-get-preferred-null.ref.ui \
statusbar-remove-all.ref.ui \
statusbar-remove-all.ui \
+ style-context-save-inheritance.css \
+ style-context-save-inheritance.ref.ui \
+ style-context-save-inheritance.ui \
style-properties-nth-child.css \
style-properties-nth-child.ref.ui \
style-properties-nth-child.ui \
diff --git a/testsuite/reftests/style-context-save-inheritance.css
b/testsuite/reftests/style-context-save-inheritance.css
new file mode 100644
index 0000000..3f3630c
--- /dev/null
+++ b/testsuite/reftests/style-context-save-inheritance.css
@@ -0,0 +1,18 @@
+ import "reset-to-defaults.css";
+
+.background {
+ color: red;
+}
+
+GtkLabel {
+ color: green;
+}
+
+GtkLabel:link,
+GtkLabel:visited {
+ color: inherit;
+}
+
+#reference, #reference * {
+ color: green;
+}
diff --git a/testsuite/reftests/style-context-save-inheritance.ref.ui
b/testsuite/reftests/style-context-save-inheritance.ref.ui
new file mode 100644
index 0000000..09b5af5
--- /dev/null
+++ b/testsuite/reftests/style-context-save-inheritance.ref.ui
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <object class="GtkWindow" id="window1">
+ <property name="can_focus">False</property>
+ <property name="type">popup</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="name">reference</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">GREEN
+<a href="http://www.gtk.org">GREEN</a></property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/testsuite/reftests/style-context-save-inheritance.ui
b/testsuite/reftests/style-context-save-inheritance.ui
new file mode 100644
index 0000000..022033b
--- /dev/null
+++ b/testsuite/reftests/style-context-save-inheritance.ui
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <object class="GtkWindow" id="window1">
+ <property name="can_focus">False</property>
+ <property name="type">popup</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">GREEN
+<a href="http://www.gtk.org">GREEN</a></property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]