add support for Ayatana indicator to Notification plugin
[claws.git] / src / plugins / litehtml_viewer / litehtml / render_block_context.cpp
blobbf6b09277c438ccce2cb5236c279f6af1ac44184
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 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;
58 } else
60 if(el->get_margins().top > 0)
62 if (last_margin > el->get_margins().top)
64 child_top -= el->get_margins().top;
65 } else
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)
74 int ln_left = 0;
75 int ln_right = child_width;
76 fmt_ctx->get_line_left_right(child_top, child_width, ln_left, ln_right);
77 child_x = ln_left;
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);
92 if(auto_margin)
94 el->pos().x += auto_margin;
96 if (rw > ret_width)
98 ret_width = rw;
100 child_top += el->height();
101 last_margin = el->get_margins().bottom;
102 last_margin_el = el;
103 is_first = false;
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;
116 } else
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;
126 if(last_margin_el)
128 last_margin_el->get_margins().bottom = 0;
133 return ret_width;
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();