summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/DOM/Document.h
blob: e75c2d90661eb7b5398226f18f4d276fd4753c99 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once

#include <AK/Function.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>
#include <AK/URL.h>
#include <AK/WeakPtr.h>
#include <LibHTML/CSS/StyleResolver.h>
#include <LibHTML/CSS/StyleSheet.h>
#include <LibHTML/DOM/ParentNode.h>

class CTimer;
class Frame;
class HTMLBodyElement;
class HTMLHtmlElement;
class HTMLHeadElement;
class LayoutDocument;
class LayoutNode;
class StyleResolver;
class StyleSheet;

class Document : public ParentNode {
public:
    Document();
    virtual ~Document() override;

    void set_url(const URL& url) { m_url = url; }
    const URL& url() const { return m_url; }

    URL complete_url(const String&) const;

    void fixup();

    StyleResolver& style_resolver() { return *m_style_resolver; }
    const StyleResolver& style_resolver() const { return *m_style_resolver; }

    void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); }
    const NonnullRefPtrVector<StyleSheet>& stylesheets() const { return m_sheets; }

    virtual String tag_name() const override { return "#document"; }

    void set_hovered_node(Node*);
    Node* hovered_node() { return m_hovered_node; }
    const Node* hovered_node() const { return m_hovered_node; }

    const HTMLHtmlElement* document_element() const;
    const HTMLHeadElement* head() const;
    const HTMLBodyElement* body() const;

    String title() const;

    void attach_to_frame(Badge<Frame>, Frame&);
    void detach_from_frame(Badge<Frame>, Frame&);

    Frame* frame() { return m_frame.ptr(); }
    const Frame* frame() const { return m_frame.ptr(); }

    Color background_color() const;
    RefPtr<GraphicsBitmap> background_image() const;

    Color link_color() const { return m_link_color; }
    void set_link_color(Color);

    Color active_link_color() const { return m_active_link_color; }
    void set_active_link_color(Color);

    Color visited_link_color() const { return m_visited_link_color; }
    void set_visited_link_color(Color);

    void layout();
    void force_layout();

    void update_style();
    void update_layout();
    Function<void()> on_layout_updated;

    virtual bool is_child_allowed(const Node&) const override;

    const LayoutDocument* layout_node() const;
    LayoutDocument* layout_node();

    void schedule_style_update();

    const Element* get_element_by_id(const String&) const;
    Vector<const Element*> get_elements_by_name(const String&) const;

private:
    virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;

    OwnPtr<StyleResolver> m_style_resolver;
    NonnullRefPtrVector<StyleSheet> m_sheets;
    RefPtr<Node> m_hovered_node;
    WeakPtr<Frame> m_frame;
    URL m_url;

    RefPtr<LayoutDocument> m_layout_root;

    Color m_link_color { Color::Blue };
    Color m_active_link_color { Color::Red };
    Color m_visited_link_color { Color::Magenta };

    RefPtr<CTimer> m_style_update_timer;
};

template<>
inline bool is<Document>(const Node& node)
{
    return node.is_document();
}