layout: Disable the speculation of block formatting contexts' inline

sizes if the block formatting contexts have negative margins.

The heuristics that determine how and whether floats flow into the
margins are not valid in that case.

Closes #13299.
This commit is contained in:
Patrick Walton 2016-09-16 18:25:59 -07:00
parent 1fee88e59c
commit b4aea115b8
4 changed files with 195 additions and 26 deletions

View file

@ -1666,33 +1666,40 @@ impl BlockFlow {
// Now compute the real value. // Now compute the real value.
self.propagate_and_compute_used_inline_size(shared_context); self.propagate_and_compute_used_inline_size(shared_context);
// Now for some speculation. self.guess_inline_size_for_block_formatting_context_if_necessary()
match self.formatting_context_type() { }
FormattingContextType::Block => {
// We can't actually compute the inline-size of this block now, because floats fn guess_inline_size_for_block_formatting_context_if_necessary(&mut self) {
// might affect it. Speculate that its inline-size is equal to the inline-size // We don't need to guess anything unless this is a block formatting context.
// computed above minus the inline-size of the previous left and/or right floats. if self.formatting_context_type() != FormattingContextType::Block {
// return
// (If `max-width` is set, then don't perform this speculation. We guess that the
// page set `max-width` in order to avoid hitting floats. The search box on Google
// SERPs falls into this category.)
if self.fragment.style.max_inline_size() == LengthOrPercentageOrNone::None {
let speculated_left_float_size =
max(Au(0),
self.base.speculated_float_placement_in.left -
self.fragment.margin.inline_start);
let speculated_right_float_size =
max(Au(0),
self.base.speculated_float_placement_in.right -
self.fragment.margin.inline_end);
self.fragment.border_box.size.inline =
self.fragment.border_box.size.inline -
speculated_left_float_size -
speculated_right_float_size;
}
}
FormattingContextType::None | FormattingContextType::Other => {}
} }
// If `max-width` is set, then don't perform this speculation. We guess that the
// page set `max-width` in order to avoid hitting floats. The search box on Google
// SERPs falls into this category.
if self.fragment.style.max_inline_size() != LengthOrPercentageOrNone::None {
return
}
// At this point, we know we can't precisely compute the inline-size of this block now,
// because floats might affect it. Speculate that its inline-size is equal to the
// inline-size computed above minus the inline-size of the previous left and/or right
// floats.
let speculated_left_float_size = if self.fragment.margin.inline_start >= Au(0) &&
self.base.speculated_float_placement_in.left > self.fragment.margin.inline_start {
self.base.speculated_float_placement_in.left - self.fragment.margin.inline_start
} else {
Au(0)
};
let speculated_right_float_size = if self.fragment.margin.inline_end >= Au(0) &&
self.base.speculated_float_placement_in.right > self.fragment.margin.inline_end {
self.base.speculated_float_placement_in.right - self.fragment.margin.inline_end
} else {
Au(0)
};
self.fragment.border_box.size.inline = self.fragment.border_box.size.inline -
speculated_left_float_size - speculated_right_float_size
} }
fn definitely_has_zero_block_size(&self) -> bool { fn definitely_has_zero_block_size(&self) -> bool {

View file

@ -652,6 +652,18 @@
"url": "/_mozilla/css/block_formatting_context_max_width_a.html" "url": "/_mozilla/css/block_formatting_context_max_width_a.html"
} }
], ],
"css/block_formatting_context_negative_margins_a.html": [
{
"path": "css/block_formatting_context_negative_margins_a.html",
"references": [
[
"/_mozilla/css/block_formatting_context_negative_margins_ref.html",
"=="
]
],
"url": "/_mozilla/css/block_formatting_context_negative_margins_a.html"
}
],
"css/block_formatting_context_overflow_a.html": [ "css/block_formatting_context_overflow_a.html": [
{ {
"path": "css/block_formatting_context_overflow_a.html", "path": "css/block_formatting_context_overflow_a.html",
@ -10058,6 +10070,18 @@
"url": "/_mozilla/css/block_formatting_context_max_width_a.html" "url": "/_mozilla/css/block_formatting_context_max_width_a.html"
} }
], ],
"css/block_formatting_context_negative_margins_a.html": [
{
"path": "css/block_formatting_context_negative_margins_a.html",
"references": [
[
"/_mozilla/css/block_formatting_context_negative_margins_ref.html",
"=="
]
],
"url": "/_mozilla/css/block_formatting_context_negative_margins_a.html"
}
],
"css/block_formatting_context_overflow_a.html": [ "css/block_formatting_context_overflow_a.html": [
{ {
"path": "css/block_formatting_context_overflow_a.html", "path": "css/block_formatting_context_overflow_a.html",

View file

@ -0,0 +1,69 @@
<!DOCTYPE html>
<html><head>
<!-- Original URL: http://fvsch.com/code/bugs/servo-negative-margins-width/ -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>Servo test case: wrong block width with negative margins and overflow</title>
<link rel="match" href="block_formatting_context_negative_margins_ref.html">
<style>
main {
border: solid 5px red;
margin: 20px;
padding: 5px 35px;
}
section {
margin: 0;
}
p {
margin: 0;
}
.test {
color: blue;
border: solid 5px;
padding: 5px;
margin: 5px -40px;
background-color: #00f1;
}
.w100 {
box-sizing: border-box;
width: 100%;
}
.test code {
visibility: hidden;
}
</style>
</head>
<body>
<main>
<h1>Servo test case: wrong block width with negative margins and overflow</h1>
<section>
<h2>With <code>width: auto</code></h2>
<p>The following blocks have negative margins on the sides. They
should end up being as large as the red container, with their left and
right borders should overlap the containers border.</p>
<p>In Servo Nightly 0.0.1-e3d946b (2016-09-16), when the value of <code>overflow</code> is not <code>visible</code>, the rendered width is wrong (as if a <code>box-sizing: border-box; width: 100%;</code> had been applied).</p>
<div class="test" style="overflow: visible;"></div>
<div class="test" style="overflow: scroll;"></div>
<div class="test" style="overflow: auto;"></div>
<div class="test" style="overflow-y: auto;"></div>
<div class="test" style="overflow: hidden;"></div>
</section>
<section>
<h2>With <code>box-sizing: border-box; width: 100%</code></h2>
<p>If we do use <code>box-sizing: border-box; width: 100%;</code>, for the <code>overflow: visible</code> block we get the expected rendering, but for the other values the width is wrong once again.</p>
<div class="test w100" style="overflow: visible;"></div>
<div class="test w100" style="overflow: scroll;"></div>
<div class="test w100" style="overflow: auto;"></div>
<div class="test w100" style="overflow-y: auto;"></div>
<div class="test w100" style="overflow: hidden;"></div>
</section>
</main>
</body></html>

View file

@ -0,0 +1,69 @@
<!DOCTYPE html>
<html><head>
<!-- Original URL: http://fvsch.com/code/bugs/servo-negative-margins-width/ -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<title>Servo test case: wrong block width with negative margins and overflow</title>
<style>
main {
border: solid 5px red;
margin: 20px;
padding: 5px 35px;
}
section {
margin: 0;
}
p {
margin: 0;
}
.test {
color: blue;
border: solid 5px;
padding: 5px;
margin: 5px -40px;
background-color: #00f1;
}
.w100 {
box-sizing: border-box;
width: 100%;
}
.test code {
visibility: hidden;
}
</style>
</head>
<body>
<main>
<h1>Servo test case: wrong block width with negative margins and overflow</h1>
<section>
<h2>With <code>width: auto</code></h2>
<p>The following blocks have negative margins on the sides. They
should end up being as large as the red container, with their left and
right borders should overlap the containers border.</p>
<p>In Servo Nightly 0.0.1-e3d946b (2016-09-16), when the value of <code>overflow</code> is not <code>visible</code>, the rendered width is wrong (as if a <code>box-sizing: border-box; width: 100%;</code> had been applied).</p>
<div class="test" style="overflow: visible;"></div>
<div class="test" style="overflow: visible;"></div>
<div class="test" style="overflow: visible;"></div>
<div class="test" style="overflow: visible;"></div>
<div class="test" style="overflow: visible;"></div>
</section>
<section>
<h2>With <code>box-sizing: border-box; width: 100%</code></h2>
<p>If we do use <code>box-sizing: border-box; width: 100%;</code>, for the <code>overflow: visible</code> block we get the expected rendering, but for the other values the width is wrong once again.</p>
<div class="test w100" style="overflow: visible;"></div>
<div class="test w100" style="overflow: visible;"></div>
<div class="test w100" style="overflow: visible;"></div>
<div class="test w100" style="overflow-y: visible;"></div>
<div class="test w100" style="overflow: visible;"></div>
</section>
</main>
</body></html>