NamedNodeMap.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtrVector.h>
  8. #include <AK/RefCounted.h>
  9. #include <AK/String.h>
  10. #include <AK/StringView.h>
  11. #include <AK/WeakPtr.h>
  12. #include <LibWeb/Bindings/Wrappable.h>
  13. #include <LibWeb/DOM/ExceptionOr.h>
  14. #include <LibWeb/Forward.h>
  15. namespace Web::DOM {
  16. // https://dom.spec.whatwg.org/#interface-namednodemap
  17. class NamedNodeMap final
  18. : public RefCounted<NamedNodeMap>
  19. , public Bindings::Wrappable {
  20. public:
  21. using WrapperType = Bindings::NamedNodeMapWrapper;
  22. static NonnullRefPtr<NamedNodeMap> create(Element const& associated_element);
  23. ~NamedNodeMap() = default;
  24. bool is_supported_property_index(u32 index) const;
  25. Vector<String> supported_property_names() const;
  26. size_t length() const { return m_attributes.size(); }
  27. bool is_empty() const { return m_attributes.is_empty(); }
  28. // Methods defined by the spec for JavaScript:
  29. Attribute const* item(u32 index) const;
  30. Attribute const* get_named_item(StringView qualified_name) const;
  31. ExceptionOr<Attribute const*> set_named_item(Attribute& attribute);
  32. ExceptionOr<Attribute const*> remove_named_item(StringView qualified_name);
  33. // Methods defined by the spec for internal use:
  34. Attribute* get_attribute(StringView qualified_name, size_t* item_index = nullptr);
  35. Attribute const* get_attribute(StringView qualified_name, size_t* item_index = nullptr) const;
  36. ExceptionOr<Attribute const*> set_attribute(Attribute& attribute);
  37. void replace_attribute(Attribute& old_attribute, Attribute& new_attribute, size_t old_attribute_index);
  38. void append_attribute(Attribute& attribute);
  39. Attribute const* remove_attribute(StringView qualified_name);
  40. private:
  41. explicit NamedNodeMap(Element const& associated_element);
  42. WeakPtr<Element> m_associated_element;
  43. NonnullRefPtrVector<Attribute> m_attributes;
  44. };
  45. }
  46. namespace Web::Bindings {
  47. NamedNodeMapWrapper* wrap(JS::GlobalObject&, DOM::NamedNodeMap&);
  48. }