2 #include "render_block_context.h"
5 int litehtml::render_item_block_context::_render_content(int x
, int y
, bool second_pass
, const containing_block_context
&self_size
, formatting_context
* fmt_ctx
)
7 element_position el_position
;
12 std::shared_ptr
<render_item
> last_margin_el
;
14 for (const auto& el
: m_children
)
16 // we don't need to process absolute and fixed positioned element on the second pass
19 el_position
= el
->src_el()->css().get_position();
20 if ((el_position
== element_position_absolute
|| el_position
== element_position_fixed
)) continue;
23 if(el
->src_el()->css().get_float() != float_none
)
25 int rw
= place_float(el
, child_top
, self_size
, fmt_ctx
);
30 } else if(el
->src_el()->css().get_display() != display_none
)
32 if(el
->src_el()->css().get_position() == element_position_absolute
|| el
->src_el()->css().get_position() == element_position_fixed
)
34 int min_rendered_width
= el
->render(0, child_top
, self_size
, fmt_ctx
);
35 if(min_rendered_width
< el
->width() && el
->src_el()->css().get_width().is_predefined())
37 el
->render(0, child_top
, self_size
.new_width(min_rendered_width
), fmt_ctx
);
41 child_top
= fmt_ctx
->get_cleared_top(el
, child_top
);
43 int child_width
= self_size
.render_width
;
45 el
->calc_outlines(self_size
.width
);
47 // Collapse top margin
48 if(is_first
&& collapse_top_margin())
50 child_top
-= el
->get_margins().top
;
51 if(el
->get_margins().top
> get_margins().top
)
53 m_margins
.top
= el
->get_margins().top
;
57 if(last_margin
> el
->get_margins().top
)
59 child_top
-= el
->get_margins().top
;
62 child_top
-= last_margin
;
66 if(el
->src_el()->is_replaced() || el
->src_el()->is_block_formatting_context() || el
->src_el()->css().get_display() == display_table
)
69 int ln_right
= child_width
;
70 fmt_ctx
->get_line_left_right(child_top
, child_width
, ln_left
, ln_right
);
72 child_width
= ln_right
- ln_left
;
74 auto el_parent
= el
->parent();
75 el
->pos().width
= el
->src_el()->css().get_width().calc_percent(child_width
);
76 el
->pos().height
= el
->src_el()->css().get_height().calc_percent(el_parent
? el_parent
->pos().height
: 0);
79 int rw
= el
->render(child_x
, child_top
, self_size
.new_width(child_width
), fmt_ctx
);
80 // Render table with "width: auto" into returned width
81 if(el
->src_el()->css().get_display() == display_table
&& rw
< child_width
&& el
->src_el()->css().get_width().is_predefined())
83 el
->render(child_x
, child_top
, self_size
.new_width(rw
), fmt_ctx
);
85 int auto_margin
= el
->calc_auto_margins(child_width
);
88 el
->pos().x
+= auto_margin
;
94 child_top
+= el
->height();
95 last_margin
= el
->get_margins().bottom
;
99 if (el
->src_el()->css().get_position() == element_position_relative
)
101 el
->apply_relative_shift(self_size
);
107 int block_height
= 0;
108 if (get_predefined_height(block_height
, self_size
.height
))
110 m_pos
.height
= block_height
;
113 m_pos
.height
= child_top
;
114 if(collapse_bottom_margin())
116 m_pos
.height
-= last_margin
;
117 if(m_margins
.bottom
< last_margin
)
119 m_margins
.bottom
= last_margin
;
123 last_margin_el
->get_margins().bottom
= 0;