[gtk+] css: Change prototype of _gtk_css_selector_matches()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] css: Change prototype of _gtk_css_selector_matches()
- Date: Mon, 9 Jan 2012 17:44:22 +0000 (UTC)
commit a6ac53e2a9e121ef670509e1b39892710d774f7a
Author: Benjamin Otte <otte redhat com>
Date: Thu Dec 29 14:26:45 2011 +0100
css: Change prototype of _gtk_css_selector_matches()
Passing the length of the widget path that is relevant is not necessary
anymore, it was only useful for inheritance. Instead, we now pass the
state flags and let the selector do the state matching for us.
gtk/gtkcssprovider.c | 26 +++++++-------------------
gtk/gtkcssselector.c | 10 +++++++---
gtk/gtkcssselectorprivate.h | 2 +-
3 files changed, 15 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index e82299b..4aa4429 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1217,11 +1217,10 @@ gtk_css_ruleset_add (GtkCssRuleset *ruleset,
static gboolean
gtk_css_ruleset_matches (GtkCssRuleset *ruleset,
- GtkWidgetPath *path)
+ GtkWidgetPath *path,
+ GtkStateFlags state)
{
- return _gtk_css_selector_matches (ruleset->selector,
- path,
- gtk_widget_path_length (path));
+ return _gtk_css_selector_matches (ruleset->selector, path, state);
}
static void
@@ -1415,7 +1414,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
if (ruleset->style == NULL)
continue;
- if (!gtk_css_ruleset_matches (ruleset, path))
+ if (!gtk_css_ruleset_matches (ruleset, path, 0))
continue;
g_hash_table_iter_init (&iter, ruleset->style);
@@ -1456,24 +1455,18 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
for (i = priv->rulesets->len - 1; i >= 0; i--)
{
GtkCssRuleset *ruleset;
- GtkStateFlags selector_state;
ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
if (ruleset->widget_style == NULL)
continue;
- if (!gtk_css_ruleset_matches (ruleset, path))
+ if (!gtk_css_ruleset_matches (ruleset, path, state))
continue;
- selector_state = _gtk_css_selector_get_state_flags (ruleset->selector);
val = g_hash_table_lookup (ruleset->widget_style, prop_name);
- if (val &&
- (selector_state == 0 ||
- selector_state == state ||
- ((selector_state & state) != 0 &&
- (selector_state & ~(state)) == 0)))
+ if (val)
{
GtkCssScanner *scanner;
@@ -1534,18 +1527,13 @@ gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider,
GtkCssRuleset *ruleset;
GHashTableIter iter;
gpointer key, val;
- GtkStateFlags selector_state;
ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
if (ruleset->style == NULL)
continue;
- selector_state = _gtk_css_selector_get_state_flags (ruleset->selector);
- if ((selector_state & state) != selector_state)
- continue;
-
- if (!gtk_css_ruleset_matches (ruleset, path))
+ if (!gtk_css_ruleset_matches (ruleset, path, state))
continue;
g_hash_table_iter_init (&iter, ruleset->style);
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index b3ccb44..21f3437 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -390,7 +390,7 @@ gtk_css_selector_matches_previous (const GtkCssSelector *selector,
* _gtk_css_selector_matches:
* @selector: the selector
* @path: the path to check
- * @length: How many elements of the path are to be used
+ * @state: The state to match
*
* Checks if the @selector matches the given @path. If @length is
* smaller than the number of elements in @path, it is assumed that
@@ -403,15 +403,19 @@ gtk_css_selector_matches_previous (const GtkCssSelector *selector,
gboolean
_gtk_css_selector_matches (const GtkCssSelector *selector,
const GtkWidgetPath *path,
- guint length)
+ GtkStateFlags state)
{
GSList *list;
gboolean match;
+ guint length;
g_return_val_if_fail (selector != NULL, FALSE);
g_return_val_if_fail (path != NULL, FALSE);
- g_return_val_if_fail (length <= gtk_widget_path_length (path), FALSE);
+ if ((selector->state & state) != selector->state)
+ return FALSE;
+
+ length = gtk_widget_path_length (path);
if (length == 0)
return FALSE;
diff --git a/gtk/gtkcssselectorprivate.h b/gtk/gtkcssselectorprivate.h
index eca5135..1baaab0 100644
--- a/gtk/gtkcssselectorprivate.h
+++ b/gtk/gtkcssselectorprivate.h
@@ -49,7 +49,7 @@ GtkStateFlags _gtk_css_selector_get_state_flags (GtkCssSelector *sel
gboolean _gtk_css_selector_matches (const GtkCssSelector *selector,
const GtkWidgetPath *path,
- guint length);
+ GtkStateFlags state);
int _gtk_css_selector_compare (const GtkCssSelector *a,
const GtkCssSelector *b);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]