Document.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Frame;
  12. class HTMLBodyElement;
  13. class HTMLHtmlElement;
  14. class HTMLHeadElement;
  15. class LayoutDocument;
  16. class LayoutNode;
  17. class StyleResolver;
  18. class StyleSheet;
  19. class Document : public ParentNode {
  20. public:
  21. Document();
  22. virtual ~Document() override;
  23. void set_url(const URL& url) { m_url = url; }
  24. const URL& url() const { return m_url; }
  25. URL complete_url(const String&) const;
  26. void fixup();
  27. StyleResolver& style_resolver();
  28. void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); }
  29. const NonnullRefPtrVector<StyleSheet>& stylesheets() const { return m_sheets; }
  30. virtual String tag_name() const override { return "#document"; }
  31. void set_hovered_node(Node* node) { m_hovered_node = node; }
  32. Node* hovered_node() { return m_hovered_node; }
  33. const Node* hovered_node() const { return m_hovered_node; }
  34. const HTMLHtmlElement* document_element() const;
  35. const HTMLHeadElement* head() const;
  36. const HTMLBodyElement* body() const;
  37. String title() const;
  38. void attach_to_frame(Badge<Frame>, Frame&);
  39. void detach_from_frame(Badge<Frame>, Frame&);
  40. Frame* frame() { return m_frame.ptr(); }
  41. const Frame* frame() const { return m_frame.ptr(); }
  42. Color background_color() const;
  43. Color link_color() const { return m_link_color; }
  44. void set_link_color(Color);
  45. Color active_link_color() const { return m_active_link_color; }
  46. void set_active_link_color(Color);
  47. Color visited_link_color() const { return m_visited_link_color; }
  48. void set_visited_link_color(Color);
  49. void layout();
  50. void invalidate_layout();
  51. Function<void()> on_invalidate_layout;
  52. virtual bool is_child_allowed(const Node&) const override;
  53. const LayoutDocument* layout_node() const;
  54. private:
  55. virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
  56. OwnPtr<StyleResolver> m_style_resolver;
  57. NonnullRefPtrVector<StyleSheet> m_sheets;
  58. RefPtr<Node> m_hovered_node;
  59. WeakPtr<Frame> m_frame;
  60. URL m_url;
  61. RefPtr<LayoutDocument> m_layout_root;
  62. Color m_link_color { Color::Blue };
  63. Color m_active_link_color { Color::Red };
  64. Color m_visited_link_color { Color::Magenta };
  65. };
  66. template<>
  67. inline bool is<Document>(const Node& node)
  68. {
  69. return node.is_document();
  70. }