Document.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #include <AK/Function.h>
  3. #include <AK/NonnullRefPtrVector.h>
  4. #include <AK/OwnPtr.h>
  5. #include <AK/String.h>
  6. #include <AK/URL.h>
  7. #include <AK/WeakPtr.h>
  8. #include <LibHTML/CSS/StyleResolver.h>
  9. #include <LibHTML/CSS/StyleSheet.h>
  10. #include <LibHTML/DOM/ParentNode.h>
  11. class CTimer;
  12. class Frame;
  13. class HTMLBodyElement;
  14. class HTMLHtmlElement;
  15. class HTMLHeadElement;
  16. class LayoutDocument;
  17. class LayoutNode;
  18. class StyleResolver;
  19. class StyleSheet;
  20. class Document : public ParentNode {
  21. public:
  22. Document();
  23. virtual ~Document() override;
  24. void set_url(const URL& url) { m_url = url; }
  25. const URL& url() const { return m_url; }
  26. URL complete_url(const String&) const;
  27. void fixup();
  28. StyleResolver& style_resolver() { return *m_style_resolver; }
  29. const StyleResolver& style_resolver() const { return *m_style_resolver; }
  30. void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); }
  31. const NonnullRefPtrVector<StyleSheet>& stylesheets() const { return m_sheets; }
  32. virtual String tag_name() const override { return "#document"; }
  33. void set_hovered_node(Node*);
  34. Node* hovered_node() { return m_hovered_node; }
  35. const Node* hovered_node() const { return m_hovered_node; }
  36. const HTMLHtmlElement* document_element() const;
  37. const HTMLHeadElement* head() const;
  38. const HTMLBodyElement* body() const;
  39. String title() const;
  40. void attach_to_frame(Badge<Frame>, Frame&);
  41. void detach_from_frame(Badge<Frame>, Frame&);
  42. Frame* frame() { return m_frame.ptr(); }
  43. const Frame* frame() const { return m_frame.ptr(); }
  44. Color background_color() const;
  45. RefPtr<GraphicsBitmap> background_image() const;
  46. Color link_color() const { return m_link_color; }
  47. void set_link_color(Color);
  48. Color active_link_color() const { return m_active_link_color; }
  49. void set_active_link_color(Color);
  50. Color visited_link_color() const { return m_visited_link_color; }
  51. void set_visited_link_color(Color);
  52. void layout();
  53. void update_style();
  54. void update_layout();
  55. Function<void()> on_layout_updated;
  56. virtual bool is_child_allowed(const Node&) const override;
  57. const LayoutDocument* layout_node() const;
  58. void schedule_style_update();
  59. private:
  60. virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
  61. OwnPtr<StyleResolver> m_style_resolver;
  62. NonnullRefPtrVector<StyleSheet> m_sheets;
  63. RefPtr<Node> m_hovered_node;
  64. WeakPtr<Frame> m_frame;
  65. URL m_url;
  66. RefPtr<LayoutDocument> m_layout_root;
  67. Color m_link_color { Color::Blue };
  68. Color m_active_link_color { Color::Red };
  69. Color m_visited_link_color { Color::Magenta };
  70. RefPtr<CTimer> m_style_update_timer;
  71. };
  72. template<>
  73. inline bool is<Document>(const Node& node)
  74. {
  75. return node.is_document();
  76. }