Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / render_block_context.cpp
blob7591378c2fb50b9ef291dc576011401249f0c008
1 #include "html.h"
2 #include "render_block_context.h"
3 #include "document.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;
9 int ret_width = 0;
10 int child_top = 0;
11 int last_margin = 0;
12 std::shared_ptr<render_item> last_margin_el;
13 bool is_first = true;
14 for (const auto& el : m_children)
16 // we don't need to process absolute and fixed positioned element on the second pass
17 if (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);
26 if (rw > ret_width)
28 ret_width = rw;
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);
39 } else
41 child_top = fmt_ctx->get_cleared_top(el, child_top);
42 int child_x = 0;
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;
55 } else
57 if(last_margin > el->get_margins().top)
59 child_top -= el->get_margins().top;
60 } else
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)
68 int ln_left = 0;
69 int ln_right = child_width;
70 fmt_ctx->get_line_left_right(child_top, child_width, ln_left, ln_right);
71 child_x = ln_left;
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);
86 if(auto_margin)
88 el->pos().x += auto_margin;
90 if (rw > ret_width)
92 ret_width = rw;
94 child_top += el->height();
95 last_margin = el->get_margins().bottom;
96 last_margin_el = el;
97 is_first = false;
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;
111 } else
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;
121 if(last_margin_el)
123 last_margin_el->get_margins().bottom = 0;
128 return ret_width;