LibWeb: Add :not pseudoclass to the CSS parser

The selector given in the :not() is stored in the SimpleSelector as a
String.
This commit is contained in:
Tobias Christiansen 2021-05-23 20:59:26 +02:00 committed by Linus Groh
parent 78f3bad7e6
commit 1ab82afee6
Notes: sideshowbarker 2024-07-18 17:25:50 +09:00
3 changed files with 9 additions and 0 deletions

View file

@ -579,6 +579,9 @@ public:
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Enabled;
} else if (pseudo_name.equals_ignoring_case("checked")) {
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Checked;
} else if (pseudo_name.starts_with("not", CaseSensitivity::CaseInsensitive)) {
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Not;
simple_selector.not_selector = capture_selector_args(pseudo_name);
} else {
dbgln("Unknown pseudo class: '{}'", pseudo_name);
return {};

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/FlyString.h>
#include <AK/String.h>
#include <AK/Vector.h>
namespace Web::CSS {
@ -41,6 +42,7 @@ public:
Disabled,
Enabled,
Checked,
Not,
};
PseudoClass pseudo_class { PseudoClass::None };
@ -75,6 +77,7 @@ public:
// FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere.
// Only used when "pseudo_class" is "NthChild" or "NthLastChild".
NthChildPattern nth_child_pattern;
String not_selector {};
};
struct ComplexSelector {

View file

@ -384,6 +384,9 @@ void dump_selector(StringBuilder& builder, const CSS::Selector& selector)
case CSS::Selector::SimpleSelector::PseudoClass::Checked:
pseudo_class_description = "Checked";
break;
case CSS::Selector::SimpleSelector::PseudoClass::Not:
pseudo_class_description = "Not";
break;
}
builder.appendff("{}:{}", type_description, simple_selector.value);