diff options
author | Tobias Christiansen <tobi@tobyase.de> | 2021-05-23 22:36:36 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-05-24 02:14:11 +0430 |
commit | b53dac6e887d8afd7d829bf070125f5bea0521cc (patch) | |
tree | 71d02fd4f853b53f785de85cf8ec5b1665818531 /Userland/Libraries/LibWeb/CSS | |
parent | 4f4cde237983cfe9d9d2ebc186cb283b7262ed4a (diff) | |
download | serenity-b53dac6e887d8afd7d829bf070125f5bea0521cc.zip |
LibWeb: Add support for more pseudoclasses
:disabled, :enabled and :checked are now parsed and matched. There
surely are more nuances to consider.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Selector.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp | 18 |
3 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp index 9706850d6e..c0c57a79eb 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp @@ -573,6 +573,12 @@ public: simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::Before; } else if (pseudo_name.equals_ignoring_case("after")) { simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::After; + } else if (pseudo_name.equals_ignoring_case("disabled")) { + simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Disabled; + } else if (pseudo_name.equals_ignoring_case("enabled")) { + 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 { dbgln("Unknown pseudo class: '{}'", pseudo_name); return {}; diff --git a/Userland/Libraries/LibWeb/CSS/Selector.h b/Userland/Libraries/LibWeb/CSS/Selector.h index 7a132fde25..9e7036a98a 100644 --- a/Userland/Libraries/LibWeb/CSS/Selector.h +++ b/Userland/Libraries/LibWeb/CSS/Selector.h @@ -38,6 +38,9 @@ public: LastOfType, NthChild, NthLastChild, + Disabled, + Enabled, + Checked, }; PseudoClass pseudo_class { PseudoClass::None }; diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index 6807f40eae..44b7a48dba 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -82,6 +82,24 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E return false; } break; + case CSS::Selector::SimpleSelector::PseudoClass::Disabled: + if (!element.tag_name().equals_ignoring_case(HTML::TagNames::input)) + return false; + if (!element.has_attribute("disabled")) + return false; + break; + case CSS::Selector::SimpleSelector::PseudoClass::Enabled: + if (!element.tag_name().equals_ignoring_case(HTML::TagNames::input)) + return false; + if (element.has_attribute("disabled")) + return false; + break; + case CSS::Selector::SimpleSelector::PseudoClass::Checked: + if (!element.tag_name().equals_ignoring_case(HTML::TagNames::input)) + return false; + if (!element.has_attribute("checked")) + return false; + break; case CSS::Selector::SimpleSelector::PseudoClass::NthChild: case CSS::Selector::SimpleSelector::PseudoClass::NthLastChild: const auto step_size = component.nth_child_pattern.step_size; |