[gtk+/wip/cssvalue: 5/142] css: Make the style provider take a matcher as an input argument
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 5/142] css: Make the style provider take a matcher as an input argument
- Date: Sat, 7 Apr 2012 19:46:46 +0000 (UTC)
commit 6a538c1a27d1f27a03eb8241a41a121f4ea363e1
Author: Benjamin Otte <otte redhat com>
Date: Sat Mar 17 02:36:11 2012 +0100
css: Make the style provider take a matcher as an input argument
gtk/gtkcssmatcher.c | 7 +++----
gtk/gtkcssmatcherprivate.h | 3 +--
gtk/gtkcssprovider.c | 20 +++++++++++---------
gtk/gtkcssselector.c | 17 +++++++----------
gtk/gtkcssselectorprivate.h | 4 ++--
gtk/gtkmodifierstyle.c | 6 ++----
gtk/gtksettings.c | 6 ++----
gtk/gtkstylecascade.c | 18 ++++--------------
gtk/gtkstylecontext.c | 5 +++--
gtk/gtkstyleproperties.c | 5 ++---
gtk/gtkstyleproviderprivate.c | 7 +++----
gtk/gtkstyleproviderprivate.h | 7 +++----
12 files changed, 43 insertions(+), 62 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 583b803..c12403e 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 61988a2..704de53 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 9cd891f..9320100 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 f526738..d5373d0 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -21,7 +21,6 @@
#include <string.h>
-#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);
-
- _gtk_css_matcher_init (&matcher, path, state);
+ g_return_val_if_fail (matcher != NULL, FALSE);
- 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 c0ff428..e1d7623 100644
--- a/gtk/gtkcssselectorprivate.h
+++ b/gtk/gtkcssselectorprivate.h
@@ -20,6 +20,7 @@
#include <gtk/gtkenums.h>
#include <gtk/gtktypes.h>
+#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 35ad0ea..c16a051 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 f265642..75487b8 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 a0cdfe5..fad9f4a 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 21dfdc4..b5e3a2f 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 e73e74b..5add14d 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 bd943e1..43ae171 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 ac7ac3d..e055502 100644
--- a/gtk/gtkstyleproviderprivate.h
+++ b/gtk/gtkstyleproviderprivate.h
@@ -20,6 +20,7 @@
#include <glib-object.h>
#include "gtk/gtkcsslookupprivate.h"
+#include "gtk/gtkcssmatcherprivate.h"
#include <gtk/gtkenums.h>
#include <gtk/gtksymboliccolor.h>
#include <gtk/gtktypes.h>
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]