Merge pull request #3107 from mrobinson/root-margin-collapse

Prevent margin collapse in the root flow
This commit is contained in:
Martin Robinson 2014-08-18 14:27:10 -07:00
commit d565eade88
4 changed files with 17 additions and 2 deletions

View file

@ -760,7 +760,7 @@ impl BlockFlow {
} }
/// If this is the root flow, shifts all kids down and adjusts our size to account for /// If this is the root flow, shifts all kids down and adjusts our size to account for
/// collapsed margins. /// root flow margins, which should never be collapsed according to CSS § 8.3.1.
/// ///
/// TODO(#2017, pcwalton): This is somewhat inefficient (traverses kids twice); can we do /// TODO(#2017, pcwalton): This is somewhat inefficient (traverses kids twice); can we do
/// better? /// better?
@ -770,7 +770,7 @@ impl BlockFlow {
} }
let (block_start_margin_value, block_end_margin_value) = match self.base.collapsible_margins { let (block_start_margin_value, block_end_margin_value) = match self.base.collapsible_margins {
MarginsCollapseThrough(margin) => (Au(0), margin.collapse()), MarginsCollapseThrough(_) => fail!("Margins unexpectedly collapsed through root flow."),
MarginsCollapse(block_start_margin, block_end_margin) => { MarginsCollapse(block_start_margin, block_end_margin) => {
(block_start_margin.collapse(), block_end_margin.collapse()) (block_start_margin.collapse(), block_end_margin.collapse())
} }
@ -1581,6 +1581,10 @@ impl Flow for BlockFlow {
} else if self.is_float() { } else if self.is_float() {
debug!("assign_block_size_float: assigning block_size for float"); debug!("assign_block_size_float: assigning block_size for float");
self.assign_block_size_float(ctx); self.assign_block_size_float(ctx);
} else if self.is_root() {
// Root element margins should never be collapsed according to CSS § 8.3.1.
debug!("assign_block_size: assigning block_size for root flow");
self.assign_block_size_block_base(ctx, MarginsMayNotCollapse);
} else { } else {
debug!("assign_block_size: assigning block_size for block"); debug!("assign_block_size: assigning block_size for block");
self.assign_block_size_block_base(ctx, MarginsMayCollapse); self.assign_block_size_block_base(ctx, MarginsMayCollapse);

View file

@ -93,3 +93,4 @@ flaky_cpu == linebreak_simple_a.html linebreak_simple_b.html
== line_height_a.html line_height_ref.html == line_height_a.html line_height_ref.html
== block_replaced_content_a.html block_replaced_content_ref.html == block_replaced_content_a.html block_replaced_content_ref.html
== block_replaced_content_b.html block_replaced_content_ref.html == block_replaced_content_b.html block_replaced_content_ref.html
== root_margin_collapse_a.html root_margin_collapse_b.html

View file

@ -0,0 +1,5 @@
<html style="margin-top: 10px;">
<body style="margin-top: 10px;">
<div style="width: 100px; height: 100px; background: black;"></div>
</body>
</html>

View file

@ -0,0 +1,5 @@
<html>
<body style="margin-top: 20px;">
<div style="width: 100px; height: 100px; background: black;"></div>
</body>
</html>