[gtk/matthiasc/css-change-tracking-4: 6/11] Fix handling of :not in supersets
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/css-change-tracking-4: 6/11] Fix handling of :not in supersets
- Date: Fri, 17 Jan 2020 05:19:18 +0000 (UTC)
commit 93abad1610eff7eac9aa5ee65127501150357a8f
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jan 16 22:29:12 2020 -0500
Fix handling of :not in supersets
The current code for supersets only works in the absence
of :not. If the node is 'label', then both 'label:hover'
and 'label:not(:hover)' need to cause hover to be added
to the change flags.
Fix this by allowing matchers to return TRUE to both a has_foo()
question and its negation, and use this for the ANY and superset
matchers.
gtk/gtkcssmatcher.c | 119 ++++++++++++++++++++++++++-------------------
gtk/gtkcssmatcherprivate.h | 40 +++++++++------
gtk/gtkcssselector.c | 46 +++++++++++-------
3 files changed, 124 insertions(+), 81 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 86e5540a47..34f0df54ca 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -74,7 +74,8 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher *matcher,
static gboolean
gtk_css_matcher_widget_path_has_state (const GtkCssMatcher *matcher,
- GtkStateFlags state)
+ GtkStateFlags state,
+ gboolean match)
{
GtkStateFlags path_state;
@@ -91,12 +92,13 @@ gtk_css_matcher_widget_path_has_state (const GtkCssMatcher *matcher,
path_state = gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
}
- return (path_state & state) == state;
+ return ((path_state & state) == state) == match;
}
static gboolean
gtk_css_matcher_widget_path_has_name (const GtkCssMatcher *matcher,
- /*interned*/ const char *name)
+ /*interned*/ const char *name,
+ gboolean match)
{
const GtkWidgetPath *siblings;
@@ -108,7 +110,7 @@ gtk_css_matcher_widget_path_has_name (const GtkCssMatcher *matcher,
if (path_name == NULL)
path_name = g_type_name (gtk_widget_path_iter_get_object_type (siblings,
matcher->path.sibling_index));
- return path_name == name;
+ return (path_name == name) == match;
}
else
{
@@ -117,52 +119,55 @@ gtk_css_matcher_widget_path_has_name (const GtkCssMatcher *matcher,
if (path_name == NULL)
path_name = g_type_name (gtk_widget_path_iter_get_object_type (matcher->path.path,
matcher->path.index));
- return path_name == name;
+ return (path_name == name) == match;
}
}
static gboolean
gtk_css_matcher_widget_path_has_class (const GtkCssMatcher *matcher,
- GQuark class_name)
+ GQuark class_name,
+ gboolean match)
{
const GtkWidgetPath *siblings;
if (matcher->path.decl &&
gtk_css_node_declaration_has_class (matcher->path.decl, class_name))
- return TRUE;
+ return match;
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path,
matcher->path.index))
- return gtk_widget_path_iter_has_qclass (siblings, matcher->path.sibling_index, class_name);
+ return gtk_widget_path_iter_has_qclass (siblings, matcher->path.sibling_index, class_name) == match;
else
- return gtk_widget_path_iter_has_qclass (matcher->path.path, matcher->path.index, class_name);
+ return gtk_widget_path_iter_has_qclass (matcher->path.path, matcher->path.index, class_name) == match;
}
static gboolean
gtk_css_matcher_widget_path_has_id (const GtkCssMatcher *matcher,
- const char *id)
+ const char *id,
+ gboolean match)
{
const GtkWidgetPath *siblings;
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path,
matcher->path.index))
- return gtk_widget_path_iter_has_name (siblings, matcher->path.sibling_index, id);
+ return gtk_widget_path_iter_has_name (siblings, matcher->path.sibling_index, id) == match;
else
- return gtk_widget_path_iter_has_name (matcher->path.path, matcher->path.index, id);
+ return gtk_widget_path_iter_has_name (matcher->path.path, matcher->path.index, id) == match;
}
static gboolean
gtk_css_matcher_widget_path_has_position (const GtkCssMatcher *matcher,
gboolean forward,
int a,
- int b)
+ int b,
+ gboolean match)
{
const GtkWidgetPath *siblings;
int x;
siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
if (!siblings)
- return FALSE;
+ return !match;
if (forward)
x = matcher->path.sibling_index + 1;
@@ -172,12 +177,12 @@ gtk_css_matcher_widget_path_has_position (const GtkCssMatcher *matcher,
x -= b;
if (a == 0)
- return x == 0;
+ return (x == 0) == match;
if (x % a)
- return FALSE;
+ return !match;
- return x / a >= 0;
+ return (x / a >= 0) == match;;
}
static void
@@ -268,21 +273,24 @@ gtk_css_matcher_node_get_previous (GtkCssMatcher *matcher,
static gboolean
gtk_css_matcher_node_has_state (const GtkCssMatcher *matcher,
- GtkStateFlags state)
+ GtkStateFlags state,
+ gboolean match)
{
- return (matcher->node.node_state & state) == state;
+ return ((matcher->node.node_state & state) == state) == match;
}
static gboolean
gtk_css_matcher_node_has_name (const GtkCssMatcher *matcher,
- /*interned*/ const char *name)
+ /*interned*/ const char *name,
+ gboolean match)
{
- return matcher->node.node_name == name;
+ return (matcher->node.node_name == name) == match;
}
static gboolean
gtk_css_matcher_node_has_class (const GtkCssMatcher *matcher,
- GQuark class_name)
+ GQuark class_name,
+ gboolean match)
{
const GQuark *classes = matcher->node.classes;
@@ -290,42 +298,44 @@ gtk_css_matcher_node_has_class (const GtkCssMatcher *matcher,
{
case 3:
if (classes[2] == class_name)
- return TRUE;
+ return match;
G_GNUC_FALLTHROUGH;
case 2:
if (classes[1] == class_name)
- return TRUE;
+ return match;
G_GNUC_FALLTHROUGH;
case 1:
if (classes[0] == class_name)
- return TRUE;
+ return match;
G_GNUC_FALLTHROUGH;
case 0:
- return FALSE;
+ return !match;
default:
- return gtk_css_node_has_class (matcher->node.node, class_name);
+ return gtk_css_node_has_class (matcher->node.node, class_name) == match;
}
- return FALSE;
+ return !match;
}
static gboolean
gtk_css_matcher_node_has_id (const GtkCssMatcher *matcher,
- const char *id)
+ const char *id,
+ gboolean match)
{
/* assume all callers pass an interned string */
- return matcher->node.node_id == id;
+ return (matcher->node.node_id == id) == match;
}
static gboolean
gtk_css_matcher_node_nth_child (GtkCssNode *node,
GtkCssNode *(* prev_node_func) (GtkCssNode *),
int a,
- int b)
+ int b,
+ gboolean match)
{
int pos, x;
@@ -338,7 +348,7 @@ gtk_css_matcher_node_nth_child (GtkCssNode *node,
node = prev_node_func (node);
}
- return b == 0 && node == NULL;
+ return (b == 0 && node == NULL) == match;
}
/* count nodes */
@@ -350,21 +360,22 @@ gtk_css_matcher_node_nth_child (GtkCssNode *node,
x = pos - b;
if (x % a)
- return FALSE;
+ return !match;
- return x / a >= 0;
+ return (x / a >= 0) == match;
}
static gboolean
gtk_css_matcher_node_has_position (const GtkCssMatcher *matcher,
gboolean forward,
int a,
- int b)
+ int b,
+ gboolean match)
{
return gtk_css_matcher_node_nth_child (matcher->node.node,
forward ? get_previous_visible_sibling
: get_next_visible_sibling,
- a, b);
+ a, b, match);
}
static void
@@ -421,28 +432,32 @@ gtk_css_matcher_any_get_previous (GtkCssMatcher *matcher,
static gboolean
gtk_css_matcher_any_has_state (const GtkCssMatcher *matcher,
- GtkStateFlags state)
+ GtkStateFlags state,
+ gboolean match)
{
return TRUE;
}
static gboolean
gtk_css_matcher_any_has_name (const GtkCssMatcher *matcher,
- /*interned*/ const char *name)
+ /*interned*/ const char *name,
+ gboolean match)
{
return TRUE;
}
static gboolean
gtk_css_matcher_any_has_class (const GtkCssMatcher *matcher,
- GQuark class_name)
+ GQuark class_name,
+ gboolean match)
{
return TRUE;
}
static gboolean
gtk_css_matcher_any_has_id (const GtkCssMatcher *matcher,
- const char *id)
+ const char *id,
+ gboolean match)
{
return TRUE;
}
@@ -451,7 +466,8 @@ static gboolean
gtk_css_matcher_any_has_position (const GtkCssMatcher *matcher,
gboolean forward,
int a,
- int b)
+ int b,
+ gboolean match)
{
return TRUE;
}
@@ -503,37 +519,42 @@ gtk_css_matcher_superset_get_previous (GtkCssMatcher *matcher,
static gboolean
gtk_css_matcher_superset_has_state (const GtkCssMatcher *matcher,
- GtkStateFlags state)
+ GtkStateFlags state,
+ gboolean match)
{
return TRUE;
}
static gboolean
gtk_css_matcher_superset_has_name (const GtkCssMatcher *matcher,
- /*interned*/ const char *name)
+ /*interned*/ const char *name,
+ gboolean match)
{
- return _gtk_css_matcher_has_name (matcher->superset.subset, name);
+ return _gtk_css_matcher_has_name (matcher->superset.subset, name, match);
}
static gboolean
gtk_css_matcher_superset_has_class (const GtkCssMatcher *matcher,
- GQuark class_name)
+ GQuark class_name,
+ gboolean match)
{
- return _gtk_css_matcher_has_class (matcher->superset.subset, class_name);
+ return _gtk_css_matcher_has_class (matcher->superset.subset, class_name, match);
}
static gboolean
gtk_css_matcher_superset_has_id (const GtkCssMatcher *matcher,
- const char *id)
+ const char *id,
+ gboolean match)
{
- return _gtk_css_matcher_has_id (matcher->superset.subset, id);
+ return _gtk_css_matcher_has_id (matcher->superset.subset, id, match);
}
static gboolean
gtk_css_matcher_superset_has_position (const GtkCssMatcher *matcher,
gboolean forward,
int a,
- int b)
+ int b,
+ gboolean match)
{
return TRUE;
}
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 094957bdaa..505900e582 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -44,17 +44,22 @@ struct _GtkCssMatcherClass {
const GtkCssMatcher *next);
gboolean (* has_state) (const GtkCssMatcher *matcher,
- GtkStateFlags state);
+ GtkStateFlags state,
+ gboolean match);
gboolean (* has_name) (const GtkCssMatcher *matcher,
- /*interned*/const char*name);
+ /*interned*/const char*name,
+ gboolean match);
gboolean (* has_class) (const GtkCssMatcher *matcher,
- GQuark class_name);
+ GQuark class_name,
+ gboolean match);
gboolean (* has_id) (const GtkCssMatcher *matcher,
- const char *id);
+ const char *id,
+ gboolean match);
gboolean (* has_position) (const GtkCssMatcher *matcher,
gboolean forward,
int a,
- int b);
+ int b,
+ gboolean match);
void (* print) (const GtkCssMatcher *matcher,
GString *string);
};
@@ -119,39 +124,44 @@ _gtk_css_matcher_get_previous (GtkCssMatcher *matcher,
static inline gboolean
_gtk_css_matcher_has_state (const GtkCssMatcher *matcher,
- GtkStateFlags state)
+ GtkStateFlags state,
+ gboolean match)
{
- return matcher->klass->has_state (matcher, state);
+ return matcher->klass->has_state (matcher, state, match);
}
static inline gboolean
_gtk_css_matcher_has_name (const GtkCssMatcher *matcher,
- /*interned*/ const char *name)
+ /*interned*/ const char *name,
+ gboolean match)
{
- return matcher->klass->has_name (matcher, name);
+ return matcher->klass->has_name (matcher, name, match);
}
static inline gboolean
_gtk_css_matcher_has_class (const GtkCssMatcher *matcher,
- GQuark class_name)
+ GQuark class_name,
+ gboolean match)
{
- return matcher->klass->has_class (matcher, class_name);
+ return matcher->klass->has_class (matcher, class_name, match);
}
static inline gboolean
_gtk_css_matcher_has_id (const GtkCssMatcher *matcher,
- const char *id)
+ const char *id,
+ gboolean match)
{
- return matcher->klass->has_id (matcher, id);
+ return matcher->klass->has_id (matcher, id, match);
}
static inline guint
_gtk_css_matcher_has_position (const GtkCssMatcher *matcher,
gboolean forward,
int a,
- int b)
+ int b,
+ gboolean match)
{
- return matcher->klass->has_position (matcher, forward, a, b);
+ return matcher->klass->has_position (matcher, forward, a, b, match);
}
static inline gboolean
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 8957e49413..852daf4837 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -483,10 +483,16 @@ gtk_css_selector_not_ ## n ## _print (const GtkCssSelector *selector, \
} \
\
static gboolean \
+gtk_css_selector_ ## n ## _match_one (const GtkCssSelector *selector, \
+ const GtkCssMatcher *matcher) \
+{ \
+ return match_func (selector, matcher, TRUE); \
+} \
+static gboolean \
gtk_css_selector_not_ ## n ## _match_one (const GtkCssSelector *selector, \
const GtkCssMatcher *matcher) \
{ \
- return !match_func (selector, matcher); \
+ return match_func (selector, matcher, FALSE); \
} \
\
static GtkCssChange \
@@ -519,7 +525,7 @@ static const GtkCssSelectorClass GTK_CSS_SELECTOR_ ## c = { \
G_STRINGIFY(n), \
gtk_css_selector_ ## n ## _print, \
gtk_css_selector_default_foreach_matcher, \
- match_func, \
+ gtk_css_selector_ ## n ## _match_one, \
gtk_css_selector_ ## n ## _get_change, \
gtk_css_selector_ ## n ## _add_specificity, \
hash_func, \
@@ -550,9 +556,10 @@ print_any (const GtkCssSelector *selector,
static gboolean
match_any (const GtkCssSelector *selector,
- const GtkCssMatcher *matcher)
+ const GtkCssMatcher *matcher,
+ gboolean match)
{
- return TRUE;
+ return match;
}
#undef GTK_CSS_CHANGE_ANY
@@ -573,9 +580,10 @@ print_name (const GtkCssSelector *selector,
static gboolean
match_name (const GtkCssSelector *selector,
- const GtkCssMatcher *matcher)
+ const GtkCssMatcher *matcher,
+ gboolean match)
{
- return _gtk_css_matcher_has_name (matcher, selector->name.name);
+ return _gtk_css_matcher_has_name (matcher, selector->name.name, match);
}
static guint
@@ -606,9 +614,10 @@ print_class (const GtkCssSelector *selector,
static gboolean
match_class (const GtkCssSelector *selector,
- const GtkCssMatcher *matcher)
+ const GtkCssMatcher *matcher,
+ gboolean match)
{
- return _gtk_css_matcher_has_class (matcher, selector->style_class.style_class);
+ return _gtk_css_matcher_has_class (matcher, selector->style_class.style_class, match);
}
static guint
@@ -643,9 +652,10 @@ print_id (const GtkCssSelector *selector,
static gboolean
match_id (const GtkCssSelector *selector,
- const GtkCssMatcher *matcher)
+ const GtkCssMatcher *matcher,
+ gboolean match)
{
- return _gtk_css_matcher_has_id (matcher, selector->id.name);
+ return _gtk_css_matcher_has_id (matcher, selector->id.name, match);
}
static guint
@@ -709,9 +719,10 @@ print_pseudoclass_state (const GtkCssSelector *selector,
static gboolean
match_pseudoclass_state (const GtkCssSelector *selector,
- const GtkCssMatcher *matcher)
+ const GtkCssMatcher *matcher,
+ gboolean match)
{
- return _gtk_css_matcher_has_state (matcher, selector->state.state);
+ return _gtk_css_matcher_has_state (matcher, selector->state.state, match);
}
static guint
@@ -835,21 +846,22 @@ print_pseudoclass_position (const GtkCssSelector *selector,
static gboolean
match_pseudoclass_position (const GtkCssSelector *selector,
- const GtkCssMatcher *matcher)
+ const GtkCssMatcher *matcher,
+ gboolean match)
{
switch (selector->position.type)
{
case POSITION_FORWARD:
- if (!_gtk_css_matcher_has_position (matcher, TRUE, selector->position.a, selector->position.b))
+ if (!_gtk_css_matcher_has_position (matcher, TRUE, selector->position.a, selector->position.b, match))
return FALSE;
break;
case POSITION_BACKWARD:
- if (!_gtk_css_matcher_has_position (matcher, FALSE, selector->position.a, selector->position.b))
+ if (!_gtk_css_matcher_has_position (matcher, FALSE, selector->position.a, selector->position.b, match))
return FALSE;
break;
case POSITION_ONLY:
- if (!_gtk_css_matcher_has_position (matcher, TRUE, 0, 1) ||
- !_gtk_css_matcher_has_position (matcher, FALSE, 0, 1))
+ if (!_gtk_css_matcher_has_position (matcher, TRUE, 0, 1, match) ||
+ !_gtk_css_matcher_has_position (matcher, FALSE, 0, 1, match))
return FALSE;
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]