aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/layout/block.rs8
-rw-r--r--src/test/ref/basic.list1
-rw-r--r--src/test/ref/root_margin_collapse_a.html5
-rw-r--r--src/test/ref/root_margin_collapse_b.html5
4 files changed, 17 insertions, 2 deletions
diff --git a/src/components/layout/block.rs b/src/components/layout/block.rs
index 50dfd7e3a3e..ea65756c7de 100644
--- a/src/components/layout/block.rs
+++ b/src/components/layout/block.rs
@@ -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);
diff --git a/src/test/ref/basic.list b/src/test/ref/basic.list
index 3a36b86aa4f..058e567068a 100644
--- a/src/test/ref/basic.list
+++ b/src/test/ref/basic.list
@@ -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
diff --git a/src/test/ref/root_margin_collapse_a.html b/src/test/ref/root_margin_collapse_a.html
new file mode 100644
index 00000000000..a3c98252be0
--- /dev/null
+++ b/src/test/ref/root_margin_collapse_a.html
@@ -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>
diff --git a/src/test/ref/root_margin_collapse_b.html b/src/test/ref/root_margin_collapse_b.html
new file mode 100644
index 00000000000..d7bdcf4e536
--- /dev/null
+++ b/src/test/ref/root_margin_collapse_b.html
@@ -0,0 +1,5 @@
+<html>
+ <body style="margin-top: 20px;">
+ <div style="width: 100px; height: 100px; background: black;"></div>
+ </body>
+</html>