NamedNodeMap.h 2.1 KB

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