| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-01-31 13:07:22 -05:00
										 |  |  |  * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-08-08 15:06:56 +02:00
										 |  |  |  * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-12-16 17:31:56 +03:00
										 |  |  |  * Copyright (c) 2022, Alexander Narsudinov <a.narsudinov@gmail.com> | 
					
						
							| 
									
										
										
										
											2023-02-28 00:05:39 +00:00
										 |  |  |  * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/StringView.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:06:56 +02:00
										 |  |  | #include <LibWeb/Bindings/LegacyPlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  | #include <LibWeb/WebIDL/ExceptionOr.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::DOM { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://dom.spec.whatwg.org/#interface-namednodemap
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:06:56 +02:00
										 |  |  | class NamedNodeMap : public Bindings::LegacyPlatformObject { | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(NamedNodeMap, Bindings::LegacyPlatformObject); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(NamedNodeMap); | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-08-13 13:05:26 +02:00
										 |  |  |     [[nodiscard]] static JS::NonnullGCPtr<NamedNodeMap> create(Element&); | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  |     ~NamedNodeMap() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:06:56 +02:00
										 |  |  |     virtual bool is_supported_property_index(u32 index) const override; | 
					
						
							| 
									
										
										
										
											2023-11-21 07:39:58 +13:00
										 |  |  |     virtual Vector<String> supported_property_names() const override; | 
					
						
							| 
									
										
										
										
											2023-02-28 00:05:39 +00:00
										 |  |  |     virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override; | 
					
						
							| 
									
										
										
										
											2023-10-08 13:16:50 +13:00
										 |  |  |     virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const override; | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     size_t length() const { return m_attributes.size(); } | 
					
						
							|  |  |  |     bool is_empty() const { return m_attributes.is_empty(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Methods defined by the spec for JavaScript:
 | 
					
						
							| 
									
										
										
										
											2022-09-18 01:03:58 +02:00
										 |  |  |     Attr const* item(u32 index) const; | 
					
						
							|  |  |  |     Attr const* get_named_item(StringView qualified_name) const; | 
					
						
							| 
									
										
										
										
											2023-09-06 19:17:17 +12:00
										 |  |  |     Attr const* get_named_item_ns(Optional<String> const& namespace_, StringView local_name) const; | 
					
						
							| 
									
										
										
										
											2023-03-10 14:56:29 +01:00
										 |  |  |     WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_named_item(Attr& attribute); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_named_item_ns(Attr& attribute); | 
					
						
							| 
									
										
										
										
											2022-09-25 17:03:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<Attr const*> remove_named_item(StringView qualified_name); | 
					
						
							| 
									
										
										
										
											2023-09-06 19:17:17 +12:00
										 |  |  |     WebIDL::ExceptionOr<Attr const*> remove_named_item_ns(Optional<String> const& namespace_, StringView local_name); | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Methods defined by the spec for internal use:
 | 
					
						
							| 
									
										
										
										
											2023-09-21 20:26:19 +12:00
										 |  |  |     // FIXME: These should be taking `FlyString const&' / 'Optional<FlyString> const&'
 | 
					
						
							| 
									
										
										
										
											2022-09-18 01:03:58 +02:00
										 |  |  |     Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr); | 
					
						
							| 
									
										
										
										
											2022-12-16 17:31:56 +03:00
										 |  |  |     Attr* get_attribute_ns(StringView namespace_, StringView local_name, size_t* item_index = nullptr); | 
					
						
							| 
									
										
										
										
											2022-09-18 01:03:58 +02:00
										 |  |  |     Attr const* get_attribute(StringView qualified_name, size_t* item_index = nullptr) const; | 
					
						
							| 
									
										
										
										
											2022-12-16 17:31:56 +03:00
										 |  |  |     Attr const* get_attribute_ns(StringView namespace_, StringView local_name, size_t* item_index = nullptr) const; | 
					
						
							| 
									
										
										
										
											2023-03-10 14:56:29 +01:00
										 |  |  |     WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute(Attr& attribute); | 
					
						
							| 
									
										
										
										
											2022-09-18 01:03:58 +02:00
										 |  |  |     void replace_attribute(Attr& old_attribute, Attr& new_attribute, size_t old_attribute_index); | 
					
						
							|  |  |  |     void append_attribute(Attr& attribute); | 
					
						
							| 
									
										
										
										
											2023-09-21 20:09:51 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 11:11:01 +13:00
										 |  |  |     Attr* get_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& local_name, size_t* item_index = nullptr); | 
					
						
							|  |  |  |     Attr const* get_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& local_name, size_t* item_index = nullptr) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-21 20:09:51 +12:00
										 |  |  |     // FIXME: This should take a 'FlyString cosnt&'
 | 
					
						
							| 
									
										
										
										
											2022-09-18 01:03:58 +02:00
										 |  |  |     Attr const* remove_attribute(StringView qualified_name); | 
					
						
							| 
									
										
										
										
											2022-12-17 17:08:51 +03:00
										 |  |  |     Attr const* remove_attribute_ns(StringView namespace_, StringView local_name); | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     explicit NamedNodeMap(Element&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-28 00:05:39 +00:00
										 |  |  |     // ^Bindings::LegacyPlatformObject
 | 
					
						
							|  |  |  |     virtual bool supports_indexed_properties() const override { return true; } | 
					
						
							|  |  |  |     virtual bool supports_named_properties() const override { return true; } | 
					
						
							|  |  |  |     virtual bool has_indexed_property_setter() const override { return false; } | 
					
						
							|  |  |  |     virtual bool has_named_property_setter() const override { return false; } | 
					
						
							|  |  |  |     virtual bool has_named_property_deleter() const override { return false; } | 
					
						
							|  |  |  |     virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; } | 
					
						
							|  |  |  |     virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return true; } | 
					
						
							|  |  |  |     virtual bool has_global_interface_extended_attribute() const override { return false; } | 
					
						
							|  |  |  |     virtual bool indexed_property_setter_has_identifier() const override { return false; } | 
					
						
							|  |  |  |     virtual bool named_property_setter_has_identifier() const override { return false; } | 
					
						
							|  |  |  |     virtual bool named_property_deleter_has_identifier() const override { return false; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     Element& associated_element() { return *m_element; } | 
					
						
							|  |  |  |     Element const& associated_element() const { return *m_element; } | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-11 16:40:01 +01:00
										 |  |  |     void remove_attribute_at_index(size_t attribute_index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     JS::NonnullGCPtr<DOM::Element> m_element; | 
					
						
							| 
									
										
										
										
											2022-09-18 01:03:58 +02:00
										 |  |  |     Vector<JS::NonnullGCPtr<Attr>> m_attributes; | 
					
						
							| 
									
										
										
										
											2021-10-16 15:30:21 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |