1
Fork 0
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:
Andreas Kling 2019-06-29 17:32:32 +02:00
parent b729b5fc64
commit 9a7dc06567
3 changed files with 68 additions and 1 deletions

View file

@ -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 };
}