2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2021-05-08 23:19:25 +03:00
|
|
|
#include "Selector.h"
|
2019-06-20 23:25:25 +02:00
|
|
|
|
2020-07-26 20:01:35 +02:00
|
|
|
namespace Web::CSS {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2021-07-23 15:24:33 +01:00
|
|
|
Selector::Selector(Vector<CompoundSelector>&& compound_selectors)
|
|
|
|
: m_compound_selectors(move(compound_selectors))
|
2019-06-20 23:25:25 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Selector::~Selector()
|
|
|
|
{
|
|
|
|
}
|
2019-06-29 17:32:32 +02:00
|
|
|
|
2020-06-25 16:43:49 +02:00
|
|
|
u32 Selector::specificity() const
|
2019-06-29 17:32:32 +02:00
|
|
|
{
|
|
|
|
unsigned ids = 0;
|
|
|
|
unsigned tag_names = 0;
|
|
|
|
unsigned classes = 0;
|
|
|
|
|
2021-07-23 15:24:33 +01:00
|
|
|
for (auto& list : m_compound_selectors) {
|
|
|
|
for (auto& simple_selector : list.simple_selectors) {
|
2019-11-27 20:37:36 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-06-29 17:32:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:43:49 +02:00
|
|
|
return ids * 0x10000 + classes * 0x100 + tag_names;
|
2019-06-29 17:32:32 +02:00
|
|
|
}
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|