From 8a90cda09f3bcb7ffc40eb456aefddb2495f1ff6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 11 Jan 2017 23:29:56 +0000 Subject: [PATCH] Do not replace an ellipsis when reflowing a line The ellipsis should be replaced, if needed, when the text itself is reflowed. --- components/layout/fragment.rs | 15 ++++++++++----- components/layout/inline.rs | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 9ac181c432a..09cebfae17f 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -764,14 +764,17 @@ impl Fragment { text_overflow_string: String) -> Fragment { let mut unscanned_ellipsis_fragments = LinkedList::new(); - unscanned_ellipsis_fragments.push_back(self.transform( - self.border_box.size, - SpecificFragmentInfo::UnscannedText( - box UnscannedTextFragmentInfo::new(text_overflow_string, None)))); + let mut ellipsis_fragment = self.transform( + self.border_box.size, + SpecificFragmentInfo::UnscannedText( + box UnscannedTextFragmentInfo::new(text_overflow_string, None))); + unscanned_ellipsis_fragments.push_back(ellipsis_fragment); let ellipsis_fragments = TextRunScanner::new().scan_for_runs(&mut layout_context.font_context(), unscanned_ellipsis_fragments); debug_assert!(ellipsis_fragments.len() == 1); - ellipsis_fragments.fragments.into_iter().next().unwrap() + ellipsis_fragment = ellipsis_fragments.fragments.into_iter().next().unwrap(); + ellipsis_fragment.flags |= IS_ELLIPSIS; + ellipsis_fragment } pub fn restyle_damage(&self) -> RestyleDamage { @@ -2997,6 +3000,8 @@ bitflags! { const IS_INLINE_FLEX_ITEM = 0b0000_0001, /// Whether this fragment represents a child in a column flex container. const IS_BLOCK_FLEX_ITEM = 0b0000_0010, + /// Whether this fragment represents the generated text from a text-overflow clip. + const IS_ELLIPSIS = 0b0000_0100, } } diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 2d591b1ee02..47e1da7b2bb 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -15,6 +15,7 @@ use flow::{CONTAINS_TEXT_OR_REPLACED_FRAGMENTS, EarlyAbsolutePositionInfo, Mutab use flow::OpaqueFlow; use flow_ref::FlowRef; use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow}; +use fragment::IS_ELLIPSIS; use fragment::SpecificFragmentInfo; use gfx::display_list::OpaqueNode; use gfx::font::FontMetrics; @@ -331,6 +332,16 @@ impl LineBreaker { None => break, Some(fragment) => fragment, }; + + // If ellipsis are still needed, then they were already needed for the previous fragment. + if fragment.flags.contains(IS_ELLIPSIS) { + continue + } + + // If ellipsis are still needed, then they were already needed for the previous fragment. + if fragment.flags.contains(IS_ELLIPSIS) { + continue + } // Try to append the fragment. self.reflow_fragment(fragment, flow, layout_context);