@@ -67,8 +67,6 @@ impl BlockLevelBox {
67
67
collected_margin : & mut CollapsedMargin ,
68
68
containing_block : & ContainingBlock ,
69
69
) -> bool {
70
- // TODO(mrobinson,Loirooriol): Cache margins here so that we don't constantly
71
- // have to keep looking forward when dealing with sequences of floats.
72
70
let style = match self {
73
71
BlockLevelBox :: SameFormattingContextBlock { ref style, .. } => & style,
74
72
BlockLevelBox :: OutOfFlowAbsolutelyPositionedBox ( _) |
@@ -399,6 +397,7 @@ fn layout_block_level_children_in_parallel(
399
397
& mut child_positioning_context,
400
398
containing_block,
401
399
/* sequential_layout_state = */ None ,
400
+ /* collapsible_with_parent_start_margin = */ None ,
402
401
) ;
403
402
( fragment, child_positioning_context)
404
403
} )
@@ -448,6 +447,9 @@ fn layout_block_level_children_sequentially(
448
447
& mut child_positioning_context,
449
448
containing_block,
450
449
Some ( & mut * sequential_layout_state) ,
450
+ Some ( CollapsibleWithParentStartMargin (
451
+ placement_state. next_in_flow_margin_collapses_with_parent_start_margin ,
452
+ ) ) ,
451
453
) ;
452
454
453
455
placement_state. place_fragment ( & mut fragment, Some ( sequential_layout_state) ) ;
@@ -474,6 +476,7 @@ impl BlockLevelBox {
474
476
positioning_context : & mut PositioningContext ,
475
477
containing_block : & ContainingBlock ,
476
478
sequential_layout_state : Option < & mut SequentialLayoutState > ,
479
+ collapsible_with_parent_start_margin : Option < CollapsibleWithParentStartMargin > ,
477
480
) -> Fragment {
478
481
match self {
479
482
BlockLevelBox :: SameFormattingContextBlock {
@@ -493,6 +496,7 @@ impl BlockLevelBox {
493
496
style,
494
497
NonReplacedContents :: SameFormattingContextBlock ( contents) ,
495
498
sequential_layout_state,
499
+ collapsible_with_parent_start_margin,
496
500
)
497
501
} ,
498
502
) ) ,
@@ -529,6 +533,7 @@ impl BlockLevelBox {
529
533
non_replaced,
530
534
) ,
531
535
sequential_layout_state,
536
+ collapsible_with_parent_start_margin,
532
537
)
533
538
} ,
534
539
) )
@@ -591,6 +596,7 @@ fn layout_in_flow_non_replaced_block_level(
591
596
style : & Arc < ComputedValues > ,
592
597
block_level_kind : NonReplacedContents ,
593
598
mut sequential_layout_state : Option < & mut SequentialLayoutState > ,
599
+ collapsible_with_parent_start_margin : Option < CollapsibleWithParentStartMargin > ,
594
600
) -> BoxFragment {
595
601
let pbm = style. padding_border_margin ( containing_block) ;
596
602
let box_size = style. content_box_size ( containing_block, & pbm) ;
@@ -671,13 +677,27 @@ fn layout_in_flow_non_replaced_block_level(
671
677
None => parent_containing_block_position_info = None ,
672
678
Some ( ref mut sequential_layout_state) => {
673
679
let mut block_start_margin = CollapsedMargin :: new ( margin. block_start ) ;
674
- if start_margin_can_collapse_with_children {
680
+
681
+ // The block start margin may collapse with content margins,
682
+ // compute the resulting one in order to place floats correctly.
683
+ // Only need to do this if the element isn't also collapsing with its parent,
684
+ // otherwise we should have already included the margin in an ancestor.
685
+ // Note this lookahead stops when finding a descendant whose `clear` isn't `none`
686
+ // (since clearance prevents collapsing margins with the parent).
687
+ // But then we have to decide whether to actually add clearance or not,
688
+ // so look forward again regardless of `collapsible_with_parent_start_margin`.
689
+ // TODO: This isn't completely right: if we don't add actual clearance,
690
+ // the margin should have been included in the parent (or some ancestor).
691
+ // The lookahead should stop for actual clearance, not just for `clear`.
692
+ let collapsible_with_parent_start_margin = collapsible_with_parent_start_margin. expect (
693
+ "We should know whether we are collapsing the block start margin with the parent \
694
+ when laying out sequentially",
695
+ ) . 0 && style. get_box ( ) . clear == Clear :: None ;
696
+ if !collapsible_with_parent_start_margin && start_margin_can_collapse_with_children {
675
697
if let NonReplacedContents :: SameFormattingContextBlock (
676
698
BlockContainer :: BlockLevelBoxes ( child_boxes) ,
677
699
) = block_level_kind
678
700
{
679
- // The block start margin may collapse with content margins,
680
- // compute the resulting one in order to place floats correctly.
681
701
BlockLevelBox :: find_block_margin_collapsing_with_parent_from_slice (
682
702
child_boxes,
683
703
& mut block_start_margin,
0 commit comments