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 if(el
->get_margins().top
> 0)
52 child_top
-= el
->get_margins().top
;
53 if (el
->get_margins().top
> get_margins().top
)
55 m_margins
.top
= el
->get_margins().top
;
60 if(el
->get_margins().top
> 0)
62 if (last_margin
> el
->get_margins().top
)
64 child_top
-= el
->get_margins().top
;
67 child_top
-= last_margin
;
72 if(el
->src_el()->is_replaced() || el
->src_el()->is_block_formatting_context() || el
->src_el()->css().get_display() == display_table
)
75 int ln_right
= child_width
;
76 fmt_ctx
->get_line_left_right(child_top
, child_width
, ln_left
, ln_right
);
78 child_width
= ln_right
- ln_left
;
80 auto el_parent
= el
->parent();
81 el
->pos().width
= el
->src_el()->css().get_width().calc_percent(child_width
);
82 el
->pos().height
= el
->src_el()->css().get_height().calc_percent(el_parent
? el_parent
->pos().height
: 0);
85 int rw
= el
->render(child_x
, child_top
, self_size
.new_width(child_width
), fmt_ctx
);
86 // Render table with "width: auto" into returned width
87 if(el
->src_el()->css().get_display() == display_table
&& rw
< child_width
&& el
->src_el()->css().get_width().is_predefined())
89 el
->render(child_x
, child_top
, self_size
.new_width(rw
), fmt_ctx
);
91 int auto_margin
= el
->calc_auto_margins(child_width
);
94 el
->pos().x
+= auto_margin
;
100 child_top
+= el
->height();
101 last_margin
= el
->get_margins().bottom
;
105 if (el
->src_el()->css().get_position() == element_position_relative
)
107 el
->apply_relative_shift(self_size
);
113 if (self_size
.height
.type
!= containing_block_context::cbc_value_type_auto
&& self_size
.height
> 0)
115 m_pos
.height
= self_size
.height
;
118 m_pos
.height
= child_top
;
119 if(collapse_bottom_margin())
121 m_pos
.height
-= last_margin
;
122 if(m_margins
.bottom
< last_margin
)
124 m_margins
.bottom
= last_margin
;
128 last_margin_el
->get_margins().bottom
= 0;
136 int litehtml::render_item_block_context::get_first_baseline()
138 if(m_children
.empty())
140 return height() - margin_bottom();
142 const auto &item
= m_children
.front();
143 return content_offset_top() + item
->top() + item
->get_first_baseline();
146 int litehtml::render_item_block_context::get_last_baseline()
148 if(m_children
.empty())
150 return height() - margin_bottom();
152 const auto &item
= m_children
.back();
153 return content_offset_top() + item
->top() + item
->get_last_baseline();