mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 15:05:07 +00:00
LibHTML: Add Selector::specificity(), which returns a Specificity object.
This commit is contained in:
parent
b729b5fc64
commit
9a7dc06567
3 changed files with 68 additions and 1 deletions
|
@ -8,3 +8,28 @@ Selector::Selector(Vector<Component>&& components)
|
|||
Selector::~Selector()
|
||||
{
|
||||
}
|
||||
|
||||
Specificity Selector::specificity() const
|
||||
{
|
||||
unsigned ids = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return { ids, classes, tag_names };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue