1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:17:44 +00:00

LibWeb: Match styles for pseudo-elements

Since each selector can only have zero or one pseudo-element, we match
against it as a separate step, before matching the rest of the
selector. This should be faster, but mostly I did this because I could
not figure out how else to stop selectors without a pseudo-element from
matching the pseudo-element, eg so `.foo` styles don't affect
`.foo::before`.
This commit is contained in:
Sam Atkins 2022-02-24 15:54:12 +00:00 committed by Andreas Kling
parent caef4ec157
commit 7eb7396f8b
6 changed files with 86 additions and 49 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -18,6 +19,19 @@ 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 {};
}
u32 Selector::specificity() const
{
if (m_specificity.has_value())