From 97de2c2afa0510cb9ba1ceb65cfb33b8ab70dda4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 14 Apr 2016 17:37:02 -0700 Subject: [PATCH 1/2] layout: Reset the speculated inline size of floats out to compensate for margins for all blocks, not just block formatting contexts. Partial fix for Reddit /r/rust. --- components/layout/floats.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 63fdc6da796..bd91acb657d 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -470,17 +470,22 @@ impl SpeculatedFloatPlacement { let block_flow = flow.as_block(); if block_flow.formatting_context_type() != FormattingContextType::None { *self = block_flow.base.speculated_float_placement_in; + } - if self.left > Au(0) || self.right > Au(0) { - let speculated_inline_content_edge_offsets = - block_flow.fragment.guess_inline_content_edge_offsets(); - if self.left > Au(0) && speculated_inline_content_edge_offsets.start > Au(0) { - self.left = self.left + speculated_inline_content_edge_offsets.start - } - if self.right > Au(0) && speculated_inline_content_edge_offsets.end > Au(0) { - self.right = self.right + speculated_inline_content_edge_offsets.end - } + if self.left > Au(0) || self.right > Au(0) { + let speculated_inline_content_edge_offsets = + block_flow.fragment.guess_inline_content_edge_offsets(); + if self.left > Au(0) && speculated_inline_content_edge_offsets.start > Au(0) { + self.left = self.left + speculated_inline_content_edge_offsets.start } + if self.right > Au(0) && speculated_inline_content_edge_offsets.end > Au(0) { + self.right = self.right + speculated_inline_content_edge_offsets.end + } + } + + if block_flow.formatting_context_type() == FormattingContextType::None { + self.left = max(self.left, block_flow.base.speculated_float_placement_in.left); + self.right = max(self.right, block_flow.base.speculated_float_placement_in.right); } } From 6b6587a73bbc9980e395268869f7e9164b29691c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 14 Apr 2016 17:41:58 -0700 Subject: [PATCH 2/2] layout: Translate floats flowing out of blocks to compensate for inline direction margins. Improves Reddit /r/rust. --- components/layout/block.rs | 6 ++++- tests/wpt/mozilla/meta/MANIFEST.json | 24 +++++++++++++++++ .../tests/css/floats_inline_margins_a.html | 27 +++++++++++++++++++ .../tests/css/floats_inline_margins_ref.html | 24 +++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/wpt/mozilla/tests/css/floats_inline_margins_a.html create mode 100644 tests/wpt/mozilla/tests/css/floats_inline_margins_ref.html diff --git a/components/layout/block.rs b/components/layout/block.rs index fa91b847b20..0b10ef39000 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1020,8 +1020,12 @@ impl BlockFlow { self.base.position.size.block = cur_b; } - // Store the current set of floats in the flow so that flows that come later in the + // Translate the current set of floats back into the parent coordinate system in the + // inline direction, and store them in the flow so that flows that come later in the // document can access them. + floats.translate(LogicalSize::new(writing_mode, + self.fragment.inline_start_offset(), + Au(0))); self.base.floats = floats.clone(); self.adjust_fragments_for_collapsed_margins_if_root(layout_context); } else { diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 4285757014f..be3c9a95e51 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -1608,6 +1608,18 @@ "url": "/_mozilla/css/floated_table_with_margin_a.html" } ], + "css/floats_inline_margins_a.html": [ + { + "path": "css/floats_inline_margins_a.html", + "references": [ + [ + "/_mozilla/css/floats_inline_margins_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/floats_inline_margins_a.html" + } + ], "css/floats_margin_collapse_a.html": [ { "path": "css/floats_margin_collapse_a.html", @@ -8336,6 +8348,18 @@ "url": "/_mozilla/css/floated_table_with_margin_a.html" } ], + "css/floats_inline_margins_a.html": [ + { + "path": "css/floats_inline_margins_a.html", + "references": [ + [ + "/_mozilla/css/floats_inline_margins_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/floats_inline_margins_a.html" + } + ], "css/floats_margin_collapse_a.html": [ { "path": "css/floats_margin_collapse_a.html", diff --git a/tests/wpt/mozilla/tests/css/floats_inline_margins_a.html b/tests/wpt/mozilla/tests/css/floats_inline_margins_a.html new file mode 100644 index 00000000000..19b4910e6e0 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/floats_inline_margins_a.html @@ -0,0 +1,27 @@ + + + + + + + +
+

submitted

+

x

+ + + diff --git a/tests/wpt/mozilla/tests/css/floats_inline_margins_ref.html b/tests/wpt/mozilla/tests/css/floats_inline_margins_ref.html new file mode 100644 index 00000000000..38da254f7d6 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/floats_inline_margins_ref.html @@ -0,0 +1,24 @@ + + + + + + +
+

submitted

+

x

+ + +