cssmatcher: Use widget path's state

Don't take a state when constructing the CSS matcher. Instead, rely on
the newly introduced state in the widget path.

This way, the state can be queried not only on the first element, but on
all elements of the widget path.
This commit is contained in:
Benjamin Otte 2014-07-19 23:26:12 +02:00
parent be09e0ed4a
commit 19eb1614de
4 changed files with 23 additions and 15 deletions

View File

@ -32,7 +32,6 @@ gtk_css_matcher_widget_path_get_parent (GtkCssMatcher *matcher,
matcher->path.klass = child->path.klass;
matcher->path.path = child->path.path;
matcher->path.state_flags = 0;
matcher->path.index = child->path.index - 1;
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index);
@ -48,7 +47,6 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher *matcher,
matcher->path.klass = next->path.klass;
matcher->path.path = next->path.path;
matcher->path.state_flags = 0;
matcher->path.index = next->path.index;
matcher->path.sibling_index = next->path.sibling_index - 1;
@ -58,7 +56,7 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher *matcher,
static GtkStateFlags
gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
{
return matcher->path.state_flags;
return gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
}
static gboolean
@ -192,15 +190,13 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
gboolean
_gtk_css_matcher_init (GtkCssMatcher *matcher,
const GtkWidgetPath *path,
GtkStateFlags state)
const GtkWidgetPath *path)
{
if (gtk_widget_path_length (path) == 0)
return FALSE;
matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
matcher->path.path = path;
matcher->path.state_flags = state;
matcher->path.index = gtk_widget_path_length (path) - 1;
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);

View File

@ -56,7 +56,6 @@ struct _GtkCssMatcherClass {
struct _GtkCssMatcherWidgetPath {
const GtkCssMatcherClass *klass;
const GtkWidgetPath *path;
GtkStateFlags state_flags;
guint index;
guint sibling_index;
};
@ -74,8 +73,7 @@ union _GtkCssMatcher {
};
gboolean _gtk_css_matcher_init (GtkCssMatcher *matcher,
const GtkWidgetPath *path,
GtkStateFlags state) G_GNUC_WARN_UNUSED_RESULT;
const GtkWidgetPath *path) G_GNUC_WARN_UNUSED_RESULT;
void _gtk_css_matcher_any_init (GtkCssMatcher *matcher);
void _gtk_css_matcher_superset_init (GtkCssMatcher *matcher,
const GtkCssMatcher *subset,

View File

@ -40,6 +40,7 @@
#include "gtkstylepropertiesprivate.h"
#include "gtkstylepropertyprivate.h"
#include "gtkstyleproviderprivate.h"
#include "gtkwidgetpath.h"
#include "gtkbindings.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
@ -1668,8 +1669,21 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
gchar *prop_name;
gint i;
if (!_gtk_css_matcher_init (&matcher, path, state))
if (state == gtk_widget_path_iter_get_state (path, -1))
{
gtk_widget_path_ref (path);
}
else
{
path = gtk_widget_path_copy (path);
gtk_widget_path_iter_set_state (path, -1, state);
}
if (!_gtk_css_matcher_init (&matcher, path))
{
gtk_widget_path_unref (path);
return FALSE;
}
tree_rules = _gtk_css_selector_tree_match_all (priv->tree, &matcher);
verify_tree_match_results (css_provider, &matcher, tree_rules);
@ -1712,6 +1726,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
g_free (prop_name);
g_ptr_array_free (tree_rules, TRUE);
gtk_widget_path_unref (path);
return found;
}

View File

@ -748,8 +748,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
}
/* Set widget state */
gtk_widget_path_iter_set_state (path, pos,
gtk_widget_path_iter_get_state (path, pos) | info->state_flags);
gtk_widget_path_iter_set_state (path, pos, info->state_flags);
return path;
}
@ -770,7 +769,7 @@ build_properties (GtkStyleContext *context,
path = create_query_path (context, info);
lookup = _gtk_css_lookup_new (relevant_changes);
if (_gtk_css_matcher_init (&matcher, path, info->state_flags))
if (_gtk_css_matcher_init (&matcher, path))
_gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
&matcher,
lookup);
@ -2957,7 +2956,7 @@ gtk_style_context_needs_full_revalidate (GtkStyleContext *context,
GtkCssMatcher matcher, superset;
path = create_query_path (context, priv->info);
if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
if (_gtk_css_matcher_init (&matcher, path))
{
_gtk_css_matcher_superset_init (&superset, &matcher, GTK_STYLE_CONTEXT_RADICAL_CHANGE & ~GTK_CSS_CHANGE_SOURCE);
priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),