Skip to content

Commit 82b37df

Browse files
authored
Auto merge of servo#29952 - Loirooriol:resolve-percentages, r=mrobinson
Resolve percentages in find_block_margin_collapsing_with_parent <!-- Please describe your changes on the following line: --> Padding percentages weren't being resolved, this function would think that margins wouldn't collapse even if the percentage resolved to 0px. And margin percentages were always resolved to 0px. So now the function takes a ContainingBlock parameter that is used to resolve these percentages properly. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2 parents f034eb6 + 995d607 commit 82b37df

File tree

1 file changed

+42
-30
lines changed
  • components/layout_2020/flow

1 file changed

+42
-30
lines changed

components/layout_2020/flow/mod.rs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use style::computed_values::clear::T as Clear;
2626
use style::computed_values::float::T as Float;
2727
use style::logical_geometry::WritingMode;
2828
use style::properties::ComputedValues;
29-
use style::values::computed::{CSSPixelLength, Length, LengthOrAuto};
29+
use style::values::computed::{Length, LengthOrAuto};
3030
use style::Zero;
3131

3232
mod construct;
@@ -65,7 +65,7 @@ impl BlockLevelBox {
6565
fn find_block_margin_collapsing_with_parent(
6666
&self,
6767
collected_margin: &mut CollapsedMargin,
68-
containing_block_writing_mode: WritingMode,
68+
containing_block: &ContainingBlock,
6969
) -> bool {
7070
// TODO(mrobinson,Loirooriol): Cache margins here so that we don't constantly
7171
// have to keep looking forward when dealing with sequences of floats.
@@ -76,39 +76,57 @@ impl BlockLevelBox {
7676
BlockLevelBox::Independent(ref context) => context.style(),
7777
};
7878

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-
8379
// FIXME: This should only return false when 'clear' causes clearance.
8480
if style.get_box().clear != Clear::None {
8581
return false;
8682
}
8783

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);
9386
collected_margin.adjoin_assign(&CollapsedMargin::new(start_margin));
9487

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-
10288
let contents = match self {
10389
BlockLevelBox::SameFormattingContextBlock { ref contents, .. } => contents,
10490
_ => return false,
10591
};
92+
93+
if pbm.padding.block_start != Length::zero() || pbm.border.block_start != Length::zero() {
94+
return false;
95+
}
96+
10697
match contents {
10798
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+
108126
if !Self::find_block_margin_collapsing_with_parent_from_slice(
109127
&boxes,
110128
collected_margin,
111-
style.writing_mode,
129+
&containing_block_for_children,
112130
) {
113131
return false;
114132
}
@@ -120,20 +138,14 @@ impl BlockLevelBox {
120138
style.content_block_size().is_definitely_zero() || style.content_block_size().is_auto();
121139
let min_block_size_zero =
122140
style.min_block_size().is_definitely_zero() || style.min_block_size().is_auto();
123-
// FIXME: Should resolve padding percentages.
124141
if !min_block_size_zero ||
125142
!block_size_zero ||
126-
!border.block_end.is_zero() ||
127-
!padding.block_end.is_zero()
143+
pbm.padding_border_sums.block != Length::zero()
128144
{
129145
return false;
130146
}
131147

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);
137149
collected_margin.adjoin_assign(&CollapsedMargin::new(end_margin));
138150

139151
true
@@ -142,12 +154,12 @@ impl BlockLevelBox {
142154
fn find_block_margin_collapsing_with_parent_from_slice(
143155
boxes: &[ArcRefCell<BlockLevelBox>],
144156
margin: &mut CollapsedMargin,
145-
writing_mode: WritingMode,
157+
containing_block: &ContainingBlock,
146158
) -> bool {
147159
boxes.iter().all(|block_level_box| {
148160
block_level_box
149161
.borrow()
150-
.find_block_margin_collapsing_with_parent(margin, writing_mode)
162+
.find_block_margin_collapsing_with_parent(margin, containing_block)
151163
})
152164
}
153165
}
@@ -668,7 +680,7 @@ fn layout_in_flow_non_replaced_block_level(
668680
BlockLevelBox::find_block_margin_collapsing_with_parent_from_slice(
669681
child_boxes,
670682
&mut block_start_margin,
671-
WritingMode::empty(),
683+
containing_block,
672684
);
673685
}
674686
}

0 commit comments

Comments
 (0)