
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. :^)
37 lines
853 B
C++
37 lines
853 B
C++
#include <LibHTML/CSS/Selector.h>
|
|
|
|
Selector::Selector(Vector<ComplexSelector>&& component_lists)
|
|
: m_complex_selectors(move(component_lists))
|
|
{
|
|
}
|
|
|
|
Selector::~Selector()
|
|
{
|
|
}
|
|
|
|
Specificity Selector::specificity() const
|
|
{
|
|
unsigned ids = 0;
|
|
unsigned tag_names = 0;
|
|
unsigned classes = 0;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
return { ids, classes, tag_names };
|
|
}
|