mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:47:35 +00:00
LibWeb: Convert CSS Dump, Selector, & SelectorEngine to east const
This commit is contained in:
parent
cd55b817cf
commit
dadcb46344
6 changed files with 57 additions and 57 deletions
|
@ -47,7 +47,7 @@ u32 Selector::specificity() const
|
|||
return ids * 0x10000 + classes * 0x100 + tag_names;
|
||||
}
|
||||
|
||||
Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPattern::parse(const StringView& args)
|
||||
Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPattern::parse(StringView const& args)
|
||||
{
|
||||
CSS::Selector::SimpleSelector::NthChildPattern pattern;
|
||||
if (args.equals_ignoring_case("odd")) {
|
||||
|
@ -56,7 +56,7 @@ Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPatt
|
|||
} else if (args.equals_ignoring_case("even")) {
|
||||
pattern.step_size = 2;
|
||||
} else {
|
||||
const auto consume_int = [](GenericLexer& lexer) -> Optional<int> {
|
||||
auto const consume_int = [](GenericLexer& lexer) -> Optional<int> {
|
||||
return AK::StringUtils::convert_to_int(lexer.consume_while([](char c) -> bool {
|
||||
return isdigit(c) || c == '+' || c == '-';
|
||||
}));
|
||||
|
@ -81,7 +81,7 @@ Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPatt
|
|||
step_size_or_offset = -1;
|
||||
lexer.retreat();
|
||||
} else {
|
||||
const auto value = consume_int(lexer);
|
||||
auto const value = consume_int(lexer);
|
||||
if (!value.has_value())
|
||||
return {};
|
||||
step_size_or_offset = value.value();
|
||||
|
@ -90,12 +90,12 @@ Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPatt
|
|||
if (lexer.consume_specific("n")) {
|
||||
lexer.ignore_while(isspace);
|
||||
if (lexer.next_is('+') || lexer.next_is('-')) {
|
||||
const auto sign = lexer.next_is('+') ? 1 : -1;
|
||||
auto const sign = lexer.next_is('+') ? 1 : -1;
|
||||
lexer.ignore();
|
||||
lexer.ignore_while(isspace);
|
||||
|
||||
// "An+B" pattern
|
||||
const auto offset = consume_int(lexer);
|
||||
auto const offset = consume_int(lexer);
|
||||
if (!offset.has_value())
|
||||
return {};
|
||||
pattern.step_size = step_size_or_offset;
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
int step_size = 0;
|
||||
int offset = 0;
|
||||
|
||||
static NthChildPattern parse(const StringView& args);
|
||||
static NthChildPattern parse(StringView const& args);
|
||||
};
|
||||
|
||||
// FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere.
|
||||
|
@ -103,7 +103,7 @@ public:
|
|||
explicit Selector(Vector<ComplexSelector>&&);
|
||||
~Selector();
|
||||
|
||||
const Vector<ComplexSelector>& complex_selectors() const { return m_complex_selectors; }
|
||||
Vector<ComplexSelector> const& complex_selectors() const { return m_complex_selectors; }
|
||||
|
||||
u32 specificity() const;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
namespace Web::SelectorEngine {
|
||||
|
||||
static bool matches_hover_pseudo_class(const DOM::Element& element)
|
||||
static bool matches_hover_pseudo_class(DOM::Element const& element)
|
||||
{
|
||||
auto* hovered_node = element.document().hovered_node();
|
||||
if (!hovered_node)
|
||||
|
@ -24,7 +24,7 @@ static bool matches_hover_pseudo_class(const DOM::Element& element)
|
|||
return element.is_ancestor_of(*hovered_node);
|
||||
}
|
||||
|
||||
static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::Element& element)
|
||||
static bool matches(CSS::Selector::SimpleSelector const& component, DOM::Element const& element)
|
||||
{
|
||||
switch (component.pseudo_element) {
|
||||
case CSS::Selector::SimpleSelector::PseudoElement::None:
|
||||
|
@ -119,12 +119,12 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
|
|||
}
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::NthChild:
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::NthLastChild:
|
||||
const auto step_size = component.nth_child_pattern.step_size;
|
||||
const auto offset = component.nth_child_pattern.offset;
|
||||
auto const step_size = component.nth_child_pattern.step_size;
|
||||
auto const offset = component.nth_child_pattern.offset;
|
||||
if (step_size == 0 && offset == 0)
|
||||
return false; // "If both a and b are equal to zero, the pseudo-class represents no element in the document tree."
|
||||
|
||||
const auto* parent = element.parent_element();
|
||||
auto const* parent = element.parent_element();
|
||||
if (!parent)
|
||||
return false;
|
||||
|
||||
|
@ -152,7 +152,7 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
|
|||
}
|
||||
|
||||
// Like "a % b", but handles negative integers correctly.
|
||||
const auto canonical_modulo = [](int a, int b) -> int {
|
||||
auto const canonical_modulo = [](int a, int b) -> int {
|
||||
int c = a % b;
|
||||
if ((c < 0 && b > 0) || (c > 0 && b < 0)) {
|
||||
c += b;
|
||||
|
@ -218,7 +218,7 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
|
|||
}
|
||||
}
|
||||
|
||||
static bool matches(const CSS::Selector& selector, int component_list_index, const DOM::Element& element)
|
||||
static bool matches(CSS::Selector const& selector, int component_list_index, DOM::Element const& element)
|
||||
{
|
||||
auto& component_list = selector.complex_selectors()[component_list_index];
|
||||
for (auto& component : component_list.compound_selector) {
|
||||
|
@ -260,7 +260,7 @@ static bool matches(const CSS::Selector& selector, int component_list_index, con
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
bool matches(const CSS::Selector& selector, const DOM::Element& element)
|
||||
bool matches(CSS::Selector const& selector, DOM::Element const& element)
|
||||
{
|
||||
VERIFY(!selector.complex_selectors().is_empty());
|
||||
return matches(selector, selector.complex_selectors().size() - 1, element);
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
|
||||
namespace Web::SelectorEngine {
|
||||
|
||||
bool matches(const CSS::Selector&, const DOM::Element&);
|
||||
bool matches(CSS::Selector const&, DOM::Element const&);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue