Initial commit of litehtml_viewer
[claws.git] / src / plugins / litehtml_viewer / litehtml / html_tag.h
1 #pragma once\r
2 \r
3 #include "element.h"\r
4 #include "style.h"\r
5 #include "background.h"\r
6 #include "css_margins.h"\r
7 #include "borders.h"\r
8 #include "css_selector.h"\r
9 #include "stylesheet.h"\r
10 #include "box.h"\r
11 #include "table.h"\r
12 \r
13 namespace litehtml\r
14 {\r
15         struct line_context\r
16         {\r
17                 int calculatedTop;\r
18                 int top;\r
19                 int left;\r
20                 int right;\r
21 \r
22                 int width()\r
23                 {\r
24                         return right - left;\r
25                 }\r
26                 void fix_top()\r
27                 {\r
28                         calculatedTop = top;\r
29                 }\r
30         };\r
31 \r
32         class html_tag : public element\r
33         {\r
34                 friend class elements_iterator;\r
35                 friend class el_table;\r
36                 friend class table_grid;\r
37                 friend class block_box;\r
38                 friend class line_box;\r
39         public:\r
40                 typedef std::shared_ptr<litehtml::html_tag>     ptr;\r
41         protected:\r
42                 box::vector                             m_boxes;\r
43                 string_vector                   m_class_values;\r
44                 tstring                                 m_tag;\r
45                 litehtml::style                 m_style;\r
46                 string_map                              m_attrs;\r
47                 vertical_align                  m_vertical_align;\r
48                 text_align                              m_text_align;\r
49                 style_display                   m_display;\r
50                 list_style_type                 m_list_style_type;\r
51                 list_style_position             m_list_style_position;\r
52                 white_space                             m_white_space;\r
53                 element_float                   m_float;\r
54                 element_clear                   m_clear;\r
55                 floated_box::vector             m_floats_left;\r
56                 floated_box::vector             m_floats_right;\r
57                 elements_vector                 m_positioned;\r
58                 background                              m_bg;\r
59                 element_position                m_el_position;\r
60                 int                                             m_line_height;\r
61                 bool                                    m_lh_predefined;\r
62                 string_vector                   m_pseudo_classes;\r
63                 used_selector::vector   m_used_styles;          \r
64                 \r
65                 uint_ptr                                m_font;\r
66                 int                                             m_font_size;\r
67                 font_metrics                    m_font_metrics;\r
68 \r
69                 css_margins                             m_css_margins;\r
70                 css_margins                             m_css_padding;\r
71                 css_borders                             m_css_borders;\r
72                 css_length                              m_css_width;\r
73                 css_length                              m_css_height;\r
74                 css_length                              m_css_min_width;\r
75                 css_length                              m_css_min_height;\r
76                 css_length                              m_css_max_width;\r
77                 css_length                              m_css_max_height;\r
78                 css_offsets                             m_css_offsets;\r
79                 css_length                              m_css_text_indent;\r
80 \r
81                 overflow                                m_overflow;\r
82                 visibility                              m_visibility;\r
83                 int                                             m_z_index;\r
84                 box_sizing                              m_box_sizing;\r
85 \r
86                 int_int_cache                   m_cahe_line_left;\r
87                 int_int_cache                   m_cahe_line_right;\r
88 \r
89                 // data for table rendering\r
90                 std::unique_ptr<table_grid>     m_grid;\r
91                 css_length                              m_css_border_spacing_x;\r
92                 css_length                              m_css_border_spacing_y;\r
93                 int                                             m_border_spacing_x;\r
94                 int                                             m_border_spacing_y;\r
95                 border_collapse                 m_border_collapse;\r
96 \r
97                 virtual void                    select_all(const css_selector& selector, elements_vector& res);\r
98 \r
99         public:\r
100                 html_tag(const std::shared_ptr<litehtml::document>& doc);\r
101                 virtual ~html_tag();\r
102 \r
103                 /* render functions */\r
104 \r
105                 virtual int                                     render(int x, int y, int max_width, bool second_pass = false) override;\r
106 \r
107                 virtual int                                     render_inline(const element::ptr &container, int max_width) override;\r
108                 virtual int                                     place_element(const element::ptr &el, int max_width) override;\r
109                 virtual bool                            fetch_positioned() override;\r
110                 virtual void                            render_positioned(render_type rt = render_all) override;\r
111 \r
112                 int                                                     new_box(const element::ptr &el, int max_width, line_context& line_ctx);\r
113 \r
114                 int                                                     get_cleared_top(const element::ptr &el, int line_top) const;\r
115                 int                                                     finish_last_box(bool end_of_render = false);\r
116 \r
117                 virtual bool                            appendChild(const element::ptr &el) override;\r
118                 virtual bool                            removeChild(const element::ptr &el) override;\r
119                 virtual void                            clearRecursive() override;\r
120                 virtual const tchar_t*          get_tagName() const override;\r
121                 virtual void                            set_tagName(const tchar_t* tag) override;\r
122                 virtual void                            set_data(const tchar_t* data) override;\r
123                 virtual element_float           get_float() const override;\r
124                 virtual vertical_align          get_vertical_align() const override;\r
125                 virtual css_length                      get_css_left() const override;\r
126                 virtual css_length                      get_css_right() const override;\r
127                 virtual css_length                      get_css_top() const override;\r
128                 virtual css_length                      get_css_bottom() const override;\r
129                 virtual css_length                      get_css_width() const override;\r
130                 virtual css_offsets                     get_css_offsets() const override;\r
131                 virtual void                            set_css_width(css_length& w) override;\r
132                 virtual css_length                      get_css_height() const override;\r
133                 virtual element_clear           get_clear() const override;\r
134                 virtual size_t                          get_children_count() const override;\r
135                 virtual element::ptr            get_child(int idx) const override;\r
136                 virtual element_position        get_element_position(css_offsets* offsets = 0) const override;\r
137                 virtual overflow                        get_overflow() const override;\r
138 \r
139                 virtual void                            set_attr(const tchar_t* name, const tchar_t* val) override;\r
140                 virtual const tchar_t*          get_attr(const tchar_t* name, const tchar_t* def = 0) override;\r
141                 virtual void                            apply_stylesheet(const litehtml::css& stylesheet) override;\r
142                 virtual void                            refresh_styles() override;\r
143 \r
144                 virtual bool                            is_white_space() const override;\r
145                 virtual bool                            is_body() const override;\r
146                 virtual bool                            is_break() const override;\r
147                 virtual int                                     get_base_line() override;\r
148                 virtual bool                            on_mouse_over() override;\r
149                 virtual bool                            on_mouse_leave() override;\r
150                 virtual bool                            on_lbutton_down() override;\r
151                 virtual bool                            on_lbutton_up() override;\r
152                 virtual void                            on_click() override;\r
153                 virtual bool                            find_styles_changes(position::vector& redraw_boxes, int x, int y) override;\r
154                 virtual const tchar_t*          get_cursor() override;\r
155                 virtual void                            init_font() override;\r
156                 virtual bool                            set_pseudo_class(const tchar_t* pclass, bool add) override;\r
157                 virtual bool                            set_class(const tchar_t* pclass, bool add) override;\r
158                 virtual bool                            is_replaced() const override;\r
159                 virtual int                                     line_height() const override;\r
160                 virtual white_space                     get_white_space() const override;\r
161                 virtual style_display           get_display() const override;\r
162                 virtual visibility                      get_visibility() const override;\r
163                 virtual void                            parse_styles(bool is_reparse = false) override;\r
164                 virtual void                            draw(uint_ptr hdc, int x, int y, const position* clip) override;\r
165                 virtual void                            draw_background(uint_ptr hdc, int x, int y, const position* clip) override;\r
166 \r
167                 virtual const tchar_t*          get_style_property(const tchar_t* name, bool inherited, const tchar_t* def = 0) override;\r
168                 virtual uint_ptr                        get_font(font_metrics* fm = 0) override;\r
169                 virtual int                                     get_font_size() const override;\r
170 \r
171                 elements_vector&                        children();\r
172                 virtual void                            calc_outlines(int parent_width) override;\r
173                 virtual void                            calc_auto_margins(int parent_width) override;\r
174 \r
175                 virtual int                                     select(const css_selector& selector, bool apply_pseudo = true) override;\r
176                 virtual int                                     select(const css_element_selector& selector, bool apply_pseudo = true) override;\r
177 \r
178                 virtual elements_vector         select_all(const tstring& selector) override;\r
179                 virtual elements_vector         select_all(const css_selector& selector) override;\r
180 \r
181                 virtual element::ptr            select_one(const tstring& selector) override;\r
182                 virtual element::ptr            select_one(const css_selector& selector) override;\r
183 \r
184                 virtual element::ptr            find_ancestor(const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = 0) override;\r
185                 virtual element::ptr            find_adjacent_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = 0) override;\r
186                 virtual element::ptr            find_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = 0) override;\r
187                 virtual void                            get_text(tstring& text) override;\r
188                 virtual void                            parse_attributes() override;\r
189 \r
190                 virtual bool                            is_first_child_inline(const element::ptr& el) const override;\r
191                 virtual bool                            is_last_child_inline(const element::ptr& el) override;\r
192                 virtual bool                            have_inline_child() const override;\r
193                 virtual void                            get_content_size(size& sz, int max_width) override;\r
194                 virtual void                            init() override;\r
195                 virtual void                            get_inline_boxes(position::vector& boxes) override;\r
196                 virtual bool                            is_floats_holder() const override;\r
197                 virtual int                                     get_floats_height(element_float el_float = float_none) const override;\r
198                 virtual int                                     get_left_floats_height() const override;\r
199                 virtual int                                     get_right_floats_height() const override;\r
200                 virtual int                                     get_line_left(int y) override;\r
201                 virtual int                                     get_line_right(int y, int def_right) override;\r
202                 virtual void                            get_line_left_right(int y, int def_right, int& ln_left, int& ln_right) override;\r
203                 virtual void                            add_float(const element::ptr &el, int x, int y) override;\r
204                 virtual void                            update_floats(int dy, const element::ptr &parent) override;\r
205                 virtual void                            add_positioned(const element::ptr &el) override;\r
206                 virtual int                                     find_next_line_top(int top, int width, int def_right) override;\r
207                 virtual void                            apply_vertical_align() override;\r
208                 virtual void                            draw_children(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex) override;\r
209                 virtual int                                     get_zindex() const override;\r
210                 virtual void                            draw_stacking_context(uint_ptr hdc, int x, int y, const position* clip, bool with_positioned) override;\r
211                 virtual void                            calc_document_size(litehtml::size& sz, int x = 0, int y = 0) override;\r
212                 virtual void                            get_redraw_box(litehtml::position& pos, int x = 0, int y = 0) override;\r
213                 virtual void                            add_style(const litehtml::style& st) override;\r
214                 virtual element::ptr            get_element_by_point(int x, int y, int client_x, int client_y) override;\r
215                 virtual element::ptr            get_child_by_point(int x, int y, int client_x, int client_y, draw_flag flag, int zindex) override;\r
216 \r
217                 virtual bool                            is_nth_child(const element::ptr& el, int num, int off, bool of_type) const override;\r
218                 virtual bool                            is_nth_last_child(const element::ptr& el, int num, int off, bool of_type) const override;\r
219                 virtual bool                            is_only_child(const element::ptr& el, bool of_type) const override;\r
220                 virtual const background*       get_background(bool own_only = false) override;\r
221 \r
222         protected:\r
223                 void                                            draw_children_box(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex);\r
224                 void                                            draw_children_table(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex);\r
225                 int                                                     render_box(int x, int y, int max_width, bool second_pass = false);\r
226                 int                                                     render_table(int x, int y, int max_width, bool second_pass = false);\r
227                 int                                                     fix_line_width(int max_width, element_float flt);\r
228                 void                                            parse_background();\r
229                 void                                            init_background_paint( position pos, background_paint &bg_paint, const background* bg );\r
230                 void                                            draw_list_marker( uint_ptr hdc, const position &pos );\r
231                 void                                            parse_nth_child_params( tstring param, int &num, int &off );\r
232                 void                                            remove_before_after();\r
233                 litehtml::element::ptr          get_element_before();\r
234                 litehtml::element::ptr          get_element_after();\r
235         };\r
236 \r
237         /************************************************************************/\r
238         /*                        Inline Functions                              */\r
239         /************************************************************************/\r
240 \r
241         inline elements_vector& litehtml::html_tag::children()\r
242         {\r
243                 return m_children;\r
244         }\r
245 }\r
246 \r