Document.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include <AK/NonnullRefPtrVector.h>
  3. #include <AK/OwnPtr.h>
  4. #include <AK/String.h>
  5. #include <AK/URL.h>
  6. #include <AK/WeakPtr.h>
  7. #include <LibHTML/CSS/StyleResolver.h>
  8. #include <LibHTML/CSS/StyleSheet.h>
  9. #include <LibHTML/DOM/ParentNode.h>
  10. class Frame;
  11. class HTMLBodyElement;
  12. class HTMLHtmlElement;
  13. class HTMLHeadElement;
  14. class LayoutNode;
  15. class StyleResolver;
  16. class StyleSheet;
  17. class Document : public ParentNode {
  18. public:
  19. Document();
  20. virtual ~Document() override;
  21. void set_url(const URL& url) { m_url = url; }
  22. const URL& url() const { return m_url; }
  23. URL complete_url(const String&) const;
  24. void normalize();
  25. StyleResolver& style_resolver();
  26. void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); }
  27. const NonnullRefPtrVector<StyleSheet>& stylesheets() const { return m_sheets; }
  28. virtual String tag_name() const override { return "#document"; }
  29. void set_hovered_node(Node* node) { m_hovered_node = node; }
  30. Node* hovered_node() { return m_hovered_node; }
  31. const Node* hovered_node() const { return m_hovered_node; }
  32. const HTMLHtmlElement* document_element() const;
  33. const HTMLHeadElement* head() const;
  34. const HTMLBodyElement* body() const;
  35. String title() const;
  36. void attach_to_frame(Badge<Frame>, Frame&);
  37. void detach_from_frame(Badge<Frame>, Frame&);
  38. Frame* frame() { return m_frame.ptr(); }
  39. const Frame* frame() const { return m_frame.ptr(); }
  40. Color background_color() const;
  41. Color link_color() const { return m_link_color; }
  42. void set_link_color(Color);
  43. Color active_link_color() const { return m_active_link_color; }
  44. void set_active_link_color(Color);
  45. Color visited_link_color() const { return m_visited_link_color; }
  46. void set_visited_link_color(Color);
  47. private:
  48. virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_properties) const override;
  49. OwnPtr<StyleResolver> m_style_resolver;
  50. NonnullRefPtrVector<StyleSheet> m_sheets;
  51. RefPtr<Node> m_hovered_node;
  52. WeakPtr<Frame> m_frame;
  53. URL m_url;
  54. Color m_link_color { Color::Blue };
  55. Color m_active_link_color { Color::Red };
  56. Color m_visited_link_color { Color::Magenta };
  57. };