mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Prevent margin collapse in the root flow
According to the CSS specification, section 8.3.1, margins of the root element's box do not collapse. Ensure that root flow margins do not collapse during the assign heights phase.
This commit is contained in:
parent
0e5d6dbac2
commit
65fce97f51
4 changed files with 17 additions and 2 deletions
|
@ -760,7 +760,7 @@ impl BlockFlow {
|
|||
}
|
||||
|
||||
/// 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
|
||||
/// better?
|
||||
|
@ -770,7 +770,7 @@ impl BlockFlow {
|
|||
}
|
||||
|
||||
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) => {
|
||||
(block_start_margin.collapse(), block_end_margin.collapse())
|
||||
}
|
||||
|
@ -1581,6 +1581,10 @@ impl Flow for BlockFlow {
|
|||
} else if self.is_float() {
|
||||
debug!("assign_block_size_float: assigning block_size for float");
|
||||
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 {
|
||||
debug!("assign_block_size: assigning block_size for block");
|
||||
self.assign_block_size_block_base(ctx, MarginsMayCollapse);
|
||||
|
|
|
@ -93,3 +93,4 @@ flaky_cpu == linebreak_simple_a.html linebreak_simple_b.html
|
|||
== line_height_a.html line_height_ref.html
|
||||
== block_replaced_content_a.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
|
||||
|
|
5
src/test/ref/root_margin_collapse_a.html
Normal file
5
src/test/ref/root_margin_collapse_a.html
Normal 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>
|
5
src/test/ref/root_margin_collapse_b.html
Normal file
5
src/test/ref/root_margin_collapse_b.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body style="margin-top: 20px;">
|
||||
<div style="width: 100px; height: 100px; background: black;"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue