@@ -62,7 +62,7 @@ pub(crate) enum BlockLevelBox {
62
62
}
63
63
64
64
impl BlockLevelBox {
65
- fn find_block_margin_collapsing_with_parent_for_floats (
65
+ fn find_block_margin_collapsing_with_parent (
66
66
& self ,
67
67
collected_margin : & mut CollapsedMargin ,
68
68
containing_block_writing_mode : WritingMode ,
@@ -80,16 +80,19 @@ impl BlockLevelBox {
80
80
let border = style. border_width ( containing_block_writing_mode) ;
81
81
let padding = style. padding ( containing_block_writing_mode) ;
82
82
83
+ // FIXME: This should only return false when 'clear' causes clearance.
83
84
if style. get_box ( ) . clear != Clear :: None {
84
85
return false ;
85
86
}
86
87
88
+ // FIXME: Percentages should be resolved against the width of the containing block.
87
89
let start_margin = margin
88
90
. block_start
89
91
. percentage_relative_to ( CSSPixelLength :: zero ( ) )
90
92
. auto_is ( CSSPixelLength :: zero) ;
91
93
collected_margin. adjoin_assign ( & CollapsedMargin :: new ( start_margin) ) ;
92
94
95
+ // FIXME: Should resolve padding percentages.
93
96
let start_padding_is_zero = padding. block_start . is_zero ( ) ;
94
97
let start_border_is_zero = border. block_start . is_zero ( ) ;
95
98
if !start_border_is_zero || !start_padding_is_zero {
@@ -102,7 +105,7 @@ impl BlockLevelBox {
102
105
} ;
103
106
match contents {
104
107
BlockContainer :: BlockLevelBoxes ( boxes) => {
105
- if !Self :: find_block_margin_collapsing_with_parent_for_floats_from_slice (
108
+ if !Self :: find_block_margin_collapsing_with_parent_from_slice (
106
109
& boxes,
107
110
collected_margin,
108
111
style. writing_mode ,
@@ -115,14 +118,18 @@ impl BlockLevelBox {
115
118
116
119
let block_size_zero =
117
120
style. content_block_size ( ) . is_definitely_zero ( ) || style. content_block_size ( ) . is_auto ( ) ;
118
- if !style. min_block_size ( ) . is_definitely_zero ( ) ||
121
+ let min_block_size_zero =
122
+ style. min_block_size ( ) . is_definitely_zero ( ) || style. min_block_size ( ) . is_auto ( ) ;
123
+ // FIXME: Should resolve padding percentages.
124
+ if !min_block_size_zero ||
119
125
!block_size_zero ||
120
126
!border. block_end . is_zero ( ) ||
121
127
!padding. block_end . is_zero ( )
122
128
{
123
129
return false ;
124
130
}
125
131
132
+ // FIXME: Percentages should be resolved against the width of the containing block.
126
133
let end_margin = margin
127
134
. block_end
128
135
. percentage_relative_to ( CSSPixelLength :: zero ( ) )
@@ -132,15 +139,15 @@ impl BlockLevelBox {
132
139
true
133
140
}
134
141
135
- fn find_block_margin_collapsing_with_parent_for_floats_from_slice (
142
+ fn find_block_margin_collapsing_with_parent_from_slice (
136
143
boxes : & [ ArcRefCell < BlockLevelBox > ] ,
137
144
margin : & mut CollapsedMargin ,
138
145
writing_mode : WritingMode ,
139
146
) -> bool {
140
147
boxes. iter ( ) . all ( |block_level_box| {
141
148
block_level_box
142
149
. borrow ( )
143
- . find_block_margin_collapsing_with_parent_for_floats ( margin, writing_mode)
150
+ . find_block_margin_collapsing_with_parent ( margin, writing_mode)
144
151
} )
145
152
}
146
153
}
@@ -421,8 +428,7 @@ fn layout_block_level_children_sequentially(
421
428
// tracks every float encountered so far (again in tree order).
422
429
let fragments = child_boxes
423
430
. iter ( )
424
- . enumerate ( )
425
- . map ( |( index, child_box) | {
431
+ . map ( |child_box| {
426
432
let mut child_positioning_context =
427
433
PositioningContext :: new_for_subtree ( collects_for_nearest_positioned_ancestor) ;
428
434
let mut fragment = child_box. borrow_mut ( ) . layout (
@@ -432,11 +438,7 @@ fn layout_block_level_children_sequentially(
432
438
Some ( & mut * sequential_layout_state) ,
433
439
) ;
434
440
435
- let sequential_info = PlacementStateSequentialInfo {
436
- sequential_layout_state,
437
- following_boxes : & child_boxes[ index..] ,
438
- } ;
439
- placement_state. place_fragment ( & mut fragment, Some ( sequential_info) ) ;
441
+ placement_state. place_fragment ( & mut fragment, Some ( sequential_layout_state) ) ;
440
442
441
443
child_positioning_context. adjust_static_position_of_hoisted_fragments ( & fragment) ;
442
444
positioning_context. append ( child_positioning_context) ;
@@ -656,7 +658,22 @@ fn layout_in_flow_non_replaced_block_level(
656
658
None => parent_containing_block_position_info = None ,
657
659
Some ( ref mut sequential_layout_state) => {
658
660
sequential_layout_state. adjoin_assign ( & CollapsedMargin :: new ( margin. block_start ) ) ;
659
- if !start_margin_can_collapse_with_children {
661
+ if start_margin_can_collapse_with_children {
662
+ if let NonReplacedContents :: SameFormattingContextBlock (
663
+ BlockContainer :: BlockLevelBoxes ( child_boxes) ,
664
+ ) = block_level_kind
665
+ {
666
+ // The block start margin may collapse with content margins,
667
+ // compute the resulting one in order to place floats correctly.
668
+ let mut future_margins = CollapsedMargin :: zero ( ) ;
669
+ BlockLevelBox :: find_block_margin_collapsing_with_parent_from_slice (
670
+ child_boxes,
671
+ & mut future_margins,
672
+ WritingMode :: empty ( ) ,
673
+ ) ;
674
+ sequential_layout_state. adjoin_assign ( & future_margins) ;
675
+ }
676
+ } else {
660
677
sequential_layout_state. collapse_margins ( ) ;
661
678
}
662
679
@@ -876,18 +893,6 @@ fn solve_inline_margins_for_in_flow_block_level(
876
893
}
877
894
}
878
895
879
- /// Information passed to [PlacementState::place_fragment] when operating in sequential
880
- /// mode.
881
- struct PlacementStateSequentialInfo < ' a > {
882
- /// The sequential layout state of the current layout.
883
- sequential_layout_state : & ' a mut SequentialLayoutState ,
884
-
885
- /// The boxes that follow the one currently being placed. This is used to try
886
- /// to calculate margins after the current box that will collapse with the
887
- /// parent, if this current box is floating.
888
- following_boxes : & ' a [ ArcRefCell < BlockLevelBox > ] ,
889
- }
890
-
891
896
/// State that we maintain when placing blocks.
892
897
///
893
898
/// In parallel mode, this placement is done after all child blocks are laid out. In
@@ -919,7 +924,7 @@ impl PlacementState {
919
924
fn place_fragment (
920
925
& mut self ,
921
926
fragment : & mut Fragment ,
922
- sequential_info : Option < PlacementStateSequentialInfo > ,
927
+ sequential_layout_state : Option < & mut SequentialLayoutState > ,
923
928
) {
924
929
match fragment {
925
930
Fragment :: Box ( fragment) => {
@@ -983,30 +988,13 @@ impl PlacementState {
983
988
fragment. borrow_mut ( ) . adjust_offsets ( offset) ;
984
989
} ,
985
990
Fragment :: Float ( box_fragment) => {
986
- let info = sequential_info
987
- . expect ( "Tried to lay out a float with no sequential placement state!" ) ;
988
-
989
- let mut margins_collapsing_with_parent_containing_block = self . start_margin ;
990
- if self . next_in_flow_margin_collapses_with_parent_start_margin {
991
- // If block start margins are still collapsing from the parent, margins of elements
992
- // that follow this float in tree order might collapse, pushing this float down
993
- // and changing the offset of the containing block of the float. We try to look
994
- // ahead to determine which margins from future elements will collapse with the
995
- // parent.
996
- let mut future_margins = CollapsedMargin :: zero ( ) ;
997
- BlockLevelBox :: find_block_margin_collapsing_with_parent_for_floats_from_slice (
998
- info. following_boxes ,
999
- & mut future_margins,
1000
- WritingMode :: empty ( ) ,
1001
- ) ;
1002
- margins_collapsing_with_parent_containing_block. adjoin_assign ( & future_margins)
1003
- }
1004
-
991
+ let sequential_layout_state = sequential_layout_state
992
+ . expect ( "Found float fragment without SequentialLayoutState" ) ;
1005
993
let block_offset_from_containing_block_top =
1006
994
self . current_block_direction_position + self . current_margin . solve ( ) ;
1007
- info . sequential_layout_state . place_float_fragment (
995
+ sequential_layout_state. place_float_fragment (
1008
996
box_fragment,
1009
- margins_collapsing_with_parent_containing_block ,
997
+ self . start_margin ,
1010
998
block_offset_from_containing_block_top,
1011
999
) ;
1012
1000
} ,
0 commit comments