1 | #ifndef LH_DOCUMENT_H |
2 | #define LH_DOCUMENT_H |
3 | |
4 | #include "style.h" |
5 | #include "types.h" |
6 | #include "context.h" |
7 | |
8 | namespace litehtml |
9 | { |
10 | struct css_text |
11 | { |
12 | typedef std::vector<css_text> vector; |
13 | |
14 | tstring text; |
15 | tstring baseurl; |
16 | tstring media; |
17 | |
18 | css_text() = default; |
19 | |
20 | css_text(const tchar_t* txt, const tchar_t* url, const tchar_t* media_str) |
21 | { |
22 | text = txt ? txt : _t("" ); |
23 | baseurl = url ? url : _t("" ); |
24 | media = media_str ? media_str : _t("" ); |
25 | } |
26 | |
27 | css_text(const css_text& val) |
28 | { |
29 | text = val.text; |
30 | baseurl = val.baseurl; |
31 | media = val.media; |
32 | } |
33 | }; |
34 | |
35 | class html_tag; |
36 | |
37 | class document : public std::enable_shared_from_this<document> |
38 | { |
39 | public: |
40 | typedef std::shared_ptr<document> ptr; |
41 | typedef std::weak_ptr<document> weak_ptr; |
42 | private: |
43 | std::shared_ptr<element> m_root; |
44 | document_container* m_container; |
45 | fonts_map m_fonts; |
46 | css_text::vector m_css; |
47 | litehtml::css m_styles; |
48 | litehtml::web_color m_def_color; |
49 | litehtml::context* m_context; |
50 | litehtml::size m_size; |
51 | position::vector m_fixed_boxes; |
52 | media_query_list::vector m_media_lists; |
53 | element::ptr m_over_element; |
54 | elements_vector m_tabular_elements; |
55 | media_features m_media; |
56 | tstring m_lang; |
57 | tstring m_culture; |
58 | public: |
59 | document(litehtml::document_container* objContainer, litehtml::context* ctx); |
60 | virtual ~document(); |
61 | |
62 | litehtml::document_container* container() { return m_container; } |
63 | uint_ptr get_font(const tchar_t* name, int size, const tchar_t* weight, const tchar_t* style, const tchar_t* decoration, font_metrics* fm); |
64 | int render(int max_width, render_type rt = render_all); |
65 | void draw(uint_ptr hdc, int x, int y, const position* clip); |
66 | web_color get_def_color() { return m_def_color; } |
67 | int cvt_units(const tchar_t* str, int fontSize, bool* is_percent = nullptr) const; |
68 | int cvt_units(css_length& val, int fontSize, int size = 0) const; |
69 | int width() const; |
70 | int height() const; |
71 | void add_stylesheet(const tchar_t* str, const tchar_t* baseurl, const tchar_t* media); |
72 | bool on_mouse_over(int x, int y, int client_x, int client_y, position::vector& redraw_boxes); |
73 | bool on_lbutton_down(int x, int y, int client_x, int client_y, position::vector& redraw_boxes); |
74 | bool on_lbutton_up(int x, int y, int client_x, int client_y, position::vector& redraw_boxes); |
75 | bool on_mouse_leave(position::vector& redraw_boxes); |
76 | litehtml::element::ptr create_element(const tchar_t* tag_name, const string_map& attributes); |
77 | element::ptr root(); |
78 | void get_fixed_boxes(position::vector& fixed_boxes); |
79 | void add_fixed_box(const position& pos); |
80 | void add_media_list(const media_query_list::ptr& list); |
81 | bool media_changed(); |
82 | bool lang_changed(); |
83 | bool match_lang(const tstring & lang); |
84 | void add_tabular(const element::ptr& el); |
85 | element::const_ptr get_over_element() const { return m_over_element; } |
86 | |
87 | void append_children_from_string(element& parent, const tchar_t* str); |
88 | void append_children_from_utf8(element& parent, const char* str); |
89 | |
90 | static litehtml::document::ptr createFromString(const tchar_t* str, litehtml::document_container* objPainter, litehtml::context* ctx, litehtml::css* user_styles = nullptr); |
91 | static litehtml::document::ptr createFromUTF8(const char* str, litehtml::document_container* objPainter, litehtml::context* ctx, litehtml::css* user_styles = nullptr); |
92 | |
93 | private: |
94 | litehtml::uint_ptr add_font(const tchar_t* name, int size, const tchar_t* weight, const tchar_t* style, const tchar_t* decoration, font_metrics* fm); |
95 | |
96 | void create_node(void* gnode, elements_vector& elements, bool parseTextNode); |
97 | bool update_media_lists(const media_features& features); |
98 | void fix_tables_layout(); |
99 | void fix_table_children(element::ptr& el_ptr, style_display disp, const tchar_t* disp_str); |
100 | void fix_table_parent(element::ptr& el_ptr, style_display disp, const tchar_t* disp_str); |
101 | }; |
102 | |
103 | inline element::ptr document::root() |
104 | { |
105 | return m_root; |
106 | } |
107 | inline void document::add_tabular(const element::ptr& el) |
108 | { |
109 | m_tabular_elements.push_back(x: el); |
110 | } |
111 | inline bool document::match_lang(const tstring & lang) |
112 | { |
113 | return lang == m_lang || lang == m_culture; |
114 | } |
115 | } |
116 | |
117 | #endif // LH_DOCUMENT_H |
118 | |