2021-10-16 15:30:21 -04:00
|
|
|
/*
|
2022-01-31 13:07:22 -05:00
|
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.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
|
|
|
|
|
2024-01-09 16:05:03 -07:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.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
|
2024-01-09 16:05:03 -07:00
|
|
|
class NamedNodeMap : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(NamedNodeMap, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(NamedNodeMap);
|
2021-10-16 15:30:21 -04:00
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<NamedNodeMap> create(Element&);
|
2021-10-16 15:30:21 -04:00
|
|
|
~NamedNodeMap() = default;
|
|
|
|
|
2023-12-24 20:59:00 +01:00
|
|
|
virtual Vector<FlyString> supported_property_names() const override;
|
2024-07-25 18:15:51 +12:00
|
|
|
virtual Optional<JS::Value> item_value(size_t index) const override;
|
2024-07-25 17:36:10 +12:00
|
|
|
virtual 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;
|
2024-01-02 21:23:53 +13:00
|
|
|
Attr const* get_named_item(FlyString const& qualified_name) const;
|
2024-01-02 23:49:13 +13:00
|
|
|
Attr const* get_named_item_ns(Optional<FlyString> const& namespace_, FlyString const& local_name) const;
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ptr<Attr>> set_named_item(Attr& attribute);
|
|
|
|
WebIDL::ExceptionOr<GC::Ptr<Attr>> set_named_item_ns(Attr& attribute);
|
2024-01-02 21:23:53 +13:00
|
|
|
WebIDL::ExceptionOr<Attr const*> remove_named_item(FlyString const& qualified_name);
|
2024-01-02 23:49:13 +13:00
|
|
|
WebIDL::ExceptionOr<Attr const*> remove_named_item_ns(Optional<FlyString> const& namespace_, FlyString const& local_name);
|
2021-10-16 15:30:21 -04:00
|
|
|
|
|
|
|
// Methods defined by the spec for internal use:
|
2024-01-02 21:23:53 +13:00
|
|
|
Attr* get_attribute(FlyString const& qualified_name, size_t* item_index = nullptr);
|
|
|
|
Attr const* get_attribute(FlyString const& qualified_name, size_t* item_index = nullptr) const;
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ptr<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;
|
|
|
|
|
2024-01-02 21:23:53 +13:00
|
|
|
Attr const* remove_attribute(FlyString const& qualified_name);
|
2024-01-02 23:49:13 +13:00
|
|
|
Attr const* remove_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& local_name);
|
2021-10-16 15:30:21 -04:00
|
|
|
|
2024-11-27 20:24:29 +02:00
|
|
|
Attr const* get_attribute_namespace_agnostic(FlyString const& local_name) const;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<Attr>> remove_attribute_node(GC::Ref<Attr>);
|
2024-04-14 15:49:48 +02:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<DOM::Element> m_element;
|
|
|
|
Vector<GC::Ref<Attr>> m_attributes;
|
2021-10-16 15:30:21 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|