Merge branch 'wip/alice/root' into 'main'

cssselector: Support :root

See merge request GNOME/gtk!7170
This commit is contained in:
Matthias Clasen 2024-04-22 16:26:18 +00:00
commit 48fc8d6606
5 changed files with 60 additions and 0 deletions

View File

@ -74,6 +74,7 @@ in a selector, widget names must be prefixed with a # character.
| E:not(selector) | [CSS Selector Level 3](https://www.w3.org/TR/css3-selectors/#negation) | |
| E:dir(ltr), E:dir(rtl) | [CSS Selector Level 4](https://drafts.csswg.org/selectors/#the-dir-pseudo) | |
| E:drop(active) | [CSS Selector Level 4](https://drafts.csswg.org/selectors/#drag-pseudos) | |
| E:root | [CSS Selector Level 3](https://www.w3.org/TR/selectors-3/#root-pseudo) | |
| E F | [CSS Selector Level 3](https://www.w3.org/TR/css3-selectors/#descendent-combinators) | |
| E > F | [CSS Selector Level 3](https://www.w3.org/TR/css3-selectors/#child-combinators) | |
| E ~ F | [CSS Selector Level 3](https://www.w3.org/TR/css3-selectors/#general-sibling-combinators) | |

View File

@ -892,6 +892,48 @@ DEFINE_SIMPLE_SELECTOR (pseudoclass_position, PSEUDOCLASS_POSITION, print_pseudo
match_pseudoclass_position, hash_pseudoclass_position, comp_pseudoclass_position,
FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_POSITION
/* PSEUDOCLASS FOR ROOT */
static void
print_pseudoclass_root (const GtkCssSelector *selector,
GString *string)
{
g_string_append (string, ":root");
}
static gboolean
match_pseudoclass_root (const GtkCssSelector *selector,
GtkCssNode *node)
{
return gtk_css_node_get_parent (node) == NULL;
}
static guint
hash_pseudoclass_root (const GtkCssSelector *selector)
{
return GPOINTER_TO_UINT (selector->class);
}
static int
comp_pseudoclass_root (const GtkCssSelector *a,
const GtkCssSelector *b)
{
return 0;
}
static GtkCssChange
change_pseudoclass_root (const GtkCssSelector *selector)
{
return 0;
}
#define GTK_CSS_CHANGE_PSEUDOCLASS_ROOT change_pseudoclass_root(selector)
DEFINE_SIMPLE_SELECTOR (pseudoclass_root, PSEUDOCLASS_ROOT, print_pseudoclass_root,
match_pseudoclass_root, hash_pseudoclass_root, comp_pseudoclass_root,
FALSE, TRUE, FALSE, TRUE)
#undef GTK_CSS_CHANGE_PSEUDOCLASS_ROOT
/* API */
static guint
@ -1267,6 +1309,7 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser *parser,
PositionType position_type;
int position_a;
int position_b;
gboolean is_root;
} pseudo_classes[] = {
{ "first-child", 0, POSITION_FORWARD, 0, 1 },
{ "last-child", 0, POSITION_BACKWARD, 0, 1 },
@ -1283,6 +1326,7 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser *parser,
{ "checked", GTK_STATE_FLAG_CHECKED, },
{ "focus-visible", GTK_STATE_FLAG_FOCUS_VISIBLE, },
{ "focus-within", GTK_STATE_FLAG_FOCUS_WITHIN, },
{ "root", 0, 0, 0, 0, TRUE },
};
guint i;
@ -1297,6 +1341,12 @@ gtk_css_selector_parse_selector_pseudo_class (GtkCssParser *parser,
selector);
selector->state.state = pseudo_classes[i].state_flag;
}
else if (pseudo_classes[i].is_root)
{
selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_ROOT
: &GTK_CSS_SELECTOR_PSEUDOCLASS_ROOT,
selector);
}
else
{
selector = gtk_css_selector_new (negate ? &GTK_CSS_SELECTOR_NOT_PSEUDOCLASS_POSITION

View File

@ -141,6 +141,7 @@ testsuite/css/style/font.ui
testsuite/css/style/inherit.ui
testsuite/css/style/label.ui
testsuite/css/style/nth-child.ui
testsuite/css/style/root.ui
testsuite/gtk/filechooser.c
testsuite/gtk/focus-chain/widget-factory2.ui
testsuite/gtk/focus-chain/widget-factory3.ui

View File

@ -49,3 +49,7 @@
:drop(active) {
color: red;
}
:root {
color: red;
}

View File

@ -49,3 +49,7 @@
:drop(active) {
color: rgb(255,0,0);
}
:root {
color: rgb(255,0,0);
}