From 8823f87276cf19ec52cb5e61118a7c17ffaf53a6 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 27 Apr 2016 12:40:58 -0700 Subject: [PATCH] layout: Don't pretend inline fragment sizes are zero when placing them between floats. --- components/gfx/text/text_run.rs | 9 ++++++++- components/layout/fragment.rs | 11 +++++++++++ components/layout/inline.rs | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index 10cced11166..7dd0b027839 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -272,7 +272,14 @@ impl<'a> TextRun { }) } - /// Returns the index of the first glyph run containing the given byte index. + pub fn minimum_splittable_inline_size(&self, range: &Range) -> Au { + match self.natural_word_slices_in_range(range).next() { + None => Au(0), + Some(slice) => self.advance_for_range(&slice.range), + } + } + + /// Returns the index of the first glyph run containing the given character index. fn index_of_first_glyph_run_containing(&self, index: ByteIndex) -> Option { let self_ptr = self as *const TextRun; INDEX_OF_FIRST_GLYPH_RUN_CACHE.with(|index_of_first_glyph_run_cache| { diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index f90a18a438d..67ced630250 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1471,6 +1471,17 @@ impl Fragment { result } + /// Returns the narrowest inline-size that the first splittable part of this fragment could + /// possibly be split to. (In most cases, this returns the inline-size of the first word in + /// this fragment.) + pub fn minimum_splittable_inline_size(&self) -> Au { + match self.specific { + SpecificFragmentInfo::ScannedText(ref text) => { + text.run.minimum_splittable_inline_size(&text.range) + } + _ => Au(0), + } + } /// TODO: What exactly does this function return? Why is it Au(0) for /// `SpecificFragmentInfo::Generic`? diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 95c3c85454a..17fdfc82937 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -444,7 +444,7 @@ impl LineBreaker { // Initially, pretend a splittable fragment has zero inline-size. We will move it later if // it has nonzero inline-size and that causes problems. let placement_inline_size = if first_fragment.can_split() { - Au(0) + first_fragment.minimum_splittable_inline_size() } else { first_fragment.margin_box_inline_size() + self.indentation_for_pending_fragment() };