mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibWeb: Support Element.matches(selectors)
This returns whether an element matches any of a set of selectors.
This commit is contained in:
parent
439be913cf
commit
9d852623f2
3 changed files with 20 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
|
||||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/CSS/StyleInvalidator.h>
|
||||
#include <LibWeb/DOM/DOMException.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
@ -247,6 +248,21 @@ NonnullRefPtr<CSS::StyleProperties> Element::computed_style()
|
|||
return properties;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-matches
|
||||
DOM::ExceptionOr<bool> Element::matches(StringView selectors) const
|
||||
{
|
||||
auto maybe_selectors = parse_selector(CSS::ParsingContext(static_cast<ParentNode&>(const_cast<Element&>(*this))), selectors);
|
||||
if (!maybe_selectors.has_value())
|
||||
return DOM::SyntaxError::create("Failed to parse selector");
|
||||
|
||||
auto sel = maybe_selectors.value();
|
||||
for (auto& s : sel) {
|
||||
if (SelectorEngine::matches(s, *this))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ExceptionOr<void> Element::set_inner_html(String const& markup)
|
||||
{
|
||||
auto result = DOMParsing::InnerHTML::inner_html_setter(*this, markup);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue