Skip to content

Commit

Permalink
layout: Correctly take the inline size of cleared floats into account
Browse files Browse the repository at this point in the history
when estimating the inline size of block formatting contexts.

The speculated inline-size of the preceding floats was forced to zero at
the wrong time if the float was itself cleared, causing it to overwrite
the speculated value. Shuffling the code around a bit fixes the problem.
  • Loading branch information
pcwalton committed Apr 7, 2015
1 parent 3c5c2f4 commit e10af4f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
21 changes: 11 additions & 10 deletions components/layout/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,17 @@ impl BlockFlow {
kid_base.fixed_static_i_offset = fixed_static_i_offset;
}

// Determine float impaction, and update the inline size speculations if necessary.
if flow::base(kid).flags.contains(CLEARS_LEFT) {
inline_start_floats_impact_child = false;
inline_size_of_preceding_left_floats = Au(0);
}
if flow::base(kid).flags.contains(CLEARS_RIGHT) {
inline_end_floats_impact_child = false;
inline_size_of_preceding_right_floats = Au(0);
}

// Update the speculated inline size if this child is floated.
match flow::base(kid).flags.float_kind() {
float::T::none => {}
float::T::left => {
Expand Down Expand Up @@ -1353,16 +1364,6 @@ impl BlockFlow {
}
}

// Determine float impaction.
if flow::base(kid).flags.contains(CLEARS_LEFT) {
inline_start_floats_impact_child = false;
inline_size_of_preceding_left_floats = Au(0);
}
if flow::base(kid).flags.contains(CLEARS_RIGHT) {
inline_end_floats_impact_child = false;
inline_size_of_preceding_right_floats = Au(0);
}

{
let kid_base = flow::mut_base(kid);
inline_start_floats_impact_child = inline_start_floats_impact_child ||
Expand Down
1 change: 1 addition & 0 deletions tests/ref/basic.list
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ flaky_cpu == append_style_a.html append_style_b.html
== background_style_attr.html background_ref.html
== basic_width_px.html basic_width_em.html
== block_formatting_context_a.html block_formatting_context_ref.html
== block_formatting_context_cleared_float_a.html block_formatting_context_cleared_float_ref.html
== block_formatting_context_complex_a.html block_formatting_context_complex_ref.html
== block_formatting_context_containing_floats_a.html block_formatting_context_containing_floats_ref.html
== block_formatting_context_relative_a.html block_formatting_context_ref.html
Expand Down
28 changes: 28 additions & 0 deletions tests/ref/block_formatting_context_cleared_float_a.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<!--
Tests that block formatting context inline-size speculation works when the floats that impact
the block formatting context are cleared.
-->
<style>
#a {
background: silver;
height: 150px;
width: 150px;
float: right;
clear: right;
}
#b {
background: goldenrod;
height: 300px;
overflow: hidden;
}
</style>
</head>
<body>
<div id=a></div>
<div id=b></div>
</body>
</html>

27 changes: 27 additions & 0 deletions tests/ref/block_formatting_context_cleared_float_ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<!--
Tests that block formatting context inline-size speculation works when the floats that impact
the block formatting context are cleared.
-->
<style>
#a {
background: silver;
height: 150px;
width: 150px;
float: right;
}
#b {
background: goldenrod;
height: 300px;
overflow: hidden;
}
</style>
</head>
<body>
<div id=a></div>
<div id=b></div>
</body>
</html>

0 comments on commit e10af4f

Please sign in to comment.