mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-03 01:38:52 +00:00
LibHTML: Implement compound selectors
This patch moves the Selector object model closer to the specification objects in Selectors Level 4. A "Selector" in LibHTML is now a { Vector<ComplexSelector> }, which is a { Relation, CompoundSelector }. A CompoundSelector is really just a Vector<SimpleSelector>, and SimpleSelector is "Component" renamed. This makes a lot more selectors actually match on the Ubuntu Apache2 default homepage. :^)
This commit is contained in:
parent
449ebbddb6
commit
d19d4da14a
Notes:
sideshowbarker
2024-07-19 11:02:52 +09:00
Author: https://github.com/awesomekling
Commit: d19d4da14a
5 changed files with 194 additions and 148 deletions
|
@ -1,7 +1,7 @@
|
|||
#include <LibHTML/CSS/Selector.h>
|
||||
|
||||
Selector::Selector(Vector<Component>&& components)
|
||||
: m_components(move(components))
|
||||
Selector::Selector(Vector<ComplexSelector>&& component_lists)
|
||||
: m_complex_selectors(move(component_lists))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -15,19 +15,21 @@ Specificity Selector::specificity() const
|
|||
unsigned tag_names = 0;
|
||||
unsigned classes = 0;
|
||||
|
||||
for (auto& component : m_components) {
|
||||
switch (component.type) {
|
||||
case Component::Type::Id:
|
||||
++ids;
|
||||
break;
|
||||
case Component::Type::Class:
|
||||
++classes;
|
||||
break;
|
||||
case Component::Type::TagName:
|
||||
++tag_names;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
for (auto& list : m_complex_selectors) {
|
||||
for (auto& simple_selector : list.compound_selector) {
|
||||
switch (simple_selector.type) {
|
||||
case SimpleSelector::Type::Id:
|
||||
++ids;
|
||||
break;
|
||||
case SimpleSelector::Type::Class:
|
||||
++classes;
|
||||
break;
|
||||
case SimpleSelector::Type::TagName:
|
||||
++tag_names;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue