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

LibWeb: Implement all "attributes" mutation records for MutationObserver

This commit is contained in:
Luke Wilde 2022-07-11 16:40:01 +01:00 committed by Andreas Kling
parent 1ca8782c99
commit a718c62c01
4 changed files with 62 additions and 6 deletions

View file

@ -7,6 +7,8 @@
#include <LibWeb/DOM/Attribute.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/MutationType.h>
#include <LibWeb/DOM/StaticNodeList.h>
namespace Web::DOM {
@ -23,6 +25,11 @@ Attribute::Attribute(Document& document, FlyString local_name, String value, Ele
{
}
Element* Attribute::owner_element()
{
return m_owner_element;
}
Element const* Attribute::owner_element() const
{
return m_owner_element;
@ -33,4 +40,33 @@ void Attribute::set_owner_element(Element const* owner_element)
m_owner_element = owner_element;
}
// https://dom.spec.whatwg.org/#set-an-existing-attribute-value
void Attribute::set_value(String value)
{
// 1. If attributes element is null, then set attributes value to value.
if (!owner_element()) {
m_value = move(value);
return;
}
// 2. Otherwise, change attribute to value.
// https://dom.spec.whatwg.org/#concept-element-attributes-change
// 1. Handle attribute changes for attribute with attributes element, attributes value, and value.
handle_attribute_changes(*owner_element(), m_value, value);
// 2. Set attributes value to value.
m_value = move(value);
}
// https://dom.spec.whatwg.org/#handle-attribute-changes
void Attribute::handle_attribute_changes(Element& element, String const& old_value, [[maybe_unused]] String const& new_value)
{
// 1. Queue a mutation record of "attributes" for element with attributes local name, attributes namespace, oldValue, « », « », null, and null.
element.queue_mutation_record(MutationType::attributes, local_name(), namespace_uri(), old_value, StaticNodeList::create({}), StaticNodeList::create({}), nullptr, nullptr);
// FIXME: 2. If element is custom, then enqueue a custom element callback reaction with element, callback name "attributeChangedCallback", and an argument list containing attributes local name, oldValue, newValue, and attributes namespace.
// FIXME: 3. Run the attribute change steps with element, attributes local name, oldValue, newValue, and attributes namespace.
}
}