Attr.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. static WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create(Document&, DeprecatedFlyString local_name, DeprecatedString value, Element const* = nullptr);
  17. JS::NonnullGCPtr<Attr> clone(Document&);
  18. virtual ~Attr() override = default;
  19. virtual DeprecatedFlyString node_name() const override { return name(); }
  20. DeprecatedFlyString const& namespace_uri() const { return m_qualified_name.namespace_(); }
  21. DeprecatedFlyString const& prefix() const { return m_qualified_name.prefix(); }
  22. DeprecatedFlyString const& local_name() const { return m_qualified_name.local_name(); }
  23. DeprecatedString const& name() const { return m_qualified_name.as_string(); }
  24. DeprecatedString const& value() const { return m_value; }
  25. void set_value(DeprecatedString value);
  26. Element const* owner_element() const;
  27. void set_owner_element(Element const* owner_element);
  28. // Always returns true: https://dom.spec.whatwg.org/#dom-attr-specified
  29. constexpr bool specified() const { return true; }
  30. void handle_attribute_changes(Element const&, DeprecatedString const& old_value, DeprecatedString const& new_value);
  31. private:
  32. Attr(Document&, QualifiedName, DeprecatedString value, Element const*);
  33. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  34. virtual void visit_edges(Cell::Visitor&) override;
  35. QualifiedName m_qualified_name;
  36. DeprecatedString m_value;
  37. JS::GCPtr<Element const> m_owner_element;
  38. };
  39. template<>
  40. inline bool Node::fast_is<Attr>() const { return is_attribute(); }
  41. }