Photon 1.0.0
Loading...
Searching...
No Matches
render_item.h
Go to the documentation of this file.
1#ifndef LH_RENDER_ITEM_H
2#define LH_RENDER_ITEM_H
3
4#include <memory>
5#include <utility>
6#include <list>
7#include <tuple>
8#include "types.h"
9#include "line_box.h"
10#include "table.h"
11#include "formatting_context.h"
12
13namespace litehtml
14{
15 class element;
16
17 class render_item : public std::enable_shared_from_this<render_item>
18 {
19 protected:
20 std::shared_ptr<element> m_element;
21 std::weak_ptr<render_item> m_parent;
22 std::list<std::shared_ptr<render_item>> m_children;
27 bool m_skip;
28 std::vector<std::shared_ptr<render_item>> m_positioned;
29
31 void calc_cb_length(const css_length& len, int percent_base, containing_block_context::typed_int& out_value) const;
32 virtual int _render(int /*x*/, int /*y*/, const containing_block_context& /*containing_block_size*/, formatting_context* /*fmt_ctx*/, bool /*second_pass = false*/)
33 {
34 return 0;
35 }
36
37 public:
38 explicit render_item(std::shared_ptr<element> src_el);
39
40 virtual ~render_item() = default;
41
42 std::list<std::shared_ptr<render_item>>& children()
43 {
44 return m_children;
45 }
46
48 {
49 return m_pos;
50 }
51
52 bool skip() const
53 {
54 return m_skip;
55 }
56
57 void skip(bool val)
58 {
59 m_skip = val;
60 }
61
62 int right() const
63 {
64 return left() + width();
65 }
66
67 int left() const
68 {
70 }
71
72 int top() const
73 {
75 }
76
77 int bottom() const
78 {
79 return top() + height();
80 }
81
82 int height() const
83 {
85 }
86
87 int width() const
88 {
90 }
91
92 int padding_top() const
93 {
94 return m_padding.top;
95 }
96
97 int padding_bottom() const
98 {
99 return m_padding.bottom;
100 }
101
102 int padding_left() const
103 {
104 return m_padding.left;
105 }
106
107 int padding_right() const
108 {
109 return m_padding.right;
110 }
111
112 int border_top() const
113 {
114 return m_borders.top;
115 }
116
117 int border_bottom() const
118 {
119 return m_borders.bottom;
120 }
121
122 int border_left() const
123 {
124 return m_borders.left;
125 }
126
127 int border_right() const
128 {
129 return m_borders.right;
130 }
131
132 int margin_top() const
133 {
134 return m_margins.top;
135 }
136
137 int margin_bottom() const
138 {
139 return m_margins.bottom;
140 }
141
142 int margin_left() const
143 {
144 return m_margins.left;
145 }
146
147 int margin_right() const
148 {
149 return m_margins.right;
150 }
151
152 std::shared_ptr<render_item> parent() const
153 {
154 return m_parent.lock();
155 }
156
158 {
159 return m_margins;
160 }
161
163 {
164 return m_padding;
165 }
166
167 void set_paddings(const margins& val)
168 {
169 m_padding = val;
170 }
171
173 {
174 return m_borders;
175 }
176
181 {
183 }
184
188 inline int content_offset_bottom() const
189 {
191 }
192
197 {
199 }
200
205 {
207 }
208
213 {
215 }
216
221 {
223 }
224
226 {
227 if(css().get_box_sizing() == box_sizing_content_box)
228 {
230 }
231 return m_margins.left;
232 }
233
235 {
236 if(css().get_box_sizing() == box_sizing_content_box)
237 {
239 }
240 return m_margins.right;
241 }
242
244 {
246 }
247
249 {
250 if(css().get_box_sizing() == box_sizing_content_box)
251 {
253 }
254 return m_margins.top;
255 }
256
258 {
259 if(css().get_box_sizing() == box_sizing_content_box)
260 {
262 }
263 return m_margins.bottom;
264 }
265
267 {
269 }
270
271 int box_sizing_left() const
272 {
273 if(css().get_box_sizing() == box_sizing_border_box)
274 {
275 return m_padding.left + m_borders.left;
276 }
277 return 0;
278 }
279
281 {
282 if(css().get_box_sizing() == box_sizing_border_box)
283 {
285 }
286 return 0;
287 }
288
290 {
292 }
293
294 int box_sizing_top() const
295 {
296 if(css().get_box_sizing() == box_sizing_border_box)
297 {
298 return m_padding.top + m_borders.top;
299 }
300 return 0;
301 }
302
304 {
305 if(css().get_box_sizing() == box_sizing_border_box)
306 {
308 }
309 return 0;
310 }
311
313 {
315 }
316
317 void parent(const std::shared_ptr<render_item>& par)
318 {
319 m_parent = par;
320 }
321
322 const std::shared_ptr<element>& src_el() const
323 {
324 return m_element;
325 }
326
327 const css_properties& css() const
328 {
329 return m_element->css();
330 }
331
332 void add_child(const std::shared_ptr<render_item>& ri)
333 {
334 m_children.push_back(ri);
335 ri->parent(shared_from_this());
336 }
337
338 bool is_root() const
339 {
340 return m_parent.expired();
341 }
342
344 {
345 return !m_borders.top &&
346 !m_padding.top &&
347 m_element->in_normal_flow() &&
348 m_element->css().get_float() == float_none &&
349 m_margins.top >= 0 &&
350 !is_flex_item() &&
351 !is_root();
352 }
353
355 {
356 return !m_borders.bottom &&
357 !m_padding.bottom &&
358 m_element->in_normal_flow() &&
359 m_element->css().get_float() == float_none &&
360 m_margins.bottom >= 0 &&
361 !is_root();
362 }
363
364 bool is_visible() const
365 {
366 return !(m_skip || src_el()->css().get_display() == display_none || src_el()->css().get_visibility() != visibility_visible);
367 }
368
369 bool is_flex_item() const
370 {
371 auto par = parent();
372 if(par && (par->css().get_display() == display_inline_flex || par->css().get_display() == display_flex))
373 {
374 return true;
375 }
376 return false;
377 }
378
379 int render(int x, int y, const containing_block_context& containing_block_size, formatting_context* fmt_ctx, bool second_pass = false);
380 void apply_relative_shift(const containing_block_context &containing_block_size);
381 void calc_outlines( int parent_width );
382 int calc_auto_margins(int parent_width); // returns left margin
383
384 virtual std::shared_ptr<render_item> init();
385 virtual void apply_vertical_align() {}
390 virtual int get_first_baseline() { return height() - margin_bottom(); }
395 virtual int get_last_baseline() { return height() - margin_bottom(); }
396
397 virtual std::shared_ptr<render_item> clone()
398 {
399 return std::make_shared<render_item>(src_el());
400 }
401 std::tuple<
402 std::shared_ptr<litehtml::render_item>,
403 std::shared_ptr<litehtml::render_item>,
404 std::shared_ptr<litehtml::render_item>
405 > split_inlines();
406 bool fetch_positioned();
408 // returns element offset related to the containing block
409 std::tuple<int, int> element_static_offset(const std::shared_ptr<litehtml::render_item> &el);
410 void add_positioned(const std::shared_ptr<litehtml::render_item> &el);
411 void get_redraw_box(litehtml::position& pos, int x = 0, int y = 0);
412 void calc_document_size( litehtml::size& sz, litehtml::size& content_size, int x = 0, int y = 0 );
413 virtual void get_inline_boxes( position::vector& /*boxes*/ ) const {};
414 virtual void set_inline_boxes( position::vector& /*boxes*/ ) {};
415 virtual void add_inline_box( const position& /*box*/ ) {};
416 virtual void clear_inline_boxes() {};
417 void draw_stacking_context( uint_ptr hdc, int x, int y, const position* clip, bool with_positioned );
418 virtual void draw_children( uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex );
419 virtual int get_draw_vertical_offset() { return 0; }
420 virtual std::shared_ptr<element> get_child_by_point(int x, int y, int client_x, int client_y, draw_flag flag, int zindex);
421 std::shared_ptr<element> get_element_by_point(int x, int y, int client_x, int client_y);
422 bool is_point_inside( int x, int y );
423 void dump(litehtml::dumper& cout);
424 position get_placement() const;
431 void get_rendering_boxes( position::vector& redraw_boxes);
432 };
433}
434
435#endif //LH_RENDER_ITEM_H
Definition css_length.h:22
Definition css_properties.h:17
Definition document.h:31
Definition formatting_context.h:10
Definition render_item.h:18
virtual std::shared_ptr< render_item > init()
Definition render_item.cpp:1186
void draw_stacking_context(uint_ptr hdc, int x, int y, const position *clip, bool with_positioned)
Definition render_item.cpp:754
int render_offset_bottom() const
Definition render_item.h:257
int box_sizing_left() const
Definition render_item.h:271
const css_properties & css() const
Definition render_item.h:327
position get_placement() const
Definition render_item.cpp:1173
bool is_point_inside(int x, int y)
Definition render_item.cpp:1088
int box_sizing_top() const
Definition render_item.h:294
int box_sizing_width() const
Definition render_item.h:289
bool collapse_top_margin() const
Definition render_item.h:343
margins m_padding
Definition render_item.h:24
virtual void add_inline_box(const position &)
Definition render_item.h:415
containing_block_context calculate_containing_block_context(const containing_block_context &cb_context)
Definition render_item.cpp:1214
int render(int x, int y, const containing_block_context &containing_block_size, formatting_context *fmt_ctx, bool second_pass=false)
Definition render_item.cpp:30
int render_offset_top() const
Definition render_item.h:248
std::shared_ptr< render_item > parent() const
Definition render_item.h:152
std::list< std::shared_ptr< render_item > > m_children
Definition render_item.h:22
int width() const
Definition render_item.h:87
margins m_margins
Definition render_item.h:23
void add_positioned(const std::shared_ptr< litehtml::render_item > &el)
Definition render_item.cpp:669
int render_offset_right() const
Definition render_item.h:234
void apply_relative_shift(const containing_block_context &containing_block_size)
Definition render_item.cpp:117
int render_offset_width() const
Definition render_item.h:243
margins & get_paddings()
Definition render_item.h:162
std::vector< std::shared_ptr< render_item > > m_positioned
Definition render_item.h:28
int margin_left() const
Definition render_item.h:142
position & pos()
Definition render_item.h:47
int box_sizing_right() const
Definition render_item.h:280
int border_left() const
Definition render_item.h:122
int margin_right() const
Definition render_item.h:147
bool fetch_positioned()
Definition render_item.cpp:217
virtual int _render(int, int, const containing_block_context &, formatting_context *, bool)
Definition render_item.h:32
std::shared_ptr< element > m_element
Definition render_item.h:20
virtual std::shared_ptr< element > get_child_by_point(int x, int y, int client_x, int client_y, draw_flag flag, int zindex)
Definition render_item.cpp:907
int bottom() const
Definition render_item.h:77
int content_offset_width() const
Definition render_item.h:212
int padding_top() const
Definition render_item.h:92
int render_offset_height() const
Definition render_item.h:266
int content_offset_left() const
Definition render_item.h:196
margins m_borders
Definition render_item.h:25
void set_paddings(const margins &val)
Definition render_item.h:167
bool m_skip
Definition render_item.h:27
void parent(const std::shared_ptr< render_item > &par)
Definition render_item.h:317
std::list< std::shared_ptr< render_item > > & children()
Definition render_item.h:42
int border_right() const
Definition render_item.h:127
int render_offset_left() const
Definition render_item.h:225
virtual void apply_vertical_align()
Definition render_item.h:385
bool collapse_bottom_margin() const
Definition render_item.h:354
int margin_bottom() const
Definition render_item.h:137
int box_sizing_height() const
Definition render_item.h:312
void calc_document_size(litehtml::size &sz, litehtml::size &content_size, int x=0, int y=0)
Definition render_item.cpp:711
std::shared_ptr< element > get_element_by_point(int x, int y, int client_x, int client_y)
Definition render_item.cpp:1021
virtual void get_inline_boxes(position::vector &) const
Definition render_item.h:413
bool skip() const
Definition render_item.h:52
const std::shared_ptr< element > & src_el() const
Definition render_item.h:322
int top() const
Definition render_item.h:72
int box_sizing_bottom() const
Definition render_item.h:303
int height() const
Definition render_item.h:82
virtual int get_last_baseline()
Definition render_item.h:395
virtual ~render_item()=default
std::tuple< std::shared_ptr< litehtml::render_item >, std::shared_ptr< litehtml::render_item >, std::shared_ptr< litehtml::render_item > > split_inlines()
Definition render_item.cpp:145
position m_pos
Definition render_item.h:26
int padding_left() const
Definition render_item.h:102
void render_positioned(render_type width=render_all)
Definition render_item.cpp:244
void calc_cb_length(const css_length &len, int percent_base, containing_block_context::typed_int &out_value) const
Definition render_item.cpp:1198
int content_offset_bottom() const
Definition render_item.h:188
int padding_right() const
Definition render_item.h:107
bool is_root() const
Definition render_item.h:338
void dump(litehtml::dumper &cout)
Definition render_item.cpp:1145
int padding_bottom() const
Definition render_item.h:97
margins & get_borders()
Definition render_item.h:172
void get_rendering_boxes(position::vector &redraw_boxes)
Definition render_item.cpp:1117
virtual void set_inline_boxes(position::vector &)
Definition render_item.h:414
virtual void clear_inline_boxes()
Definition render_item.h:416
void get_redraw_box(litehtml::position &pos, int x=0, int y=0)
Definition render_item.cpp:684
virtual void draw_children(uint_ptr hdc, int x, int y, const position *clip, draw_flag flag, int zindex)
Definition render_item.cpp:797
margins & get_margins()
Definition render_item.h:157
void add_child(const std::shared_ptr< render_item > &ri)
Definition render_item.h:332
bool is_flex_item() const
Definition render_item.h:369
virtual std::shared_ptr< render_item > clone()
Definition render_item.h:397
int border_bottom() const
Definition render_item.h:117
std::weak_ptr< render_item > m_parent
Definition render_item.h:21
void calc_outlines(int parent_width)
Definition render_item.cpp:61
int border_top() const
Definition render_item.h:112
int calc_auto_margins(int parent_width)
Definition render_item.cpp:79
int margin_top() const
Definition render_item.h:132
int content_offset_right() const
Definition render_item.h:204
bool is_visible() const
Definition render_item.h:364
int left() const
Definition render_item.h:67
int content_offset_top() const
Definition render_item.h:180
virtual int get_first_baseline()
Definition render_item.h:390
virtual int get_draw_vertical_offset()
Definition render_item.h:419
int right() const
Definition render_item.h:62
int content_offset_height() const
Definition render_item.h:220
void skip(bool val)
Definition render_item.h:57
std::tuple< int, int > element_static_offset(const std::shared_ptr< litehtml::render_item > &el)
Definition render_item.cpp:1319
Definition background.h:12
@ box_sizing_content_box
Definition types.h:859
@ box_sizing_border_box
Definition types.h:860
std::uintptr_t uint_ptr
Definition types.h:17
@ float_none
Definition types.h:482
render_type
Definition types.h:904
@ render_all
Definition types.h:905
draw_flag
Definition types.h:228
@ visibility_visible
Definition types.h:625
@ display_none
Definition types.h:329
@ display_flex
Definition types.h:345
@ display_inline_flex
Definition types.h:346
Definition types.h:62
int bottom
Definition types.h:66
int height() const
Definition types.h:74
int left
Definition types.h:63
int right
Definition types.h:64
int top
Definition types.h:65
int width() const
Definition types.h:73
Definition types.h:103
int top() const
Definition types.h:127
std::vector< position > vector
Definition types.h:104
int left() const
Definition types.h:126
int height
Definition types.h:109
int width
Definition types.h:108
Definition types.h:89