mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 15:16:14 +00:00
LibWeb: Bring Selector terminology in line with the CSS spec
- CompoundSelector -> *deleted* - ComplexSelector -> CompoundSelector - Relation -> Combinator Our Selector is really a ComplexSelector, but only the Parser and SelectorEngine need to know that, so keeping it named Selector makes it more understandable for users. Our CompoundSelector is really a CompoundSelectorAndCombinator. Combining the two makes sense in our codebase, but the accurate name is so long that I think it makes the code less readable. Renamed some Combinators to also match the spec terminology: - AdjacentSibling -> NextSibling - GeneralSibling -> SubsequentSibling The previous names are somewhat ambiguous, so hopefully this is clearer.
This commit is contained in:
committed by
Andreas Kling
parent
ca436afeb5
commit
6ea5d03f43
@@ -195,15 +195,15 @@ static bool matches(CSS::Selector::SimpleSelector const& component, DOM::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) {
|
||||
if (!matches(component, element))
|
||||
auto& relative_selector = selector.compound_selectors()[component_list_index];
|
||||
for (auto& simple_selector : relative_selector.simple_selectors) {
|
||||
if (!matches(simple_selector, element))
|
||||
return false;
|
||||
}
|
||||
switch (component_list.relation) {
|
||||
case CSS::Selector::ComplexSelector::Relation::None:
|
||||
switch (relative_selector.combinator) {
|
||||
case CSS::Selector::Combinator::None:
|
||||
return true;
|
||||
case CSS::Selector::ComplexSelector::Relation::Descendant:
|
||||
case CSS::Selector::Combinator::Descendant:
|
||||
VERIFY(component_list_index != 0);
|
||||
for (auto* ancestor = element.parent(); ancestor; ancestor = ancestor->parent()) {
|
||||
if (!is<DOM::Element>(*ancestor))
|
||||
@@ -212,24 +212,24 @@ static bool matches(CSS::Selector const& selector, int component_list_index, DOM
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case CSS::Selector::ComplexSelector::Relation::ImmediateChild:
|
||||
case CSS::Selector::Combinator::ImmediateChild:
|
||||
VERIFY(component_list_index != 0);
|
||||
if (!element.parent() || !is<DOM::Element>(*element.parent()))
|
||||
return false;
|
||||
return matches(selector, component_list_index - 1, verify_cast<DOM::Element>(*element.parent()));
|
||||
case CSS::Selector::ComplexSelector::Relation::AdjacentSibling:
|
||||
case CSS::Selector::Combinator::NextSibling:
|
||||
VERIFY(component_list_index != 0);
|
||||
if (auto* sibling = element.previous_element_sibling())
|
||||
return matches(selector, component_list_index - 1, *sibling);
|
||||
return false;
|
||||
case CSS::Selector::ComplexSelector::Relation::GeneralSibling:
|
||||
case CSS::Selector::Combinator::SubsequentSibling:
|
||||
VERIFY(component_list_index != 0);
|
||||
for (auto* sibling = element.previous_element_sibling(); sibling; sibling = sibling->previous_element_sibling()) {
|
||||
if (matches(selector, component_list_index - 1, *sibling))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case CSS::Selector::ComplexSelector::Relation::Column:
|
||||
case CSS::Selector::Combinator::Column:
|
||||
TODO();
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
@@ -237,8 +237,8 @@ static bool matches(CSS::Selector const& selector, int component_list_index, DOM
|
||||
|
||||
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);
|
||||
VERIFY(!selector.compound_selectors().is_empty());
|
||||
return matches(selector, selector.compound_selectors().size() - 1, element);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user