@@ -193,20 +193,10 @@ int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass,
193
193
case flex_direction_column:
194
194
is_row_direction = false ;
195
195
reverse = false ;
196
- container_main_size = self_size.height ;
197
- if (css ().get_box_sizing () == box_sizing_border_box)
198
- {
199
- container_main_size -= box_sizing_height ();
200
- }
201
196
break ;
202
197
case flex_direction_column_reverse:
203
198
is_row_direction = false ;
204
199
reverse = true ;
205
- container_main_size = self_size.height ;
206
- if (css ().get_box_sizing () == box_sizing_border_box)
207
- {
208
- container_main_size -= box_sizing_height ();
209
- }
210
200
break ;
211
201
case flex_direction_row:
212
202
is_row_direction = true ;
@@ -218,8 +208,29 @@ int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass,
218
208
break ;
219
209
}
220
210
211
+ bool single_line = css ().get_flex_wrap () == flex_wrap_nowrap;
212
+ bool fit_container = false ;
213
+
214
+ if (!is_row_direction)
215
+ {
216
+ if (self_size.height .type != containing_block_context::cbc_value_type_auto)
217
+ {
218
+ container_main_size = self_size.height ;
219
+ if (css ().get_box_sizing () == box_sizing_border_box)
220
+ {
221
+ container_main_size -= box_sizing_height ();
222
+ }
223
+ } else
224
+ {
225
+ // Direction columns, height is auto - always in single line
226
+ container_main_size = 0 ;
227
+ single_line = true ;
228
+ fit_container = true ;
229
+ }
230
+ }
231
+
221
232
// Split flex items to lines
222
- std::list<flex_line> lines = get_lines (self_size, fmt_ctx, is_row_direction, container_main_size);
233
+ std::list<flex_line> lines = get_lines (self_size, fmt_ctx, is_row_direction, container_main_size, single_line );
223
234
224
235
// Resolving Flexible Lengths
225
236
// REF: https://www.w3.org/TR/css-flexbox-1/#resolve-flexible-lengths
@@ -238,7 +249,10 @@ int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass,
238
249
ret_width += ln.base_size ;
239
250
}
240
251
241
- ln.distribute_free_space (container_main_size);
252
+ if (!fit_container)
253
+ {
254
+ ln.distribute_free_space (container_main_size);
255
+ }
242
256
243
257
if (is_row_direction)
244
258
{
@@ -267,8 +281,6 @@ int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass,
267
281
item.el ->render (el_x,
268
282
el_y,
269
283
self_size.new_width (el_ret_width), fmt_ctx, false );
270
- // TODO: must be rendered into the specified height
271
- item.el ->pos ().height = item.main_size - item.el ->content_offset_height ();
272
284
ln.cross_size = std::max (ln.cross_size , item.el ->width ());
273
285
el_y += item.el ->height ();
274
286
}
@@ -278,24 +290,21 @@ int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass,
278
290
}
279
291
280
292
int free_cross_size = 0 ;
281
- if (sum_cross_size )
293
+ if (is_row_direction )
282
294
{
283
- if (is_row_direction )
295
+ if (self_size. height . type != containing_block_context::cbc_value_type_auto )
284
296
{
285
- if (self_size.height .type != containing_block_context::cbc_value_type_auto)
297
+ int height = self_size.height ;
298
+ if (src_el ()->css ().get_box_sizing () == box_sizing_border_box)
286
299
{
287
- int height = self_size.height ;
288
- if (src_el ()->css ().get_box_sizing () == box_sizing_border_box)
289
- {
290
- height -= box_sizing_height ();
291
- }
292
- free_cross_size = height - sum_cross_size;
300
+ height -= box_sizing_height ();
293
301
}
294
- } else
295
- {
296
- free_cross_size = self_size.render_width - sum_cross_size;
297
- ret_width = sum_cross_size;
302
+ free_cross_size = height - sum_cross_size;
298
303
}
304
+ } else
305
+ {
306
+ free_cross_size = self_size.render_width - sum_cross_size;
307
+ ret_width = sum_cross_size;
299
308
}
300
309
301
310
// Find line cross size and align items
@@ -377,8 +386,11 @@ int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass,
377
386
break ;
378
387
default :
379
388
item.el ->pos ().y = el_y + item.el ->content_offset_top ();
380
- // TODO: must be rendered into the specified height
381
- item.el ->pos ().height = ln.cross_size - item.el ->content_offset_height ();
389
+ if (item.el ->css ().get_height ().is_predefined ())
390
+ {
391
+ // TODO: must be rendered into the specified height
392
+ item.el ->pos ().height = ln.cross_size - item.el ->content_offset_height ();
393
+ }
382
394
break ;
383
395
}
384
396
m_pos.height = std::max (m_pos.height , item.el ->bottom ());
@@ -458,8 +470,11 @@ int litehtml::render_item_flex::_render_content(int x, int y, bool second_pass,
458
470
item.el ->render (el_x,
459
471
item.el ->pos ().y - item.el ->content_offset_top (),
460
472
self_size.new_width (ln.cross_size ), fmt_ctx, false );
461
- // TODO: must be rendered into the specified height
462
- item.el ->pos ().height = item.main_size - item.el ->content_offset_height ();
473
+ if (item.el ->css ().get_width ().is_predefined ())
474
+ {
475
+ // TODO: must be rendered into the specified height
476
+ item.el ->pos ().height = item.main_size - item.el ->content_offset_height ();
477
+ }
463
478
break ;
464
479
}
465
480
m_pos.height = std::max (m_pos.height , item.el ->bottom ());
@@ -610,7 +625,8 @@ litehtml::render_item_flex::flex_line::distribute_free_space(int container_main_
610
625
611
626
std::list<litehtml::render_item_flex::flex_line> litehtml::render_item_flex::get_lines (const litehtml::containing_block_context &self_size,
612
627
litehtml::formatting_context *fmt_ctx,
613
- bool is_row_direction, int container_main_size)
628
+ bool is_row_direction, int container_main_size,
629
+ bool single_line)
614
630
{
615
631
std::list<flex_line> lines;
616
632
flex_line line;
@@ -748,7 +764,7 @@ std::list<litehtml::render_item_flex::flex_line> litehtml::render_item_flex::get
748
764
// Add flex items to lines
749
765
for (auto & item : items)
750
766
{
751
- if (!line.items .empty () && css (). get_flex_wrap () != flex_wrap_nowrap && line.base_size + item.base_size > container_main_size)
767
+ if (!line.items .empty () && !single_line && line.base_size + item.base_size > container_main_size)
752
768
{
753
769
lines.push_back (line);
754
770
line.clear ();
0 commit comments