1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:07:45 +00:00

LibWeb: Extract changing an attribute to its own method

This will be needed outside of this the method to set an existing
attribute, so do not inline this implementation.
This commit is contained in:
Timothy Flynn 2023-09-01 10:40:37 -04:00 committed by Ali Mohammad Pur
parent 889e6ab43d
commit 2c096486a4
2 changed files with 14 additions and 5 deletions

View file

@ -71,16 +71,24 @@ void Attr::set_value(DeprecatedString value)
// 1. If attributes element is null, then set attributes value to value. // 1. If attributes element is null, then set attributes value to value.
if (!owner_element()) { if (!owner_element()) {
m_value = move(value); m_value = move(value);
return;
} }
// 2. Otherwise, change attribute to value. // 2. Otherwise, change attribute to value.
// https://dom.spec.whatwg.org/#concept-element-attributes-change else {
// 1. Handle attribute changes for attribute with attributes element, attributes value, and value. change_attribute(move(value));
handle_attribute_changes(*owner_element(), m_value, value); }
}
// https://dom.spec.whatwg.org/#concept-element-attributes-change
void Attr::change_attribute(DeprecatedString value)
{
// 1. Let oldValue be attributes value.
auto old_value = move(m_value);
// 2. Set attributes value to value. // 2. Set attributes value to value.
m_value = move(value); m_value = move(value);
// 3. Handle attribute changes for attribute with attributes element, oldValue, and value.
handle_attribute_changes(*owner_element(), old_value, m_value);
} }
// https://dom.spec.whatwg.org/#handle-attribute-changes // https://dom.spec.whatwg.org/#handle-attribute-changes

View file

@ -33,6 +33,7 @@ public:
DeprecatedString const& value() const { return m_value; } DeprecatedString const& value() const { return m_value; }
void set_value(DeprecatedString value); void set_value(DeprecatedString value);
void change_attribute(DeprecatedString value);
Element* owner_element(); Element* owner_element();
Element const* owner_element() const; Element const* owner_element() const;