Don't strip out all empty fragments

Empty fragments may need to be layed out to draw borders, padding/background,
and insertion points.  (Fragments that consist of discardable whitespace and
control characters, on the other hand, can still be discarded.)

This ends up preserving some useless empty fragments.  It's possible we could
avoid this by storing some sort of flag on "important" empty fragments, so we
can discard the rest.
This commit is contained in:
Matt Brubeck 2016-04-15 16:00:07 -07:00
parent 1807fd3cc5
commit 1695d14a9e
3 changed files with 8 additions and 11 deletions

View file

@ -1861,6 +1861,7 @@ fn control_chars_to_fragment(node: &InlineFragmentNodeInfo,
let info = SpecificFragmentInfo::UnscannedText(
box UnscannedTextFragmentInfo::new(String::from(text), None));
let mut style = node.style.clone();
properties::modify_style_for_replaced_content(&mut style);
properties::modify_style_for_text(&mut style);
Fragment::from_opaque_node_and_style(node.address,
node.pseudo,

View file

@ -173,6 +173,7 @@ impl TextRunScanner {
let mut insertion_point = None;
for (fragment_index, in_fragment) in self.clump.iter().enumerate() {
debug!(" flushing {:?}", in_fragment);
let mut mapping = RunMapping::new(&run_info_list[..], &run_info, fragment_index);
let text;
let selection;
@ -239,7 +240,6 @@ impl TextRunScanner {
mapping.flush(&mut mappings,
&mut run_info,
&**text,
insertion_point,
compression,
text_transform,
&mut last_whitespace,
@ -269,7 +269,6 @@ impl TextRunScanner {
mapping.flush(&mut mappings,
&mut run_info,
&**text,
insertion_point,
compression,
text_transform,
&mut last_whitespace,
@ -606,15 +605,12 @@ impl RunMapping {
mappings: &mut Vec<RunMapping>,
run_info: &mut RunInfo,
text: &str,
insertion_point: Option<CharIndex>,
compression: CompressionMode,
text_transform: text_transform::T,
last_whitespace: &mut bool,
start_position: &mut usize,
end_position: usize) {
if *start_position == end_position && insertion_point.is_none() {
return;
}
let was_empty = *start_position == end_position;
let old_byte_length = run_info.text.len();
*last_whitespace = util::transform_text(&text[(*start_position)..end_position],
compression,
@ -633,8 +629,11 @@ impl RunMapping {
run_info.character_length = run_info.character_length + character_count;
*start_position = end_position;
// Don't flush mappings that contain no characters and no insertion_point.
if character_count == 0 && !self.contains_insertion_point(insertion_point) {
// Don't save mappings that contain only discarded characters.
// (But keep ones that contained no characters to begin with, since they might have been
// generated by an empty flow to draw its borders/padding/insertion point.)
let is_empty = character_count == 0;
if is_empty && !was_empty {
return;
}

View file

@ -1,3 +0,0 @@
[bidi-011.htm]
type: reftest
expected: FAIL