diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c index 583b80301e..c12403ecd8 100644 --- a/gtk/gtkcssmatcher.c +++ b/gtk/gtkcssmatcher.c @@ -62,11 +62,10 @@ _gtk_css_matcher_get_previous (GtkCssMatcher *matcher, return TRUE; } -gboolean -_gtk_css_matcher_has_state (const GtkCssMatcher *matcher, - GtkStateFlags state_flags) +GtkStateFlags +_gtk_css_matcher_get_state (const GtkCssMatcher *matcher) { - return (matcher->state_flags & state_flags) == state_flags; + return matcher->state_flags; } gboolean diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h index 61988a296b..704de5332c 100644 --- a/gtk/gtkcssmatcherprivate.h +++ b/gtk/gtkcssmatcherprivate.h @@ -40,8 +40,7 @@ gboolean _gtk_css_matcher_get_parent (GtkCssMatcher *match gboolean _gtk_css_matcher_get_previous (GtkCssMatcher *matcher, const GtkCssMatcher *next); -gboolean _gtk_css_matcher_has_state (const GtkCssMatcher *matcher, - GtkStateFlags state_flags); +GtkStateFlags _gtk_css_matcher_get_state (const GtkCssMatcher *matcher); gboolean _gtk_css_matcher_has_name (const GtkCssMatcher *matcher, const char *name); gboolean _gtk_css_matcher_has_class (const GtkCssMatcher *matcher, diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index 9cd891fc81..93201007aa 100644 --- a/gtk/gtkcssprovider.c +++ b/gtk/gtkcssprovider.c @@ -1293,11 +1293,10 @@ gtk_css_ruleset_add (GtkCssRuleset *ruleset, } static gboolean -gtk_css_ruleset_matches (GtkCssRuleset *ruleset, - GtkWidgetPath *path, - GtkStateFlags state) +gtk_css_ruleset_matches (GtkCssRuleset *ruleset, + const GtkCssMatcher *matcher) { - return _gtk_css_selector_matches (ruleset->selector, path, state); + return _gtk_css_selector_matches (ruleset->selector, matcher); } static void @@ -1469,6 +1468,7 @@ static GtkStyleProperties * gtk_css_provider_get_style (GtkStyleProvider *provider, GtkWidgetPath *path) { + GtkCssMatcher matcher; GtkCssProvider *css_provider; GtkCssProviderPrivate *priv; GtkStyleProperties *props; @@ -1479,6 +1479,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider, props = gtk_style_properties_new (); css_provider_dump_symbolic_colors (css_provider, props); + _gtk_css_matcher_init (&matcher, path, 0); for (i = 0; i < priv->rulesets->len; i++) { @@ -1489,7 +1490,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider, if (ruleset->styles == NULL) continue; - if (!gtk_css_ruleset_matches (ruleset, path, 0)) + if (!gtk_css_ruleset_matches (ruleset, &matcher)) continue; for (j = 0; j < ruleset->n_styles; j++) @@ -1512,6 +1513,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider, GtkCssProvider *css_provider = GTK_CSS_PROVIDER (provider); GtkCssProviderPrivate *priv = css_provider->priv; WidgetPropertyValue *val; + GtkCssMatcher matcher; gboolean found = FALSE; gchar *prop_name; gint i; @@ -1519,6 +1521,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider, prop_name = g_strdup_printf ("-%s-%s", g_type_name (pspec->owner_type), pspec->name); + _gtk_css_matcher_init (&matcher, path, 0); for (i = priv->rulesets->len - 1; i >= 0; i--) { @@ -1529,7 +1532,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider, if (ruleset->widget_style == NULL) continue; - if (!gtk_css_ruleset_matches (ruleset, path, state)) + if (!gtk_css_ruleset_matches (ruleset, &matcher)) continue; for (val = ruleset->widget_style; val != NULL; val = val->next) @@ -1581,8 +1584,7 @@ gtk_css_style_provider_get_color (GtkStyleProviderPrivate *provider, static void gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup) { GtkCssProvider *css_provider; @@ -1606,7 +1608,7 @@ gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider, ruleset->set_styles)) continue; - if (!gtk_css_ruleset_matches (ruleset, path, state)) + if (!gtk_css_ruleset_matches (ruleset, matcher)) continue; for (j = 0; j < ruleset->n_styles; j++) diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c index 746394918f..4bac4b4f2b 100644 --- a/gtk/gtkcssselector.c +++ b/gtk/gtkcssselector.c @@ -21,7 +21,6 @@ #include -#include "gtkcssmatcherprivate.h" #include "gtkcssprovider.h" #include "gtkstylecontextprivate.h" @@ -370,7 +369,9 @@ static gboolean gtk_css_selector_pseudoclass_state_match (const GtkCssSelector *selector, const GtkCssMatcher *matcher) { - if (!_gtk_css_matcher_has_state (matcher, GPOINTER_TO_UINT (selector->data))) + GtkStateFlags state = GPOINTER_TO_UINT (selector->data); + + if ((_gtk_css_matcher_get_state (matcher) & state) != state) return FALSE; return gtk_css_selector_match (gtk_css_selector_previous (selector), matcher); @@ -829,18 +830,14 @@ _gtk_css_selector_to_string (const GtkCssSelector *selector) * Returns: %TRUE if the selector matches @path **/ gboolean -_gtk_css_selector_matches (const GtkCssSelector *selector, - const GtkWidgetPath *path, - GtkStateFlags state) +_gtk_css_selector_matches (const GtkCssSelector *selector, + const GtkCssMatcher *matcher) { - GtkCssMatcher matcher; g_return_val_if_fail (selector != NULL, FALSE); - g_return_val_if_fail (path != NULL, FALSE); + g_return_val_if_fail (matcher != NULL, FALSE); - _gtk_css_matcher_init (&matcher, path, state); - - return gtk_css_selector_match (selector, &matcher); + return gtk_css_selector_match (selector, matcher); } /* Computes specificity according to CSS 2.1. diff --git a/gtk/gtkcssselectorprivate.h b/gtk/gtkcssselectorprivate.h index c0ff428e0a..e1d7623867 100644 --- a/gtk/gtkcssselectorprivate.h +++ b/gtk/gtkcssselectorprivate.h @@ -20,6 +20,7 @@ #include #include +#include "gtk/gtkcssmatcherprivate.h" #include "gtk/gtkcssparserprivate.h" G_BEGIN_DECLS @@ -36,8 +37,7 @@ void _gtk_css_selector_print (const GtkCssSelector *sel GtkStateFlags _gtk_css_selector_get_state_flags (const GtkCssSelector *selector); gboolean _gtk_css_selector_matches (const GtkCssSelector *selector, - const GtkWidgetPath *path, - GtkStateFlags state); + const GtkCssMatcher *matcher); int _gtk_css_selector_compare (const GtkCssSelector *a, const GtkCssSelector *b); diff --git a/gtk/gtkmodifierstyle.c b/gtk/gtkmodifierstyle.c index 35ad0ea6dd..c16a051c44 100644 --- a/gtk/gtkmodifierstyle.c +++ b/gtk/gtkmodifierstyle.c @@ -144,15 +144,13 @@ gtk_modifier_style_provider_get_color (GtkStyleProviderPrivate *provider, static void gtk_modifier_style_provider_lookup (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup) { GtkModifierStyle *style = GTK_MODIFIER_STYLE (provider); _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (style->priv->style), - path, - state, + matcher, lookup); } diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index f265642bbf..75487b8239 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -1469,8 +1469,7 @@ gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider, static void gtk_settings_style_provider_lookup (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup) { GtkSettings *settings = GTK_SETTINGS (provider); @@ -1478,8 +1477,7 @@ gtk_settings_style_provider_lookup (GtkStyleProviderPrivate *provider, settings_ensure_style (settings); _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style), - path, - state, + matcher, lookup); } diff --git a/gtk/gtkstylecascade.c b/gtk/gtkstylecascade.c index 0c427ce819..f1bf516125 100644 --- a/gtk/gtkstylecascade.c +++ b/gtk/gtkstylecascade.c @@ -173,8 +173,7 @@ gtk_style_cascade_get_color (GtkStyleProviderPrivate *provider, static void gtk_style_cascade_lookup (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup) { GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider); @@ -188,22 +187,13 @@ gtk_style_cascade_lookup (GtkStyleProviderPrivate *provider, if (GTK_IS_STYLE_PROVIDER_PRIVATE (item)) { _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (item), - path, - state, + matcher, lookup); } else { - GtkStyleProperties *provider_style = gtk_style_provider_get_style (item, path); - - if (provider_style) - { - _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (provider_style), - path, - state, - lookup); - g_object_unref (provider_style); - } + /* you lose */ + g_warn_if_reached (); } } } diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 9be3a85a6d..415b186188 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -884,15 +884,16 @@ build_properties (GtkStyleContext *context, GtkStateFlags state) { GtkStyleContextPrivate *priv; + GtkCssMatcher matcher; GtkCssLookup *lookup; priv = context->priv; + _gtk_css_matcher_init (&matcher, path, state); lookup = _gtk_css_lookup_new (); _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade), - path, - state, + &matcher, lookup); style_data->store = _gtk_css_computed_values_new (); diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c index e73e74b6ac..5add14dfc2 100644 --- a/gtk/gtkstyleproperties.c +++ b/gtk/gtkstyleproperties.c @@ -303,8 +303,7 @@ gtk_style_properties_provider_get_color (GtkStyleProviderPrivate *provider, static void gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup) { GtkStyleProperties *props; @@ -330,7 +329,7 @@ gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider, if (!_gtk_css_lookup_is_missing (lookup, id)) continue; - value = property_data_match_state (data, state); + value = property_data_match_state (data, _gtk_css_matcher_get_state (matcher)); if (value == NULL) continue; diff --git a/gtk/gtkstyleproviderprivate.c b/gtk/gtkstyleproviderprivate.c index bd943e1739..43ae1712ff 100644 --- a/gtk/gtkstyleproviderprivate.c +++ b/gtk/gtkstyleproviderprivate.c @@ -45,14 +45,13 @@ _gtk_style_provider_private_get_color (GtkStyleProviderPrivate *provider, void _gtk_style_provider_private_lookup (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup) { GtkStyleProviderPrivateInterface *iface; g_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider)); - g_return_if_fail (path != NULL); + g_return_if_fail (matcher != NULL); g_return_if_fail (lookup != NULL); iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider); @@ -60,5 +59,5 @@ _gtk_style_provider_private_lookup (GtkStyleProviderPrivate *provider, if (!iface->lookup) return; - iface->lookup (provider, path, state, lookup); + iface->lookup (provider, matcher, lookup); } diff --git a/gtk/gtkstyleproviderprivate.h b/gtk/gtkstyleproviderprivate.h index ac7ac3d806..e0555026c6 100644 --- a/gtk/gtkstyleproviderprivate.h +++ b/gtk/gtkstyleproviderprivate.h @@ -20,6 +20,7 @@ #include #include "gtk/gtkcsslookupprivate.h" +#include "gtk/gtkcssmatcherprivate.h" #include #include #include @@ -41,8 +42,7 @@ struct _GtkStyleProviderPrivateInterface GtkSymbolicColor * (* get_color) (GtkStyleProviderPrivate *provider, const char *name); void (* lookup) (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup); }; @@ -51,8 +51,7 @@ GType _gtk_style_provider_private_get_type (void) G_GNUC_C GtkSymbolicColor * _gtk_style_provider_private_get_color (GtkStyleProviderPrivate *provider, const char *name); void _gtk_style_provider_private_lookup (GtkStyleProviderPrivate *provider, - GtkWidgetPath *path, - GtkStateFlags state, + const GtkCssMatcher *matcher, GtkCssLookup *lookup); G_END_DECLS