1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-08 06:37:35 +00:00

LibHTML: Implement some attribute selector support

This patch adds a[foo] and a[foo=bar] attribute selectors.

Note that an attribute selector is an optional part of a selector
component, and not a component on its own.
This commit is contained in:
Andreas Kling 2019-11-21 20:07:43 +01:00
parent 54a6ae9201
commit 8946e50986
6 changed files with 115 additions and 8 deletions

View file

@ -29,6 +29,19 @@ bool matches(const Selector::Component& component, const Element& element)
break;
}
switch (component.attribute_match_type) {
case Selector::Component::AttributeMatchType::HasAttribute:
if (!element.has_attribute(component.attribute_name))
return false;
break;
case Selector::Component::AttributeMatchType::ExactValueMatch:
if (element.attribute(component.attribute_name) != component.attribute_value)
return false;
break;
default:
break;
}
switch (component.type) {
case Selector::Component::Type::Universal:
return true;