2019-06-15 19:55:47 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-06 14:58:18 +03:00
|
|
|
#include <AK/Function.h>
|
2019-06-29 22:42:07 +03:00
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
2019-09-29 17:24:57 +03:00
|
|
|
#include <AK/String.h>
|
2019-10-05 11:16:27 +03:00
|
|
|
#include <AK/URL.h>
|
2019-10-04 16:50:04 +03:00
|
|
|
#include <AK/WeakPtr.h>
|
2019-06-29 22:42:07 +03:00
|
|
|
#include <LibHTML/CSS/StyleResolver.h>
|
|
|
|
#include <LibHTML/CSS/StyleSheet.h>
|
2019-06-16 00:41:15 +03:00
|
|
|
#include <LibHTML/DOM/ParentNode.h>
|
2019-06-15 19:55:47 +03:00
|
|
|
|
2019-10-04 16:50:04 +03:00
|
|
|
class Frame;
|
2019-10-04 22:05:52 +03:00
|
|
|
class HTMLBodyElement;
|
2019-09-29 17:24:57 +03:00
|
|
|
class HTMLHtmlElement;
|
|
|
|
class HTMLHeadElement;
|
2019-10-13 13:34:25 +03:00
|
|
|
class LayoutDocument;
|
2019-06-15 23:49:44 +03:00
|
|
|
class LayoutNode;
|
2019-06-29 22:42:07 +03:00
|
|
|
class StyleResolver;
|
|
|
|
class StyleSheet;
|
2019-06-15 23:49:44 +03:00
|
|
|
|
2019-06-15 19:55:47 +03:00
|
|
|
class Document : public ParentNode {
|
|
|
|
public:
|
|
|
|
Document();
|
|
|
|
virtual ~Document() override;
|
|
|
|
|
2019-10-05 11:16:27 +03:00
|
|
|
void set_url(const URL& url) { m_url = url; }
|
|
|
|
const URL& url() const { return m_url; }
|
|
|
|
|
|
|
|
URL complete_url(const String&) const;
|
|
|
|
|
2019-10-09 19:54:34 +03:00
|
|
|
void fixup();
|
2019-09-25 12:26:26 +03:00
|
|
|
|
2019-06-29 22:42:07 +03:00
|
|
|
StyleResolver& style_resolver();
|
2019-06-15 23:49:44 +03:00
|
|
|
|
2019-06-29 22:42:07 +03:00
|
|
|
void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); }
|
|
|
|
const NonnullRefPtrVector<StyleSheet>& stylesheets() const { return m_sheets; }
|
2019-06-15 23:49:44 +03:00
|
|
|
|
2019-09-28 23:59:16 +03:00
|
|
|
virtual String tag_name() const override { return "#document"; }
|
|
|
|
|
2019-10-14 18:54:17 +03:00
|
|
|
void set_hovered_node(Node*);
|
2019-09-29 12:50:35 +03:00
|
|
|
Node* hovered_node() { return m_hovered_node; }
|
|
|
|
const Node* hovered_node() const { return m_hovered_node; }
|
|
|
|
|
2019-09-29 17:24:57 +03:00
|
|
|
const HTMLHtmlElement* document_element() const;
|
|
|
|
const HTMLHeadElement* head() const;
|
2019-10-04 22:05:52 +03:00
|
|
|
const HTMLBodyElement* body() const;
|
2019-09-29 17:24:57 +03:00
|
|
|
|
|
|
|
String title() const;
|
|
|
|
|
2019-10-04 16:50:04 +03:00
|
|
|
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(); }
|
|
|
|
|
2019-10-04 22:05:52 +03:00
|
|
|
Color background_color() const;
|
|
|
|
|
2019-10-06 11:11:54 +03:00
|
|
|
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);
|
|
|
|
|
2019-10-13 13:34:25 +03:00
|
|
|
void layout();
|
|
|
|
|
2019-10-14 18:56:19 +03:00
|
|
|
void update_style();
|
|
|
|
void update_layout();
|
|
|
|
Function<void()> on_layout_updated;
|
2019-10-06 14:58:18 +03:00
|
|
|
|
2019-10-13 00:26:47 +03:00
|
|
|
virtual bool is_child_allowed(const Node&) const override;
|
|
|
|
|
2019-10-13 13:34:25 +03:00
|
|
|
const LayoutDocument* layout_node() const;
|
|
|
|
|
2019-06-15 19:55:47 +03:00
|
|
|
private:
|
2019-10-07 10:23:53 +03:00
|
|
|
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
|
2019-10-05 23:27:52 +03:00
|
|
|
|
2019-06-29 22:42:07 +03:00
|
|
|
OwnPtr<StyleResolver> m_style_resolver;
|
|
|
|
NonnullRefPtrVector<StyleSheet> m_sheets;
|
2019-09-29 12:50:35 +03:00
|
|
|
RefPtr<Node> m_hovered_node;
|
2019-10-04 16:50:04 +03:00
|
|
|
WeakPtr<Frame> m_frame;
|
2019-10-05 11:16:27 +03:00
|
|
|
URL m_url;
|
2019-10-06 11:11:54 +03:00
|
|
|
|
2019-10-13 13:34:25 +03:00
|
|
|
RefPtr<LayoutDocument> m_layout_root;
|
|
|
|
|
2019-10-06 11:11:54 +03:00
|
|
|
Color m_link_color { Color::Blue };
|
|
|
|
Color m_active_link_color { Color::Red };
|
|
|
|
Color m_visited_link_color { Color::Magenta };
|
2019-06-15 19:55:47 +03:00
|
|
|
};
|
2019-10-06 21:37:39 +03:00
|
|
|
|
|
|
|
template<>
|
|
|
|
inline bool is<Document>(const Node& node)
|
|
|
|
{
|
|
|
|
return node.is_document();
|
|
|
|
}
|