stylecontext: Use correct parent style for lookups
After 3a337156d1 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.
This commit is contained in:
@ -652,8 +652,9 @@ gtk_style_context_is_saved (GtkStyleContext *context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GtkWidgetPath *
|
static GtkWidgetPath *
|
||||||
create_query_path (GtkStyleContext *context,
|
create_query_path (GtkStyleContext *context,
|
||||||
const GtkCssNodeDeclaration *decl)
|
const GtkCssNodeDeclaration *decl,
|
||||||
|
GtkCssStyle **out_parent)
|
||||||
{
|
{
|
||||||
GtkStyleContextPrivate *priv;
|
GtkStyleContextPrivate *priv;
|
||||||
GtkWidgetPath *path;
|
GtkWidgetPath *path;
|
||||||
@ -671,11 +672,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_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);
|
gtk_css_node_declaration_add_to_widget_path (decl, path, length);
|
||||||
|
*out_parent = root->values;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
gtk_css_node_declaration_add_to_widget_path (decl, path, length - 1);
|
gtk_css_node_declaration_add_to_widget_path (decl, path, length - 1);
|
||||||
|
*out_parent = priv->parent ? style_values_lookup (priv->parent) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
@ -690,11 +693,11 @@ update_properties (GtkStyleContext *context,
|
|||||||
GtkStyleContextPrivate *priv;
|
GtkStyleContextPrivate *priv;
|
||||||
GtkCssMatcher matcher;
|
GtkCssMatcher matcher;
|
||||||
GtkWidgetPath *path;
|
GtkWidgetPath *path;
|
||||||
GtkCssStyle *result;
|
GtkCssStyle *result, *parent;
|
||||||
|
|
||||||
priv = context->priv;
|
priv = context->priv;
|
||||||
|
|
||||||
path = create_query_path (context, decl);
|
path = create_query_path (context, decl, &parent);
|
||||||
|
|
||||||
if (!_gtk_css_matcher_init (&matcher, path))
|
if (!_gtk_css_matcher_init (&matcher, path))
|
||||||
{
|
{
|
||||||
@ -706,7 +709,7 @@ update_properties (GtkStyleContext *context,
|
|||||||
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
|
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
|
||||||
&matcher,
|
&matcher,
|
||||||
priv->scale,
|
priv->scale,
|
||||||
priv->parent ? style_values_lookup (priv->parent) : NULL);
|
parent);
|
||||||
|
|
||||||
gtk_widget_path_free (path);
|
gtk_widget_path_free (path);
|
||||||
|
|
||||||
@ -721,23 +724,23 @@ build_properties (GtkStyleContext *context,
|
|||||||
GtkStyleContextPrivate *priv;
|
GtkStyleContextPrivate *priv;
|
||||||
GtkCssMatcher matcher;
|
GtkCssMatcher matcher;
|
||||||
GtkWidgetPath *path;
|
GtkWidgetPath *path;
|
||||||
GtkCssStyle *style;
|
GtkCssStyle *style, *parent;
|
||||||
|
|
||||||
priv = context->priv;
|
priv = context->priv;
|
||||||
|
|
||||||
path = create_query_path (context, decl);
|
path = create_query_path (context, decl, &parent);
|
||||||
|
|
||||||
if (_gtk_css_matcher_init (&matcher, path))
|
if (_gtk_css_matcher_init (&matcher, path))
|
||||||
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
|
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
|
||||||
&matcher,
|
&matcher,
|
||||||
priv->scale,
|
priv->scale,
|
||||||
priv->parent ? style_values_lookup (priv->parent) : NULL,
|
parent,
|
||||||
out_change);
|
out_change);
|
||||||
else
|
else
|
||||||
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
|
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
|
||||||
NULL,
|
NULL,
|
||||||
priv->scale,
|
priv->scale,
|
||||||
priv->parent ? style_values_lookup (priv->parent) : NULL,
|
parent,
|
||||||
out_change);
|
out_change);
|
||||||
|
|
||||||
gtk_widget_path_free (path);
|
gtk_widget_path_free (path);
|
||||||
@ -1500,6 +1503,11 @@ gtk_style_context_save (GtkStyleContext *context)
|
|||||||
|
|
||||||
priv = context->priv;
|
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->saved_nodes = g_slist_prepend (priv->saved_nodes, priv->info);
|
||||||
|
|
||||||
priv->info = style_info_copy (priv->info);
|
priv->info = style_info_copy (priv->info);
|
||||||
|
|||||||
@ -397,6 +397,9 @@ testdata = \
|
|||||||
sizegroups-get-preferred-null.ref.ui \
|
sizegroups-get-preferred-null.ref.ui \
|
||||||
statusbar-remove-all.ref.ui \
|
statusbar-remove-all.ref.ui \
|
||||||
statusbar-remove-all.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.css \
|
||||||
style-properties-nth-child.ref.ui \
|
style-properties-nth-child.ref.ui \
|
||||||
style-properties-nth-child.ui \
|
style-properties-nth-child.ui \
|
||||||
|
|||||||
18
testsuite/reftests/style-context-save-inheritance.css
Normal file
18
testsuite/reftests/style-context-save-inheritance.css
Normal file
@ -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;
|
||||||
|
}
|
||||||
19
testsuite/reftests/style-context-save-inheritance.ref.ui
Normal file
19
testsuite/reftests/style-context-save-inheritance.ref.ui
Normal file
@ -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>
|
||||||
18
testsuite/reftests/style-context-save-inheritance.ui
Normal file
18
testsuite/reftests/style-context-save-inheritance.ui
Normal file
@ -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>
|
||||||
Reference in New Issue
Block a user