Skip to content

Commit 109a837

Browse files
committed
fixed table rendering
1 parent 61e89e5 commit 109a837

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/render_block.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,14 @@ int litehtml::render_item_block::_render(int x, int y, int max_width, const cont
672672

673673
containing_block_context cb_size = calculate_containing_block_context(containing_block_size);
674674

675+
max_width -= content_offset_left() + content_offset_right();
676+
if(max_width < 0) max_width = 0;
677+
max_width = std::min(max_width, cb_size.width);
678+
675679
//*****************************************
676680
// Render content
677681
//*****************************************
678-
ret_width = _render_content(x, y, cb_size.width, second_pass, ret_width, cb_size);
682+
ret_width = _render_content(x, y, max_width, second_pass, ret_width, cb_size);
679683
//*****************************************
680684

681685
bool requires_rerender = false;
@@ -685,6 +689,7 @@ int litehtml::render_item_block::_render(int x, int y, int max_width, const cont
685689
(src_el()->is_inline_box() ||
686690
src_el()->css().get_float() != float_none ||
687691
src_el()->css().get_display() == display_table_cell ||
692+
src_el()->css().get_display() == display_table_caption ||
688693
src_el()->css().get_position() > element_position_relative
689694
))
690695
{
@@ -790,14 +795,12 @@ int litehtml::render_item_block::_render(int x, int y, int max_width, const cont
790795
_render_content(x, y, cb_size.width, true, ret_width, cb_size);
791796
}
792797

793-
ret_width += content_offset_left() + content_offset_right();
794-
795798
if (src_el()->is_floats_holder() && !second_pass)
796799
{
797800
for (const auto& fb : m_floats_left)
798801
{
799802
fb.el->apply_relative_shift(containing_block_size);
800803
}
801804
}
802-
return ret_width;
805+
return ret_width + content_offset_width();
803806
}

src/render_item.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,10 @@ litehtml::containing_block_context litehtml::render_item::calculate_containing_b
10011001
if (src_el()->css().get_display() != display_table_cell)
10021002
{
10031003
calc_cb_length(src_el()->css().get_width(), cb_context.width, ret.width, ret.width_type);
1004+
if (src_el()->css().get_display() == display_table && ret.width_type != containing_block_context::cbc_value_type_auto)
1005+
{
1006+
ret.width -= content_offset_width();
1007+
}
10041008
}
10051009
calc_cb_length(src_el()->css().get_min_width(), cb_context.width, ret.min_width, ret.min_width_type);
10061010
calc_cb_length(src_el()->css().get_max_width(), cb_context.width, ret.max_width, ret.max_width_type);

src/render_table.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ int litehtml::render_item_table::_render(int x, int y, int max_width, const cont
2525

2626
containing_block_context cb_size = calculate_containing_block_context(containing_block_size);
2727

28+
if(cb_size.width_type == containing_block_context::cbc_value_type_auto)
29+
{
30+
max_width -= content_offset_left() + content_offset_right();
31+
} else
32+
{
33+
max_width -= m_padding.width() + m_borders.width();
34+
}
35+
if(max_width < 0) max_width = 0;
36+
max_width = std::min(max_width, cb_size.width);
37+
2838
// Calculate table spacing
2939
int table_width_spacing = 0;
3040
if (src_el()->css().get_border_collapse() == border_collapse_separate)
@@ -87,7 +97,7 @@ int litehtml::render_item_table::_render(int x, int y, int max_width, const cont
8797
else
8898
{
8999
// calculate minimum content width
90-
cell->min_width = cell->el->render(0, 0, 1, cb_size);
100+
cell->min_width = cell->el->render(0, 0, cell->el->content_offset_width(), cb_size);
91101
// calculate maximum content width
92102
cell->max_width = cell->el->render(0, 0, max_width - table_width_spacing, cb_size);
93103
}
@@ -327,8 +337,6 @@ int litehtml::render_item_table::_render(int x, int y, int max_width, const cont
327337
table_height += m_border_spacing_y;
328338
}
329339

330-
m_pos.width = table_width;
331-
332340
// Render table captions
333341
// Table border doesn't round the caption, so we have to start caption in the border position
334342
int captions_height = -border_top();
@@ -370,7 +378,7 @@ int litehtml::render_item_table::_render(int x, int y, int max_width, const cont
370378
m_pos.width = table_width;
371379
m_pos.height = table_height + captions_height;
372380

373-
return std::min(table_width, max_table_width) + content_offset_left() + content_offset_right();
381+
return std::min(table_width, max_table_width) + content_offset_width();
374382
}
375383

376384
std::shared_ptr<litehtml::render_item> litehtml::render_item_table::init()

test/render/table-4-td-width.htm.png

-8 Bytes
Loading

0 commit comments

Comments
 (0)