Document.h 2.4 KB

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