Skip to content

Commit

Permalink
Do not replace an ellipsis when reflowing a line
Browse files Browse the repository at this point in the history
The ellipsis should be replaced, if needed, when the text itself is reflowed.
  • Loading branch information
notriddle committed Jan 12, 2017
1 parent 783829e commit 8a90cda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 10 additions & 5 deletions components/layout/fragment.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}

Expand Down
11 changes: 11 additions & 0 deletions components/layout/inline.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8a90cda

Please sign in to comment.