diff options
| author | Yuri Kobets <yuri.kobets@gmail.com> | 2022-09-14 00:39:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-14 00:39:44 +0300 |
| commit | e56cd9b730f4f0153906f67f14dc2ed95b05b75c (patch) | |
| tree | ba0ea98eb36863a4334a62615b30e95bee88aa8b /src/render_block_context.cpp | |
| parent | 436f49c07cd0608311b40f26c904ac77cced7be0 (diff) | |
Internal refactoring (#212)
* Refactored CSS properties
All CSS related properties are moved into the separate class css_properties.
Getters and setters are removed from classes element and html_tag.
Access to the css_properties rleased via css() [ro] and css_w() [rw] methods
* fix: el_text don't have to copy all css properties from parent
* Refactored rendering code
* Added flex and inline_flex values for display css property
* Implementing box generation
https://www.w3.org/TR/CSS22/visuren.html#box-gen
* Split inlines on block box inside
* Split parsing and rendering trees.
* Fixed some bugs
* Fixed: impossible to click urls on Obama wiki's toc
* Make element::get_placement work again
* Fixed: incorrect rendering table captions
* find_styles_changes function returned to the element class
* set parent correctly during render items split
* fixed urls on https://en.cppreference.com/w/cpp/container/vector
* fixed rendering blocks with width in percents
Example:
https://web.archive.org/web/20110101155107/http://www.unicode.org/
Issue #208
* Fixed placement of blocks with "overflow: hidden" with floating boxes.
* refactoring of rendering block
* Selectors :before and :after returned back with fixed behaviour.
* fixed render_item::is_last_child_inline
* fixed: text inside nested inlines has extra paddings/margins
* fixed documet test
Diffstat (limited to 'src/render_block_context.cpp')
| -rw-r--r-- | src/render_block_context.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/render_block_context.cpp b/src/render_block_context.cpp new file mode 100644 index 00000000..81ce2040 --- /dev/null +++ b/src/render_block_context.cpp @@ -0,0 +1,110 @@ +#include "html.h" +#include "render_item.h" +#include "document.h" + +int litehtml::render_item_block_context::_render_content(int x, int y, int max_width, bool second_pass, int ret_width) +{ + element_position el_position; + + int child_top = 0; + int last_margin = 0; + bool is_first = true; + for (const auto& el : m_children) + { + // we don't need to process absolute and fixed positioned element on the second pass + if (second_pass) + { + el_position = el->src_el()->css().get_position(); + if ((el_position == element_position_absolute || el_position == element_position_fixed)) continue; + } + + if(el->src_el()->css().get_float() != float_none) + { + int rw = place_float(el, child_top, max_width); + if (rw > ret_width) + { + ret_width = rw; + } + } else if(el->src_el()->css().get_display() != display_none) + { + if(el->src_el()->css().get_position() == element_position_absolute || el->src_el()->css().get_position() == element_position_fixed) + { + el->render(0, child_top, max_width); + el->pos().x += el->content_margins_left(); + el->pos().y += el->content_margins_top(); + } else + { + child_top = get_cleared_top(el, child_top); + int child_x = 0; + int child_width = max_width; + + el->calc_outlines(max_width); + + // Collapse top margin + if(is_first && collapse_top_margin()) + { + child_top -= el->get_margins().top; + if(el->get_margins().top > get_margins().top) + { + m_margins.top = el->get_margins().top; + } + } else + { + if(last_margin > el->get_margins().top) + { + child_top -= el->get_margins().top; + } else + { + child_top -= last_margin; + } + } + + if(el->src_el()->is_replaced() || el->src_el()->is_floats_holder()) + { + int ln_left = 0; + int ln_right = child_width; + get_line_left_right(child_top, child_width, ln_left, ln_right); + child_x = ln_left; + child_width = ln_right - ln_left; + + auto el_parent = el->parent(); + el->pos().width = el->src_el()->css().get_width().calc_percent(child_width); + el->pos().height = el->src_el()->css().get_height().calc_percent(el_parent ? el_parent->pos().height : 0); + } + + int rw = el->render(child_x, child_top, child_width); + if (rw > ret_width) + { + ret_width = rw; + } + child_top += el->height(); + last_margin = el->get_margins().bottom; + is_first = false; + + if (el->src_el()->css().get_position() == element_position_relative) + { + el->apply_relative_shift(max_width); + } + } + } + } + + int block_height = 0; + if (get_predefined_height(block_height)) + { + m_pos.height = block_height; + } else + { + m_pos.height = child_top; + if(collapse_bottom_margin()) + { + m_pos.height -= last_margin; + if(m_margins.bottom < last_margin) + { + m_margins.bottom = last_margin; + } + } + } + + return ret_width; +} |
