mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Make whitespace preservation computation recursive in order to fix lifetime issues
This commit is contained in:
parent
42058681a5
commit
0d6c60f03e
1 changed files with 45 additions and 25 deletions
|
@ -348,33 +348,53 @@ where
|
||||||
if !text.starts_with(|c: char| c.is_ascii_whitespace()) {
|
if !text.starts_with(|c: char| c.is_ascii_whitespace()) {
|
||||||
return (false, text);
|
return (false, text);
|
||||||
}
|
}
|
||||||
let mut inline_level_boxes = self.current_inline_level_boxes().iter().rev();
|
|
||||||
let mut stack = Vec::new();
|
let preserved = match whitespace_is_preserved(self.current_inline_level_boxes()) {
|
||||||
let preserved = loop {
|
WhitespacePreservedResult::Unknown => {
|
||||||
let inline_box = match inline_level_boxes.next() {
|
// Paragraph start.
|
||||||
Some(box_) => box_,
|
false
|
||||||
None => match stack.pop() {
|
|
||||||
Some(iter) => {
|
|
||||||
inline_level_boxes = iter;
|
|
||||||
continue;
|
|
||||||
},
|
},
|
||||||
None => break false,
|
WhitespacePreservedResult::NotPreserved => false,
|
||||||
|
WhitespacePreservedResult::Preserved => true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let text = text.trim_start_matches(|c: char| c.is_ascii_whitespace());
|
||||||
|
return (preserved, text);
|
||||||
|
|
||||||
|
fn whitespace_is_preserved(
|
||||||
|
inline_level_boxes: &[ArcRefCell<InlineLevelBox>],
|
||||||
|
) -> WhitespacePreservedResult {
|
||||||
|
for inline_level_box in inline_level_boxes.iter().rev() {
|
||||||
|
match *inline_level_box.borrow() {
|
||||||
|
InlineLevelBox::TextRun(ref r) => {
|
||||||
|
if r.text.ends_with(' ') {
|
||||||
|
return WhitespacePreservedResult::NotPreserved;
|
||||||
|
}
|
||||||
|
return WhitespacePreservedResult::Preserved;
|
||||||
|
},
|
||||||
|
InlineLevelBox::Atomic { .. } => {
|
||||||
|
return WhitespacePreservedResult::NotPreserved;
|
||||||
},
|
},
|
||||||
};{
|
|
||||||
match &*inline_box.borrow() {
|
|
||||||
InlineLevelBox::TextRun(r) => break !r.text.ends_with(' '),
|
|
||||||
InlineLevelBox::Atomic { .. } => break false,
|
|
||||||
InlineLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
|
InlineLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
|
||||||
InlineLevelBox::OutOfFlowFloatBox(_) => {},
|
InlineLevelBox::OutOfFlowFloatBox(_) => {},
|
||||||
InlineLevelBox::InlineBox(b) => {
|
InlineLevelBox::InlineBox(ref b) => {
|
||||||
stack.push(inline_level_boxes);
|
match whitespace_is_preserved(&b.children) {
|
||||||
inline_level_boxes = b.children.iter().rev()
|
WhitespacePreservedResult::Unknown => {},
|
||||||
|
result => return result,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};}
|
}
|
||||||
()
|
}
|
||||||
};
|
|
||||||
let text = text.trim_start_matches(|c: char| c.is_ascii_whitespace());
|
WhitespacePreservedResult::Unknown
|
||||||
(preserved, text)
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
|
enum WhitespacePreservedResult {
|
||||||
|
Preserved,
|
||||||
|
NotPreserved,
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_inline_level_element(
|
fn handle_inline_level_element(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue