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.
This commit is contained in:
Benjamin Otte 2011-12-29 14:26:45 +01:00
parent a3225fdd42
commit a6ac53e2a9
3 changed files with 15 additions and 23 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);