1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:08:11 +00:00

LibHTML: Implement some very simple selector matching.

We walk the entire DOM and check all selectors against all elements. Only
id, class and tag name are checked right now. There's no ancestor stack
or compound selectors. All in good time :^)
This commit is contained in:
Andreas Kling 2019-06-27 20:40:21 +02:00
parent 2b4eea5a50
commit e971f5604c
7 changed files with 109 additions and 29 deletions

View file

@ -50,6 +50,19 @@ void Element::set_attributes(Vector<Attribute>&& attributes)
m_attributes = move(attributes);
}
bool Element::has_class(const StringView& class_name) const
{
auto value = attribute("class");
if (value.is_empty())
return false;
auto parts = value.split_view(' ');
for (auto& part : parts) {
if (part == class_name)
return true;
}
return false;
}
RefPtr<LayoutNode> Element::create_layout_node()
{
if (m_tag_name == "html")