mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:17:44 +00:00
LibWeb: Implement the Element classList attribute
And ensure it is updated (if it exists) when the 'class' attribute is changed.
This commit is contained in:
parent
d24ae8063b
commit
14349f058a
3 changed files with 14 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/CSS/StyleInvalidator.h>
|
||||
#include <LibWeb/DOM/DOMException.h>
|
||||
#include <LibWeb/DOM/DOMTokenList.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
|
@ -171,6 +172,8 @@ void Element::parse_attribute(const FlyString& name, const String& value)
|
|||
for (auto& new_class : new_classes) {
|
||||
m_classes.unchecked_append(new_class);
|
||||
}
|
||||
if (m_class_list)
|
||||
m_class_list->associated_attribute_changed(value);
|
||||
} else if (name == HTML::AttributeNames::style) {
|
||||
auto parsed_style = parse_css_declaration(CSS::ParsingContext(document()), value);
|
||||
if (!parsed_style.is_null()) {
|
||||
|
@ -256,6 +259,13 @@ NonnullRefPtr<CSS::StyleProperties> Element::computed_style()
|
|||
return properties;
|
||||
}
|
||||
|
||||
RefPtr<DOMTokenList> const& Element::class_list()
|
||||
{
|
||||
if (!m_class_list)
|
||||
m_class_list = DOMTokenList::create(*this, HTML::AttributeNames::class_);
|
||||
return m_class_list;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-matches
|
||||
DOM::ExceptionOr<bool> Element::matches(StringView selectors) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue