GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit a94b85d3 authored by Benjamin Otte's avatar Benjamin Otte

css: Make the style provider take a matcher as an input argument

parent c0b7c332
......@@ -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
......
......@@ -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,
......
......@@ -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++)
......
......@@ -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.
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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 ();
}
}
}
......
......@@ -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 ();
......
......@@ -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;
......
......@@ -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);
}
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment