From 4667a6b15952a96c7a8a5e1e790865babfa9e999 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 21 Aug 2018 21:45:56 +0200 Subject: [PATCH] Handle adjoining margins in flex layout Top border is handled by collapsing_with_children set to False when the box is a flex item. Bottom border is handled at the end of the flex item layout, by adding the collapsed adjoining margins to the child's bottom border. Fix #673. --- weasyprint/layout/blocks.py | 2 +- weasyprint/layout/flex.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/weasyprint/layout/blocks.py b/weasyprint/layout/blocks.py index 00994415..78167b77 100644 --- a/weasyprint/layout/blocks.py +++ b/weasyprint/layout/blocks.py @@ -482,7 +482,7 @@ def block_container_layout(context, box, max_position_y, skip_stack, this_box_adjoining_margins = adjoining_margins collapsing_with_children = not ( - box.border_top_width or box.padding_top or + box.border_top_width or box.padding_top or box.is_flex_item or establishes_formatting_context(box) or box.is_for_root_element) if collapsing_with_children: # XXX not counting margins in adjoining_margins, if any diff --git a/weasyprint/layout/flex.py b/weasyprint/layout/flex.py index 3e9fbd2b..ba96a543 100644 --- a/weasyprint/layout/flex.py +++ b/weasyprint/layout/flex.py @@ -420,14 +420,20 @@ def flex_layout(context, box, max_position_y, skip_stack, containing_block, if child_copy.margin_bottom == 'auto': child_copy.margin_bottom = 0 blocks.block_level_width(child_copy, box) - new_child = blocks.block_level_layout_switch( - context, child_copy, float('inf'), - child_skip_stack, box, device_size, page_is_empty, - absolute_boxes, fixed_boxes, adjoining_margins=[])[0] + new_child, _, _, adjoining_margins, _ = ( + blocks.block_level_layout_switch( + context, child_copy, float('inf'), + child_skip_stack, box, device_size, page_is_empty, + absolute_boxes, fixed_boxes, adjoining_margins=[])) child._baseline = find_in_flow_baseline(new_child) if cross == 'height': child.height = new_child.height + # As flex items margins never collapse (with other flex items + # or with the flex container), we can add the adjoining margins + # to the child bottom margin. + child.margin_bottom += blocks.collapse_margin( + adjoining_margins) else: child.width = min_content_width(context, child, outer=False)