css: Make _gtk_css_selector_matches() take a path length

This will be necessary when handling inherit.
This commit is contained in:
Benjamin Otte
2011-05-16 20:20:55 +02:00
parent 08e83ca66b
commit d6f0042773
3 changed files with 21 additions and 6 deletions

View File

@@ -1123,7 +1123,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
info = g_ptr_array_index (priv->selectors_info, i);
if (!_gtk_css_selector_matches (info->selector, path))
if (!_gtk_css_selector_matches (info->selector, path, gtk_widget_path_length (path)))
continue;
g_hash_table_iter_init (&iter, info->style);
@@ -1175,7 +1175,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
info = g_ptr_array_index (priv->selectors_info, i);
if (!_gtk_css_selector_matches (info->selector, path))
if (!_gtk_css_selector_matches (info->selector, path, gtk_widget_path_length (path)))
continue;
selector_state = _gtk_css_selector_get_state_flags (info->selector);

View File

@@ -353,18 +353,32 @@ gtk_css_selector_matches_previous (const GtkCssSelector *selector,
return FALSE;
}
/**
* _gtk_css_selector_matches:
* @selector: the selector
* @path: the path to check
* @length: How many elements of the path are to be used
*
* Checks if the @selector matches the given @path. If @length is
* smaller than the number of elements in @path, it is assumed that
* only the first @length element of @path are valid and the rest
* does not exist. This is useful for doing parent matches for the
* 'inherit' keyword.
*
* Returns: %TRUE if the selector matches @path
**/
gboolean
_gtk_css_selector_matches (const GtkCssSelector *selector,
/* const */ GtkWidgetPath *path)
/* const */ GtkWidgetPath *path,
guint length)
{
GSList *list;
guint length;
gboolean match;
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);
length = gtk_widget_path_length (path);
if (length == 0)
return FALSE;

View File

@@ -48,7 +48,8 @@ void _gtk_css_selector_print (const GtkCssSelector *sel
GtkStateFlags _gtk_css_selector_get_state_flags (GtkCssSelector *selector);
gboolean _gtk_css_selector_matches (const GtkCssSelector *selector,
/* const */ GtkWidgetPath *path);
/* const */ GtkWidgetPath *path,
guint length);
int _gtk_css_selector_compare (const GtkCssSelector *a,
const GtkCssSelector *b);