From 3a56cc7f2f123fed90729f3160702e30352c9d27 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 27 Sep 2016 18:28:03 -0700 Subject: [PATCH 1/3] layout: When searching for the baseline offset of the last in-flow line and an inline flow has no applicable lines, continue checking previous sibling flows. Improves Twitter by placing the favorite icon in the right place. --- components/layout/flow.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 36b8da6cc48..af6448547d7 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -1402,7 +1402,9 @@ impl<'a> ImmutableFlowUtils for &'a Flow { fn baseline_offset_of_last_line_box_in_flow(self) -> Option { for kid in base(self).children.iter().rev() { if kid.is_inline_flow() { - return kid.as_inline().baseline_offset_of_last_line() + if let Some(baseline_offset) = kid.as_inline().baseline_offset_of_last_line() { + return Some(baseline_offset) + } } if kid.is_block_like() && kid.as_block().formatting_context_type() == FormattingContextType::None && From 0803ef98e3f70a51f8a7b27c49adad60df4d9e8d Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 27 Sep 2016 18:26:40 -0700 Subject: [PATCH 2/3] layout: Don't count lines that consist solely of hypothetical boxes when determining the baseline offset of the last line. Improves Twitter by placing the favorite icon in the right place vertically. --- components/layout/inline.rs | 13 ++++++---- tests/wpt/mozilla/meta/MANIFEST.json | 24 +++++++++++++++++++ ...line_absolute_hypothetical_baseline_a.html | 10 ++++++++ ...ne_absolute_hypothetical_baseline_ref.html | 4 ++++ 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_a.html create mode 100644 tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_ref.html diff --git a/components/layout/inline.rs b/components/layout/inline.rs index d1d50b22fe4..bae35f7cac5 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -1262,13 +1262,16 @@ impl InlineFlow { } pub fn baseline_offset_of_last_line(&self) -> Option { - match self.lines.last() { - None => None, - Some(ref last_line) => { - Some(last_line.bounds.start.b + last_line.bounds.size.block - - last_line.inline_metrics.depth_below_baseline) + // Find the last line that doesn't consist entirely of hypothetical boxes. + for line in self.lines.iter().rev() { + if (line.range.begin().get()..line.range.end().get()).any(|index| { + !self.fragments.fragments[index as usize].is_hypothetical() + }) { + return Some(line.bounds.start.b + line.bounds.size.block - + line.inline_metrics.depth_below_baseline) } } + None } } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index fc7ee02cb96..208db196a24 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -2372,6 +2372,18 @@ "url": "/_mozilla/css/incremental_visibility_a.html" } ], + "css/inline_absolute_hypothetical_baseline_a.html": [ + { + "path": "css/inline_absolute_hypothetical_baseline_a.html", + "references": [ + [ + "/_mozilla/css/inline_absolute_hypothetical_baseline_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/inline_absolute_hypothetical_baseline_a.html" + } + ], "css/inline_absolute_hypothetical_clip_a.html": [ { "path": "css/inline_absolute_hypothetical_clip_a.html", @@ -16010,6 +16022,18 @@ "url": "/_mozilla/css/incremental_visibility_a.html" } ], + "css/inline_absolute_hypothetical_baseline_a.html": [ + { + "path": "css/inline_absolute_hypothetical_baseline_a.html", + "references": [ + [ + "/_mozilla/css/inline_absolute_hypothetical_baseline_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/inline_absolute_hypothetical_baseline_a.html" + } + ], "css/inline_absolute_hypothetical_clip_a.html": [ { "path": "css/inline_absolute_hypothetical_clip_a.html", diff --git a/tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_a.html b/tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_a.html new file mode 100644 index 00000000000..c54a2c36990 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_a.html @@ -0,0 +1,10 @@ + + + + +
+
A
+ B +
+C +D diff --git a/tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_ref.html b/tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_ref.html new file mode 100644 index 00000000000..e5c686e02a5 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/inline_absolute_hypothetical_baseline_ref.html @@ -0,0 +1,4 @@ + + +
A C D
+
B
From b021952be9c556cb55ade993d0781d8a3f9b46aa Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 27 Sep 2016 18:29:27 -0700 Subject: [PATCH 3/3] layout: Remove a stray newline. --- components/layout/inline.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/components/layout/inline.rs b/components/layout/inline.rs index bae35f7cac5..434d5200da8 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -1454,7 +1454,6 @@ impl Flow for InlineFlow { self.minimum_depth_below_baseline); scanner.scan_for_lines(self, layout_context); - // Now, go through each line and lay out the fragments inside. let line_count = self.lines.len(); for (line_index, line) in self.lines.iter_mut().enumerate() {