mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:27:35 +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
|
||||
{
|
||||
|
|
|
@ -58,6 +58,8 @@ public:
|
|||
size_t attribute_list_size() const { return m_attributes->length(); }
|
||||
NonnullRefPtr<NamedNodeMap> const& attributes() const { return m_attributes; }
|
||||
|
||||
RefPtr<DOMTokenList> const& class_list();
|
||||
|
||||
DOM::ExceptionOr<bool> matches(StringView selectors) const;
|
||||
|
||||
int client_top() const;
|
||||
|
@ -140,6 +142,7 @@ private:
|
|||
RefPtr<CSS::StyleProperties> m_specified_css_values;
|
||||
HashMap<String, CSS::StyleComputer::CustomPropertyResolutionTuple> m_custom_properties;
|
||||
|
||||
RefPtr<DOMTokenList> m_class_list;
|
||||
Vector<FlyString> m_classes;
|
||||
|
||||
RefPtr<ShadowRoot> m_shadow_root;
|
||||
|
|
|
@ -20,6 +20,7 @@ interface Element : Node {
|
|||
|
||||
[Reflect] attribute DOMString id;
|
||||
[Reflect=class] attribute DOMString className;
|
||||
[SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
|
||||
|
||||
boolean matches(DOMString selectors);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue