mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			72 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | ||
|  * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
 | ||
|  *
 | ||
|  * SPDX-License-Identifier: BSD-2-Clause
 | ||
|  */
 | ||
| 
 | ||
| #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 {
 | ||
| 
 | ||
| NonnullRefPtr<Attribute> Attribute::create(Document& document, FlyString local_name, String value, Element const* owner_element)
 | ||
| {
 | ||
|     return adopt_ref(*new Attribute(document, move(local_name), move(value), owner_element));
 | ||
| }
 | ||
| 
 | ||
| Attribute::Attribute(Document& document, FlyString local_name, String value, Element const* owner_element)
 | ||
|     : Node(document, NodeType::ATTRIBUTE_NODE)
 | ||
|     , m_qualified_name(move(local_name), {}, {})
 | ||
|     , m_value(move(value))
 | ||
|     , m_owner_element(owner_element)
 | ||
| {
 | ||
| }
 | ||
| 
 | ||
| Element* Attribute::owner_element()
 | ||
| {
 | ||
|     return m_owner_element;
 | ||
| }
 | ||
| 
 | ||
| Element const* Attribute::owner_element() const
 | ||
| {
 | ||
|     return m_owner_element;
 | ||
| }
 | ||
| 
 | ||
| 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 attribute’s element is null, then set attribute’s 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 attribute’s element, attribute’s value, and value.
 | ||
|     handle_attribute_changes(*owner_element(), m_value, value);
 | ||
| 
 | ||
|     // 2. Set attribute’s 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 attribute’s local name, attribute’s 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 attribute’s local name, oldValue, newValue, and attribute’s namespace.
 | ||
| 
 | ||
|     // FIXME: 3. Run the attribute change steps with element, attribute’s local name, oldValue, newValue, and attribute’s namespace.
 | ||
| }
 | ||
| 
 | ||
| }
 | 
