@@ -26,7 +26,8 @@ namespace litehtml
26
26
bool m_skip;
27
27
std::vector<std::shared_ptr<render_item>> m_positioned;
28
28
29
- virtual int _render (int x, int y, int max_width, bool second_pass) { return 0 ; }
29
+ containing_block_context calculate_containing_block_context (const containing_block_context& cb_context);
30
+ void calc_cb_length (const css_length& len, int percent_base, containing_block_context::typed_int& out_value) const ;
30
31
31
32
public:
32
33
explicit render_item (std::shared_ptr<element> src_el);
@@ -216,6 +217,36 @@ namespace litehtml
216
217
return content_offset_top () + content_offset_bottom ();
217
218
}
218
219
220
+ int box_sizing_left () const
221
+ {
222
+ return m_padding.left + m_borders.left ;
223
+ }
224
+
225
+ int box_sizing_right () const
226
+ {
227
+ return m_padding.right + m_borders.right ;
228
+ }
229
+
230
+ int box_sizing_width () const
231
+ {
232
+ return box_sizing_left () + box_sizing_left ();
233
+ }
234
+
235
+ int box_sizing_top () const
236
+ {
237
+ return m_padding.top + m_borders.top ;
238
+ }
239
+
240
+ int box_sizing_bottom () const
241
+ {
242
+ return m_padding.bottom + m_borders.bottom ;
243
+ }
244
+
245
+ int box_sizing_height () const
246
+ {
247
+ return box_sizing_top () + box_sizing_bottom ();
248
+ }
249
+
219
250
void parent (const std::shared_ptr<render_item>& par)
220
251
{
221
252
m_parent = par;
@@ -237,15 +268,15 @@ namespace litehtml
237
268
ri->parent (shared_from_this ());
238
269
}
239
270
240
- int render (int x, int y, int max_width )
241
- {
242
- return _render (x, y, max_width, false ) ;
243
- }
271
+ virtual int render (int x, int y, const containing_block_context& containing_block_size, bool second_pass = false )
272
+ {
273
+ return 0 ;
274
+ }
244
275
245
- bool have_parent () const
246
- {
247
- return ! m_parent.expired ();
248
- }
276
+ bool is_root () const
277
+ {
278
+ return m_parent.expired ();
279
+ }
249
280
250
281
bool collapse_top_margin () const
251
282
{
@@ -254,7 +285,7 @@ namespace litehtml
254
285
m_element->in_normal_flow () &&
255
286
m_element->css ().get_float () == float_none &&
256
287
m_margins.top >= 0 &&
257
- have_parent ();
288
+ ! is_root ();
258
289
}
259
290
260
291
bool collapse_bottom_margin () const
@@ -264,19 +295,19 @@ namespace litehtml
264
295
m_element->in_normal_flow () &&
265
296
m_element->css ().get_float () == float_none &&
266
297
m_margins.bottom >= 0 &&
267
- have_parent ();
298
+ ! is_root ();
268
299
}
269
300
270
301
bool is_visible () const
271
302
{
272
303
return !(m_skip || src_el ()->css ().get_display () == display_none || src_el ()->css ().get_visibility () != visibility_visible);
273
304
}
274
305
275
- int calc_width (int defVal) const ;
276
- bool get_predefined_height (int & p_height) const ;
277
- void apply_relative_shift (int parent_width );
306
+ int calc_width (int defVal, int containing_block_width ) const ;
307
+ bool get_predefined_height (int & p_height, int containing_block_height ) const ;
308
+ void apply_relative_shift (const containing_block_context &containing_block_size );
278
309
void calc_outlines ( int parent_width );
279
- void calc_auto_margins (int parent_width);
310
+ int calc_auto_margins (int parent_width); // returns left margin
280
311
281
312
virtual std::shared_ptr<render_item> init ();
282
313
virtual void apply_vertical_align () {}
@@ -294,7 +325,7 @@ namespace litehtml
294
325
void render_positioned (render_type rt = render_all);
295
326
void add_positioned (const std::shared_ptr<litehtml::render_item> &el);
296
327
void get_redraw_box (litehtml::position& pos, int x = 0 , int y = 0 );
297
- void calc_document_size ( litehtml::size& sz, int x = 0 , int y = 0 );
328
+ void calc_document_size ( litehtml::size& sz, litehtml::size& content_size, int x = 0 , int y = 0 );
298
329
virtual void get_inline_boxes ( position::vector& boxes ) const {};
299
330
virtual void set_inline_boxes ( position::vector& boxes ) {};
300
331
virtual void add_inline_box ( const position& box ) {};
@@ -334,21 +365,20 @@ namespace litehtml
334
365
int_int_cache m_cache_line_left;
335
366
int_int_cache m_cache_line_right;
336
367
337
- int _render (int x, int y, int max_width, bool second_pass) override ;
338
-
339
368
/* *
340
369
* Render block content.
341
370
*
342
371
* @param x - horizontal position of the content
343
372
* @param y - vertical position of the content
344
- * @param max_width - maximal width of the content
345
373
* @param second_pass - true is this is the second pass.
346
374
* @param ret_width - input minimal width.
375
+ * @param self_size - defines calculated size of block
347
376
* @return return value is the minimal width of the content in block. Must be greater or equal to ret_width parameter
348
377
*/
349
- virtual int _render_content (int x, int y, int max_width, bool second_pass, int ret_width) {return ret_width;}
378
+ virtual int _render_content (int x, int y, bool second_pass, int ret_width, const containing_block_context &self_size) {return ret_width;}
379
+ int render (int x, int y, const containing_block_context &containing_block_size, bool second_pass) override ;
350
380
351
- int place_float (const std::shared_ptr<render_item> &el, int top, int max_width );
381
+ int place_float (const std::shared_ptr<render_item> &el, int top, const containing_block_context &containing_block_size );
352
382
int get_floats_height (element_float el_float = float_none) const override ;
353
383
int get_left_floats_height () const override ;
354
384
int get_right_floats_height () const override ;
@@ -358,7 +388,9 @@ namespace litehtml
358
388
void add_float (const std::shared_ptr<render_item> &el, int x, int y) override ;
359
389
int get_cleared_top (const std::shared_ptr<render_item> &el, int line_top) const ;
360
390
int find_next_line_top ( int top, int width, int def_right ) override ;
361
- virtual void fix_line_width ( int max_width, element_float flt ) {}
391
+ virtual void fix_line_width (element_float flt,
392
+ const containing_block_context &containing_block_size)
393
+ {}
362
394
void update_floats (int dy, const std::shared_ptr<render_item> &_parent) override ;
363
395
public:
364
396
explicit render_item_block (std::shared_ptr<element> src_el) : render_item(std::move(src_el))
@@ -379,7 +411,8 @@ namespace litehtml
379
411
class render_item_block_context : public render_item_block
380
412
{
381
413
protected:
382
- int _render_content (int x, int y, int max_width, bool second_pass, int ret_width) override ;
414
+ int _render_content (int x, int y, bool second_pass, int ret_width,
415
+ const containing_block_context &self_size) override ;
383
416
384
417
public:
385
418
explicit render_item_block_context (std::shared_ptr<element> src_el) : render_item_block(std::move(src_el))
@@ -417,12 +450,14 @@ namespace litehtml
417
450
std::vector<std::unique_ptr<litehtml::line_box> > m_line_boxes;
418
451
int m_max_line_width;
419
452
420
- int _render_content (int x, int y, int max_width, bool second_pass, int ret_width) override ;
421
- void fix_line_width ( int max_width, element_float flt ) override ;
453
+ int _render_content (int x, int y, bool second_pass, int ret_width,
454
+ const containing_block_context &self_size) override ;
455
+ void fix_line_width (element_float flt,
456
+ const containing_block_context &self_size) override ;
422
457
423
- std::list<std::unique_ptr<line_box_item> > finish_last_box (bool end_of_render, int max_width );
424
- void place_inline (std::unique_ptr<line_box_item> item, int max_width );
425
- int new_box (const std::unique_ptr<line_box_item>& el, int max_width, line_context& line_ctx);
458
+ std::list<std::unique_ptr<line_box_item> > finish_last_box (bool end_of_render, const containing_block_context &self_size );
459
+ void place_inline (std::unique_ptr<line_box_item> item, const containing_block_context &self_size );
460
+ int new_box (const std::unique_ptr<line_box_item>& el, line_context& line_ctx, const containing_block_context &self_size );
426
461
void apply_vertical_align () override ;
427
462
public:
428
463
explicit render_item_inline_context (std::shared_ptr<element> src_el) : render_item_block(std::move(src_el)), m_max_line_width(0 )
@@ -444,15 +479,14 @@ namespace litehtml
444
479
int m_border_spacing_x;
445
480
int m_border_spacing_y;
446
481
447
- int _render (int x, int y, int max_width, bool second_pass) override ;
448
-
449
482
public:
450
483
explicit render_item_table (std::shared_ptr<element> src_el);
451
484
452
485
std::shared_ptr<render_item> clone () override
453
486
{
454
487
return std::make_shared<render_item_table>(src_el ());
455
488
}
489
+ int render (int x, int y, const containing_block_context &containing_block_size, bool second_pass) override ;
456
490
void draw_children (uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex) override ;
457
491
int get_draw_vertical_offset () override ;
458
492
std::shared_ptr<render_item> init () override ;
@@ -464,8 +498,6 @@ namespace litehtml
464
498
explicit render_item_table_part (std::shared_ptr<element> src_el) : render_item(std::move(src_el))
465
499
{}
466
500
467
- int _render (int x, int y, int max_width, bool second_pass) override
468
- {return 0 ;}
469
501
std::shared_ptr<render_item> clone () override
470
502
{
471
503
return std::make_shared<render_item_table_part>(src_el ());
@@ -478,8 +510,6 @@ namespace litehtml
478
510
explicit render_item_table_row (std::shared_ptr<element> src_el) : render_item(std::move(src_el))
479
511
{}
480
512
481
- int _render (int x, int y, int max_width, bool second_pass) override
482
- {return 0 ;}
483
513
std::shared_ptr<render_item> clone () override
484
514
{
485
515
return std::make_shared<render_item_table_row>(src_el ());
@@ -492,7 +522,6 @@ namespace litehtml
492
522
protected:
493
523
position::vector m_boxes;
494
524
495
- int _render (int x, int y, int max_width, bool second_pass) override ;
496
525
public:
497
526
explicit render_item_inline (std::shared_ptr<element> src_el) : render_item(std::move(src_el))
498
527
{}
@@ -512,13 +541,13 @@ namespace litehtml
512
541
class render_item_image : public render_item
513
542
{
514
543
protected:
515
- int _render (int x, int y, int max_width, bool second_pass) override ;
516
- int calc_max_height (int image_height);
544
+ int calc_max_height (int image_height, int containing_block_height);
517
545
518
546
public:
519
547
explicit render_item_image (std::shared_ptr<element> src_el) : render_item(std::move(src_el))
520
548
{}
521
549
550
+ int render (int x, int y, const containing_block_context &containing_block_size, bool second_pass) override ;
522
551
std::shared_ptr<render_item> clone () override
523
552
{
524
553
return std::make_shared<render_item_image>(src_el ());
@@ -548,7 +577,8 @@ namespace litehtml
548
577
protected:
549
578
std::list<std::unique_ptr<flex_item>> m_flex_items;
550
579
551
- int _render_content (int x, int y, int max_width, bool second_pass, int ret_width) override ;
580
+ int _render_content (int x, int y, bool second_pass, int ret_width,
581
+ const containing_block_context &self_size) override ;
552
582
553
583
public:
554
584
explicit render_item_flex (std::shared_ptr<element> src_el) : render_item_block(std::move(src_el))
0 commit comments