From 69e5bd2e3d8887e6e4aa192d8e1d2ce1422eddb8 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 17 Aug 2015 16:41:47 -0700 Subject: [PATCH] layout: Use the value of the `max-width` property when speculating what the inline sizes of block formatting contexts are likely to be. Usually, Web developers set this property on block formatting contexts in order to avoid running into floats, and we can use this as a speculation hint. Fixes the width of the search box on the Google SERPs. --- components/layout/block.rs | 14 +++++++--- tests/ref/basic.list | 1 + .../block_formatting_context_max_width_a.html | 24 +++++++++++++++++ ...lock_formatting_context_max_width_ref.html | 27 +++++++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tests/ref/block_formatting_context_max_width_a.html create mode 100644 tests/ref/block_formatting_context_max_width_ref.html diff --git a/components/layout/block.rs b/components/layout/block.rs index c73f97a821b..7a7d7d281cc 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1639,10 +1639,16 @@ impl Flow for BlockFlow { // We can't actually 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. - self.fragment.border_box.size.inline = - self.fragment.border_box.size.inline - - self.inline_size_of_preceding_left_floats - - self.inline_size_of_preceding_right_floats; + // + // (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 { + self.fragment.border_box.size.inline = + self.fragment.border_box.size.inline - + self.inline_size_of_preceding_left_floats - + self.inline_size_of_preceding_right_floats; + } } FormattingContextType::Other => { self.base.flags.remove(IMPACTED_BY_LEFT_FLOATS); diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 465e1ea4501..6e859e3fa6d 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -44,6 +44,7 @@ flaky_cpu == append_style_a.html append_style_b.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_float_placement_a.html block_formatting_context_float_placement_ref.html +== block_formatting_context_max_width_a.html block_formatting_context_max_width_ref.html == block_formatting_context_relative_a.html block_formatting_context_ref.html == block_formatting_context_translation_a.html block_formatting_context_translation_ref.html == block_formatting_context_with_margin_a.html block_formatting_context_with_margin_ref.html diff --git a/tests/ref/block_formatting_context_max_width_a.html b/tests/ref/block_formatting_context_max_width_a.html new file mode 100644 index 00000000000..94cdedd3782 --- /dev/null +++ b/tests/ref/block_formatting_context_max_width_a.html @@ -0,0 +1,24 @@ + + +
+ diff --git a/tests/ref/block_formatting_context_max_width_ref.html b/tests/ref/block_formatting_context_max_width_ref.html new file mode 100644 index 00000000000..3c40d312253 --- /dev/null +++ b/tests/ref/block_formatting_context_max_width_ref.html @@ -0,0 +1,27 @@ + + +
+