[gtk/redo-superset] wip: Redo change computation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/redo-superset] wip: Redo change computation
- Date: Fri, 17 Jan 2020 14:31:28 +0000 (UTC)
commit cc2485349025e1973d0e845143c8a1674356672a
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jan 17 09:29:59 2020 -0500
wip: Redo change computation
Replace the superset matcher with a differnt selector
api. This doesn't work yet.
gtk/gtkcssprovider.c | 21 +++----------
gtk/gtkcssselector.c | 75 ++++++++++++++++++++++++++++++++++++---------
gtk/gtkcssselectorprivate.h | 2 ++
3 files changed, 68 insertions(+), 30 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 76be1f5eb0..0e6668609a 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -436,26 +436,15 @@ compute_change (GtkCssProvider *provider,
{
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
GtkCssChange change = 0;
- GPtrArray *tree_rules;
int i;
- GtkCssMatcher change_matcher;
-
- _gtk_css_matcher_superset_init (&change_matcher, matcher);
- tree_rules = _gtk_css_selector_tree_match_all (priv->tree, &change_matcher);
- if (tree_rules)
+ for (i = 0; i < priv->rulesets->len; i++)
{
- for (i = tree_rules->len - 1; i >= 0; i--)
- {
- GtkCssRuleset *ruleset;
+ GtkCssRuleset *ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
- ruleset = tree_rules->pdata[i];
-
- change |= _gtk_css_selector_get_change (ruleset->selector);
- }
-
- g_ptr_array_free (tree_rules, TRUE);
- }
+ if (_gtk_css_selector_matches_for_change (ruleset->selector, matcher))
+ change |= _gtk_css_selector_get_change (ruleset->selector);
+ }
return change;
}
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 8957e49413..d2ba1805d2 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -62,7 +62,8 @@ struct _GtkCssSelectorClass {
int (* compare_one) (const GtkCssSelector *a,
const GtkCssSelector *b);
- guint is_simple :1;
+ guint is_simple : 1;
+ guint ignore_for_change : 1;
};
typedef enum {
@@ -177,6 +178,16 @@ gtk_css_selector_match (const GtkCssSelector *selector,
return selector->class->match_one (selector, matcher);
}
+static gboolean
+gtk_css_selector_match_for_change (const GtkCssSelector *selector,
+ const GtkCssMatcher *matcher)
+{
+ if (selector->class->ignore_for_change)
+ return TRUE;
+
+ return selector->class->match_one (selector, matcher);
+}
+
static gboolean
gtk_css_selector_foreach (const GtkCssSelector *selector,
const GtkCssMatcher *matcher,
@@ -319,6 +330,7 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_DESCENDANT = {
gtk_css_selector_default_add_specificity,
gtk_css_selector_default_hash_one,
gtk_css_selector_default_compare_one,
+ FALSE,
FALSE
};
@@ -360,6 +372,7 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_CHILD = {
gtk_css_selector_default_add_specificity,
gtk_css_selector_default_hash_one,
gtk_css_selector_default_compare_one,
+ FALSE,
FALSE
};
@@ -411,6 +424,7 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_SIBLING = {
gtk_css_selector_default_add_specificity,
gtk_css_selector_default_hash_one,
gtk_css_selector_default_compare_one,
+ FALSE,
FALSE
};
@@ -452,7 +466,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_ADJACENT = {
gtk_css_selector_default_add_specificity,
gtk_css_selector_default_hash_one,
gtk_css_selector_default_compare_one,
- FALSE
+ FALSE,
+ FALSE,
};
/* SIMPLE SELECTOR DEFINE */
@@ -465,7 +480,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_ADJACENT = {
comp_func, \
increase_id_specificity, \
increase_class_specificity, \
- increase_element_specificity) \
+ increase_element_specificity, \
+ ignore_for_change) \
static void \
gtk_css_selector_ ## n ## _print (const GtkCssSelector *selector, \
GString *string) \
@@ -536,7 +552,8 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_NOT_ ## c = { \
gtk_css_selector_ ## n ## _add_specificity, \
hash_func, \
comp_func, \
- TRUE \
+ TRUE, \
+ ignore_for_change \
};
/* ANY */
@@ -559,7 +576,7 @@ match_any (const GtkCssSelector *selector,
#define GTK_CSS_CHANGE_ANY 0
DEFINE_SIMPLE_SELECTOR(any, ANY, print_any, match_any,
gtk_css_selector_default_hash_one, gtk_css_selector_default_compare_one,
- FALSE, FALSE, FALSE)
+ FALSE, FALSE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_ANY
/* NAME */
@@ -592,7 +609,7 @@ comp_name (const GtkCssSelector *a,
b->name.name);
}
-DEFINE_SIMPLE_SELECTOR(name, NAME, print_name, match_name, hash_name, comp_name, FALSE, FALSE, TRUE)
+DEFINE_SIMPLE_SELECTOR(name, NAME, print_name, match_name, hash_name, comp_name, FALSE, FALSE, TRUE, FALSE)
/* CLASS */
@@ -629,7 +646,7 @@ comp_class (const GtkCssSelector *a,
return 0;
}
-DEFINE_SIMPLE_SELECTOR(class, CLASS, print_class, match_class, hash_class, comp_class, FALSE, TRUE, FALSE)
+DEFINE_SIMPLE_SELECTOR(class, CLASS, print_class, match_class, hash_class, comp_class, FALSE, TRUE, FALSE,
FALSE)
/* ID */
@@ -666,7 +683,7 @@ comp_id (const GtkCssSelector *a,
return 0;
}
-DEFINE_SIMPLE_SELECTOR(id, ID, print_id, match_id, hash_id, comp_id, TRUE, FALSE, FALSE)
+DEFINE_SIMPLE_SELECTOR(id, ID, print_id, match_id, hash_id, comp_id, TRUE, FALSE, FALSE, FALSE)
const gchar *
gtk_css_pseudoclass_name (GtkStateFlags state)
@@ -731,31 +748,31 @@ comp_pseudoclass_state (const GtkCssSelector *a,
#define GTK_CSS_CHANGE_PSEUDOCLASS_HOVER GTK_CSS_CHANGE_HOVER
DEFINE_SIMPLE_SELECTOR(pseudoclass_hover, PSEUDOCLASS_HOVER, print_pseudoclass_state,
match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
- FALSE, TRUE, FALSE)
+ FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_HOVER
#define GTK_CSS_CHANGE_PSEUDOCLASS_DISABLED GTK_CSS_CHANGE_DISABLED
DEFINE_SIMPLE_SELECTOR(pseudoclass_disabled, PSEUDOCLASS_DISABLED, print_pseudoclass_state,
match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
- FALSE, TRUE, FALSE)
+ FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_DISABLED
#define GTK_CSS_CHANGE_PSEUDOCLASS_BACKDROP GTK_CSS_CHANGE_BACKDROP
DEFINE_SIMPLE_SELECTOR(pseudoclass_backdrop, PSEUDOCLASS_BACKDROP, print_pseudoclass_state,
match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
- FALSE, TRUE, FALSE)
+ FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_BACKDROP
#define GTK_CSS_CHANGE_PSEUDOCLASS_SELECTED GTK_CSS_CHANGE_SELECTED
DEFINE_SIMPLE_SELECTOR(pseudoclass_selected, PSEUDOCLASS_SELECTED, print_pseudoclass_state,
match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
- FALSE, TRUE, FALSE)
+ FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_SELECTED
#define GTK_CSS_CHANGE_PSEUDOCLASS_STATE GTK_CSS_CHANGE_STATE
DEFINE_SIMPLE_SELECTOR(pseudoclass_state, PSEUDOCLASS_STATE, print_pseudoclass_state,
match_pseudoclass_state, hash_pseudoclass_state, comp_pseudoclass_state,
- FALSE, TRUE, FALSE)
+ FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_STATE
/* PSEUDOCLASS FOR POSITION */
@@ -909,7 +926,7 @@ change_pseudoclass_position (const GtkCssSelector *selector)
#define GTK_CSS_CHANGE_PSEUDOCLASS_POSITION change_pseudoclass_position(selector)
DEFINE_SIMPLE_SELECTOR(pseudoclass_position, PSEUDOCLASS_POSITION, print_pseudoclass_position,
match_pseudoclass_position, hash_pseudoclass_position, comp_pseudoclass_position,
- FALSE, TRUE, FALSE)
+ FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_POSITION
/* API */
@@ -1728,6 +1745,36 @@ _gtk_css_selector_matches (const GtkCssSelector *selector,
return gtk_css_selector_foreach (selector, matcher, gtk_css_selector_foreach_match, NULL);
}
+static gboolean
+gtk_css_selector_foreach_match_for_change (const GtkCssSelector *selector,
+ const GtkCssMatcher *matcher,
+ gpointer unused)
+{
+ selector = gtk_css_selector_previous (selector);
+
+ if (selector == NULL)
+ return TRUE;
+
+ if (!gtk_css_selector_match_for_change (selector, matcher))
+ return FALSE;
+
+ return gtk_css_selector_foreach (selector, matcher, gtk_css_selector_foreach_match_for_change, NULL);
+}
+
+gboolean
+_gtk_css_selector_matches_for_change (const GtkCssSelector *selector,
+ const GtkCssMatcher *matcher)
+{
+
+ g_return_val_if_fail (selector != NULL, FALSE);
+ g_return_val_if_fail (matcher != NULL, FALSE);
+
+ if (!gtk_css_selector_match_for_change (selector, matcher))
+ return FALSE;
+
+ return gtk_css_selector_foreach (selector, matcher, gtk_css_selector_foreach_match_for_change, NULL);
+}
+
/* Computes specificity according to CSS 2.1.
* The arguments must be initialized to 0 */
static void
diff --git a/gtk/gtkcssselectorprivate.h b/gtk/gtkcssselectorprivate.h
index 7b7ba1073c..407b56b730 100644
--- a/gtk/gtkcssselectorprivate.h
+++ b/gtk/gtkcssselectorprivate.h
@@ -36,6 +36,8 @@ void _gtk_css_selector_print (const GtkCssSelector *sel
gboolean _gtk_css_selector_matches (const GtkCssSelector *selector,
const GtkCssMatcher *matcher);
+gboolean _gtk_css_selector_matches_for_change (const GtkCssSelector *selector,
+ const GtkCssMatcher *matcher);
GtkCssChange _gtk_css_selector_get_change (const GtkCssSelector *selector);
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]