summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/Attribute.h
blob: 1431d3083b56c8ed5b162e4040ad5aace18f8a9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/FlyString.h>
#include <AK/WeakPtr.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/QualifiedName.h>

namespace Web::DOM {

// https://dom.spec.whatwg.org/#attr
class Attribute final : public Node {
public:
    using WrapperType = Bindings::AttributeWrapper;

    static NonnullRefPtr<Attribute> create(Document&, FlyString local_name, String value, Element const* = nullptr);

    virtual ~Attribute() override = default;

    virtual FlyString node_name() const override { return name(); }

    FlyString const& namespace_uri() const { return m_qualified_name.namespace_(); }
    FlyString const& prefix() const { return m_qualified_name.prefix(); }
    FlyString const& local_name() const { return m_qualified_name.local_name(); }
    String const& name() const { return m_qualified_name.as_string(); }

    String const& value() const { return m_value; }
    void set_value(String value);

    Element* owner_element();
    Element const* owner_element() const;
    void set_owner_element(Element const* owner_element);

    // Always returns true: https://dom.spec.whatwg.org/#dom-attr-specified
    constexpr bool specified() const { return true; }

    void handle_attribute_changes(Element&, String const& old_value, String const& new_value);

private:
    Attribute(Document&, FlyString local_name, String value, Element const*);

    QualifiedName m_qualified_name;
    String m_value;
    WeakPtr<Element> m_owner_element;
};

template<>
inline bool Node::fast_is<Attribute>() const { return is_attribute(); }

}