diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-13 21:54:26 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-14 17:31:52 +0200 |
commit | 605a225b53197089c09b14cc507ca7c6d816694c (patch) | |
tree | 3e65970191b67ea94b621cb49e51495e088d451d /Libraries/LibHTML | |
parent | e4015ab7cc0320da752f561100701290f07483f8 (diff) | |
download | serenity-605a225b53197089c09b14cc507ca7c6d816694c.zip |
LibHTML: Parse the :link and :hover CSS pseudo-classes
We don't actually do anything with these yet, but now the values will
be there for the selector engine to look at when it feels ready. :^)
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r-- | Libraries/LibHTML/CSS/Selector.h | 7 | ||||
-rw-r--r-- | Libraries/LibHTML/Parser/CSSParser.cpp | 19 |
2 files changed, 22 insertions, 4 deletions
diff --git a/Libraries/LibHTML/CSS/Selector.h b/Libraries/LibHTML/CSS/Selector.h index 16111d6417..c30bad10d6 100644 --- a/Libraries/LibHTML/CSS/Selector.h +++ b/Libraries/LibHTML/CSS/Selector.h @@ -15,6 +15,13 @@ public: }; Type type { Type::Invalid }; + enum class PseudoClass { + None, + Link, + Hover, + }; + PseudoClass pseudo_class { PseudoClass::None }; + enum class Relation { None, ImmediateChild, diff --git a/Libraries/LibHTML/Parser/CSSParser.cpp b/Libraries/LibHTML/Parser/CSSParser.cpp index fc96d6241c..a8afc81e2d 100644 --- a/Libraries/LibHTML/Parser/CSSParser.cpp +++ b/Libraries/LibHTML/Parser/CSSParser.cpp @@ -197,7 +197,7 @@ public: buffer.append(consume_one()); PARSE_ASSERT(!buffer.is_null()); - Selector::Component component { type, relation, String::copy(buffer) }; + Selector::Component component { type, Selector::Component::PseudoClass::None, relation, String::copy(buffer) }; buffer.clear(); if (peek() == '[') { @@ -209,12 +209,23 @@ public: } if (peek() == ':') { - // FIXME: Implement pseudo stuff. + // FIXME: Implement pseudo elements. + [[maybe_unused]] bool is_pseudo_element = false; consume_one(); - if (peek() == ':') + if (peek() == ':') { + is_pseudo_element = true; consume_one(); + } while (is_valid_selector_char(peek())) - consume_one(); + buffer.append(consume_one()); + + auto pseudo_name = String::copy(buffer); + buffer.clear(); + + if (pseudo_name == "link") + component.pseudo_class = Selector::Component::PseudoClass::Link; + else if (pseudo_name == "hover") + component.pseudo_class = Selector::Component::PseudoClass::Hover; } return component; |