@@ -26,7 +26,7 @@ use style::computed_values::clear::T as Clear;
26
26
use style:: computed_values:: float:: T as Float ;
27
27
use style:: logical_geometry:: WritingMode ;
28
28
use style:: properties:: ComputedValues ;
29
- use style:: values:: computed:: { CSSPixelLength , Length , LengthOrAuto } ;
29
+ use style:: values:: computed:: { Length , LengthOrAuto } ;
30
30
use style:: Zero ;
31
31
32
32
mod construct;
@@ -65,7 +65,7 @@ impl BlockLevelBox {
65
65
fn find_block_margin_collapsing_with_parent (
66
66
& self ,
67
67
collected_margin : & mut CollapsedMargin ,
68
- containing_block_writing_mode : WritingMode ,
68
+ containing_block : & ContainingBlock ,
69
69
) -> bool {
70
70
// TODO(mrobinson,Loirooriol): Cache margins here so that we don't constantly
71
71
// have to keep looking forward when dealing with sequences of floats.
@@ -76,39 +76,57 @@ impl BlockLevelBox {
76
76
BlockLevelBox :: Independent ( ref context) => context. style ( ) ,
77
77
} ;
78
78
79
- let margin = style. margin ( containing_block_writing_mode) ;
80
- let border = style. border_width ( containing_block_writing_mode) ;
81
- let padding = style. padding ( containing_block_writing_mode) ;
82
-
83
79
// FIXME: This should only return false when 'clear' causes clearance.
84
80
if style. get_box ( ) . clear != Clear :: None {
85
81
return false ;
86
82
}
87
83
88
- // FIXME: Percentages should be resolved against the width of the containing block.
89
- let start_margin = margin
90
- . block_start
91
- . percentage_relative_to ( CSSPixelLength :: zero ( ) )
92
- . auto_is ( CSSPixelLength :: zero) ;
84
+ let pbm = style. padding_border_margin ( containing_block) ;
85
+ let start_margin = pbm. margin . block_start . auto_is ( Length :: zero) ;
93
86
collected_margin. adjoin_assign ( & CollapsedMargin :: new ( start_margin) ) ;
94
87
95
- // FIXME: Should resolve padding percentages.
96
- let start_padding_is_zero = padding. block_start . is_zero ( ) ;
97
- let start_border_is_zero = border. block_start . is_zero ( ) ;
98
- if !start_border_is_zero || !start_padding_is_zero {
99
- return false ;
100
- }
101
-
102
88
let contents = match self {
103
89
BlockLevelBox :: SameFormattingContextBlock { ref contents, .. } => contents,
104
90
_ => return false ,
105
91
} ;
92
+
93
+ if pbm. padding . block_start != Length :: zero ( ) || pbm. border . block_start != Length :: zero ( ) {
94
+ return false ;
95
+ }
96
+
106
97
match contents {
107
98
BlockContainer :: BlockLevelBoxes ( boxes) => {
99
+ let min_inline_size = style
100
+ . content_min_box_size ( containing_block, & pbm)
101
+ . auto_is ( Length :: zero)
102
+ . inline ;
103
+ let max_inline_size = style. content_max_box_size ( containing_block, & pbm) . inline ;
104
+ let inline_size = style
105
+ . content_box_size ( containing_block, & pbm)
106
+ . inline
107
+ . auto_is ( || {
108
+ let margin_inline_start = pbm. margin . inline_start . auto_is ( Length :: zero) ;
109
+ let margin_inline_end = pbm. margin . inline_end . auto_is ( Length :: zero) ;
110
+ containing_block. inline_size -
111
+ pbm. padding_border_sums . inline -
112
+ margin_inline_start -
113
+ margin_inline_end
114
+ } )
115
+ . clamp_between_extremums ( min_inline_size, max_inline_size) ;
116
+
117
+ // The block size is irrelevant here.
118
+ let block_size = LengthOrAuto :: Auto ;
119
+
120
+ let containing_block_for_children = ContainingBlock {
121
+ inline_size,
122
+ block_size,
123
+ style,
124
+ } ;
125
+
108
126
if !Self :: find_block_margin_collapsing_with_parent_from_slice (
109
127
& boxes,
110
128
collected_margin,
111
- style . writing_mode ,
129
+ & containing_block_for_children ,
112
130
) {
113
131
return false ;
114
132
}
@@ -120,20 +138,14 @@ impl BlockLevelBox {
120
138
style. content_block_size ( ) . is_definitely_zero ( ) || style. content_block_size ( ) . is_auto ( ) ;
121
139
let min_block_size_zero =
122
140
style. min_block_size ( ) . is_definitely_zero ( ) || style. min_block_size ( ) . is_auto ( ) ;
123
- // FIXME: Should resolve padding percentages.
124
141
if !min_block_size_zero ||
125
142
!block_size_zero ||
126
- !border. block_end . is_zero ( ) ||
127
- !padding. block_end . is_zero ( )
143
+ pbm. padding_border_sums . block != Length :: zero ( )
128
144
{
129
145
return false ;
130
146
}
131
147
132
- // FIXME: Percentages should be resolved against the width of the containing block.
133
- let end_margin = margin
134
- . block_end
135
- . percentage_relative_to ( CSSPixelLength :: zero ( ) )
136
- . auto_is ( CSSPixelLength :: zero) ;
148
+ let end_margin = pbm. margin . block_end . auto_is ( Length :: zero) ;
137
149
collected_margin. adjoin_assign ( & CollapsedMargin :: new ( end_margin) ) ;
138
150
139
151
true
@@ -142,12 +154,12 @@ impl BlockLevelBox {
142
154
fn find_block_margin_collapsing_with_parent_from_slice (
143
155
boxes : & [ ArcRefCell < BlockLevelBox > ] ,
144
156
margin : & mut CollapsedMargin ,
145
- writing_mode : WritingMode ,
157
+ containing_block : & ContainingBlock ,
146
158
) -> bool {
147
159
boxes. iter ( ) . all ( |block_level_box| {
148
160
block_level_box
149
161
. borrow ( )
150
- . find_block_margin_collapsing_with_parent ( margin, writing_mode )
162
+ . find_block_margin_collapsing_with_parent ( margin, containing_block )
151
163
} )
152
164
}
153
165
}
@@ -668,7 +680,7 @@ fn layout_in_flow_non_replaced_block_level(
668
680
BlockLevelBox :: find_block_margin_collapsing_with_parent_from_slice (
669
681
child_boxes,
670
682
& mut block_start_margin,
671
- WritingMode :: empty ( ) ,
683
+ containing_block ,
672
684
) ;
673
685
}
674
686
}
0 commit comments