Skip to content

Commit 819c20e

Browse files
committed
fixed rendering elements with position absoute and fixed
Also: * refactoring: have_parent is replaced with is_root in render_item * fixed: The tag <body> is not floats holder by default * expanding <html> and <body> elements auto-expanding up to client rectangle
1 parent ec2d946 commit 819c20e

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

include/litehtml/render_item.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ namespace litehtml
273273
return 0;
274274
}
275275

276-
bool have_parent() const
277-
{
278-
return !m_parent.expired();
279-
}
276+
bool is_root() const
277+
{
278+
return m_parent.expired();
279+
}
280280

281281
bool collapse_top_margin() const
282282
{
@@ -285,7 +285,7 @@ namespace litehtml
285285
m_element->in_normal_flow() &&
286286
m_element->css().get_float() == float_none &&
287287
m_margins.top >= 0 &&
288-
have_parent();
288+
!is_root();
289289
}
290290

291291
bool collapse_bottom_margin() const
@@ -295,7 +295,7 @@ namespace litehtml
295295
m_element->in_normal_flow() &&
296296
m_element->css().get_float() == float_none &&
297297
m_margins.bottom >= 0 &&
298-
have_parent();
298+
!is_root();
299299
}
300300

301301
bool is_visible() const

src/html_tag.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,6 @@ bool litehtml::html_tag::is_floats_holder() const
10681068
if( m_css.get_display() == display_inline_block ||
10691069
m_css.get_display() == display_table_cell ||
10701070
is_root() ||
1071-
is_body() ||
10721071
m_css.get_float() != float_none ||
10731072
m_css.get_position() == element_position_absolute ||
10741073
m_css.get_position() == element_position_fixed ||

src/render_block.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ int litehtml::render_item_block::render(int x, int y, const containing_block_con
789789
}
790790

791791
// re-render content with new width if required
792-
if (requires_rerender && !second_pass && have_parent())
792+
if (requires_rerender && !second_pass && !is_root())
793793
{
794794
m_floats_left.clear();
795795
m_floats_right.clear();
@@ -799,18 +799,6 @@ int litehtml::render_item_block::render(int x, int y, const containing_block_con
799799
_render_content(x, y, true, ret_width, self_size.new_width(m_pos.width));
800800
}
801801

802-
if(src_el()->is_root() || src_el()->is_body())
803-
{
804-
if(self_size.width.type == containing_block_context::cbc_value_type_auto && m_pos.width < containing_block_size.width - content_offset_width())
805-
{
806-
m_pos.width = containing_block_size.width - content_offset_width();
807-
}
808-
if(self_size.height.type == containing_block_context::cbc_value_type_auto && m_pos.height < containing_block_size.height - content_offset_height())
809-
{
810-
m_pos.height = containing_block_size.height - content_offset_height();
811-
}
812-
}
813-
814802
if (src_el()->is_floats_holder() && !second_pass)
815803
{
816804
for (const auto& fb : m_floats_left)

src/render_item.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ void litehtml::render_item::render_positioned(render_type rt)
464464

465465
void litehtml::render_item::add_positioned(const std::shared_ptr<litehtml::render_item> &el)
466466
{
467-
if (src_el()->css().get_position() != element_position_static || (!have_parent()))
467+
if (src_el()->css().get_position() != element_position_static || is_root())
468468
{
469469
m_positioned.push_back(el);
470470
} else
@@ -1002,7 +1002,10 @@ litehtml::containing_block_context litehtml::render_item::calculate_containing_b
10021002
{
10031003
containing_block_context ret;
10041004
ret.width.value = ret.max_width.value = cb_context.width.value - content_offset_width();
1005-
ret.height.value = cb_context.height.value - content_offset_height();
1005+
if(src_el()->css().get_position() != element_position_absolute && src_el()->css().get_position() != element_position_fixed)
1006+
{
1007+
ret.height.value = cb_context.height.value - content_offset_height();
1008+
}
10061009

10071010
// Calculate width if css property is not auto
10081011
// We have to use aut value for display_table_cell also.

0 commit comments

Comments
 (0)