summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Selector.cpp23
-rw-r--r--Userland/Libraries/LibWeb/CSS/Selector.h3
2 files changed, 12 insertions, 14 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Selector.cpp b/Userland/Libraries/LibWeb/CSS/Selector.cpp
index a81edfe313..14bac1c4e3 100644
--- a/Userland/Libraries/LibWeb/CSS/Selector.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Selector.cpp
@@ -13,25 +13,22 @@ namespace Web::CSS {
Selector::Selector(Vector<CompoundSelector>&& compound_selectors)
: m_compound_selectors(move(compound_selectors))
{
+ // Note: This assumes that only one pseudo-element is allowed in a selector, and that it appears at the end.
+ // This is true currently, and there are no current proposals to change this, but you never know!
+ if (!m_compound_selectors.is_empty()) {
+ for (auto const& simple_selector : m_compound_selectors.last().simple_selectors) {
+ if (simple_selector.type == SimpleSelector::Type::PseudoElement) {
+ m_pseudo_element = simple_selector.pseudo_element;
+ break;
+ }
+ }
+ }
}
Selector::~Selector()
{
}
-Optional<Selector::PseudoElement> Selector::pseudo_element() const
-{
- // Note: This assumes that only one pseudo-element is allowed in a selector, and that it appears at the end.
- // This is true currently, and there are no current proposals to change this, but you never know!
- if (compound_selectors().is_empty())
- return {};
- for (auto const& simple_selector : compound_selectors().last().simple_selectors) {
- if (simple_selector.type == SimpleSelector::Type::PseudoElement)
- return simple_selector.pseudo_element;
- }
- return {};
-}
-
// https://www.w3.org/TR/selectors-4/#specificity-rules
u32 Selector::specificity() const
{
diff --git a/Userland/Libraries/LibWeb/CSS/Selector.h b/Userland/Libraries/LibWeb/CSS/Selector.h
index 9ee035730f..8d05b6e312 100644
--- a/Userland/Libraries/LibWeb/CSS/Selector.h
+++ b/Userland/Libraries/LibWeb/CSS/Selector.h
@@ -135,7 +135,7 @@ public:
~Selector();
Vector<CompoundSelector> const& compound_selectors() const { return m_compound_selectors; }
- Optional<PseudoElement> pseudo_element() const;
+ Optional<PseudoElement> pseudo_element() const { return m_pseudo_element; }
u32 specificity() const;
String serialize() const;
@@ -144,6 +144,7 @@ private:
Vector<CompoundSelector> m_compound_selectors;
mutable Optional<u32> m_specificity;
+ Optional<Selector::PseudoElement> m_pseudo_element;
};
constexpr StringView pseudo_element_name(Selector::PseudoElement pseudo_element)