2020-05-22 21:45:00 +02:00
|
|
|
/*
|
2021-09-16 00:51:48 +02:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-05-22 21:45:00 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-22 21:45:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
#include <AK/DeprecatedFlyString.h>
|
2021-10-17 15:09:47 -04:00
|
|
|
#include <AK/WeakPtr.h>
|
2021-10-15 09:57:07 -04:00
|
|
|
#include <LibWeb/DOM/Node.h>
|
2022-02-18 20:52:47 +01:00
|
|
|
#include <LibWeb/DOM/QualifiedName.h>
|
2020-05-22 21:45:00 +02:00
|
|
|
|
2021-09-16 00:51:48 +02:00
|
|
|
namespace Web::DOM {
|
2020-05-22 21:45:00 +02:00
|
|
|
|
2021-10-15 09:57:07 -04:00
|
|
|
// https://dom.spec.whatwg.org/#attr
|
2022-09-18 01:03:58 +02:00
|
|
|
class Attr final : public Node {
|
|
|
|
|
WEB_PLATFORM_OBJECT(Attr, Node);
|
2020-05-22 21:45:00 +02:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2023-03-29 23:46:18 +01:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create(Document&, QualifiedName, DeprecatedString value = "", Element* = nullptr);
|
|
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Attr>> create(Document&, DeprecatedFlyString local_name, DeprecatedString value = "", Element* = nullptr);
|
2022-12-13 13:08:46 +01:00
|
|
|
JS::NonnullGCPtr<Attr> clone(Document&);
|
2020-05-22 21:45:00 +02:00
|
|
|
|
2022-09-18 01:03:58 +02:00
|
|
|
virtual ~Attr() override = default;
|
2021-10-15 09:57:07 -04:00
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
virtual DeprecatedFlyString node_name() const override { return name(); }
|
2021-10-15 09:57:07 -04:00
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
DeprecatedFlyString const& namespace_uri() const { return m_qualified_name.namespace_(); }
|
|
|
|
|
DeprecatedFlyString const& prefix() const { return m_qualified_name.prefix(); }
|
|
|
|
|
DeprecatedFlyString const& local_name() const { return m_qualified_name.local_name(); }
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& name() const { return m_qualified_name.as_string(); }
|
2021-10-15 09:57:07 -04:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& value() const { return m_value; }
|
|
|
|
|
void set_value(DeprecatedString value);
|
2021-10-15 09:57:07 -04:00
|
|
|
|
2023-03-29 23:46:18 +01:00
|
|
|
Element* owner_element();
|
2021-10-17 15:09:47 -04:00
|
|
|
Element const* owner_element() const;
|
2023-03-29 23:46:18 +01:00
|
|
|
void set_owner_element(Element* owner_element);
|
2021-10-15 09:57:07 -04:00
|
|
|
|
|
|
|
|
// Always returns true: https://dom.spec.whatwg.org/#dom-attr-specified
|
|
|
|
|
constexpr bool specified() const { return true; }
|
2020-05-22 21:45:00 +02:00
|
|
|
|
2023-03-29 23:46:18 +01:00
|
|
|
void handle_attribute_changes(Element&, DeprecatedString const& old_value, DeprecatedString const& new_value);
|
2022-07-11 16:40:01 +01:00
|
|
|
|
2020-05-22 21:45:00 +02:00
|
|
|
private:
|
2023-03-29 23:46:18 +01:00
|
|
|
Attr(Document&, QualifiedName, DeprecatedString value, Element*);
|
2021-10-15 09:57:07 -04:00
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2021-10-15 09:57:07 -04:00
|
|
|
QualifiedName m_qualified_name;
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_value;
|
2023-03-29 23:46:18 +01:00
|
|
|
JS::GCPtr<Element> m_owner_element;
|
2020-05-22 21:45:00 +02:00
|
|
|
};
|
|
|
|
|
|
2022-01-31 18:05:54 +00:00
|
|
|
template<>
|
2022-09-18 01:03:58 +02:00
|
|
|
inline bool Node::fast_is<Attr>() const { return is_attribute(); }
|
2022-01-31 18:05:54 +00:00
|
|
|
|
2020-05-22 21:45:00 +02:00
|
|
|
}
|