Attr.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedFlyString.h>
  8. #include <AK/WeakPtr.h>
  9. #include <LibWeb/DOM/Node.h>
  10. #include <LibWeb/DOM/QualifiedName.h>
  11. namespace Web::DOM {
  12. // https://dom.spec.whatwg.org/#attr
  13. class Attr final : public Node {
  14. WEB_PLATFORM_OBJECT(Attr, Node);
  15. public:
  16. [[nodiscard]] static JS::NonnullGCPtr<Attr> create(Document&, QualifiedName, DeprecatedString value = "", Element* = nullptr);
  17. [[nodiscard]] static JS::NonnullGCPtr<Attr> create(Document&, DeprecatedFlyString local_name, DeprecatedString value = "", Element* = nullptr);
  18. JS::NonnullGCPtr<Attr> clone(Document&);
  19. virtual ~Attr() override = default;
  20. virtual FlyString node_name() const override { return MUST(FlyString::from_deprecated_fly_string(name())); }
  21. DeprecatedFlyString const& namespace_uri() const { return m_qualified_name.namespace_(); }
  22. DeprecatedFlyString const& prefix() const { return m_qualified_name.prefix(); }
  23. DeprecatedFlyString const& local_name() const { return m_qualified_name.local_name(); }
  24. DeprecatedFlyString const& name() const { return m_qualified_name.as_string(); }
  25. DeprecatedString const& value() const { return m_value; }
  26. void set_value(DeprecatedString value);
  27. void change_attribute(DeprecatedString value);
  28. Element* owner_element();
  29. Element const* owner_element() const;
  30. void set_owner_element(Element* owner_element);
  31. // Always returns true: https://dom.spec.whatwg.org/#dom-attr-specified
  32. constexpr bool specified() const { return true; }
  33. void handle_attribute_changes(Element&, DeprecatedString const& old_value, DeprecatedString const& new_value);
  34. private:
  35. Attr(Document&, QualifiedName, DeprecatedString value, Element*);
  36. virtual void initialize(JS::Realm&) override;
  37. virtual void visit_edges(Cell::Visitor&) override;
  38. QualifiedName m_qualified_name;
  39. DeprecatedString m_value;
  40. JS::GCPtr<Element> m_owner_element;
  41. };
  42. template<>
  43. inline bool Node::fast_is<Attr>() const { return is_attribute(); }
  44. }