aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2020-03-13 19:32:24 -0700
committerPatrick Walton <pcwalton@mimiga.net>2020-03-17 20:13:57 -0700
commit0d6c60f03ed6829dc02fc16fb3e43482f0ab1ae7 (patch)
treec3d15a51fadf5ae5ae89f21c1c346337f7e07273
parent42058681a5d04ca4203bac4fc8c60547a8fed2f8 (diff)
downloadservo-0d6c60f03ed6829dc02fc16fb3e43482f0ab1ae7.tar.gz
servo-0d6c60f03ed6829dc02fc16fb3e43482f0ab1ae7.zip
Make whitespace preservation computation recursive in order to fix lifetime issues
-rw-r--r--components/layout_2020/flow/construct.rs70
1 files changed, 45 insertions, 25 deletions
diff --git a/components/layout_2020/flow/construct.rs b/components/layout_2020/flow/construct.rs
index 89a54d08840..0bf0b5c83ad 100644
--- a/components/layout_2020/flow/construct.rs
+++ b/components/layout_2020/flow/construct.rs
@@ -348,33 +348,53 @@ where
if !text.starts_with(|c: char| c.is_ascii_whitespace()) {
return (false, text);
}
- let mut inline_level_boxes = self.current_inline_level_boxes().iter().rev();
- let mut stack = Vec::new();
- let preserved = loop {
- let inline_box = match inline_level_boxes.next() {
- Some(box_) => box_,
- None => match stack.pop() {
- Some(iter) => {
- inline_level_boxes = iter;
- continue;
- },
- None => break false,
- },
- };{
- match &*inline_box.borrow() {
- InlineLevelBox::TextRun(r) => break !r.text.ends_with(' '),
- InlineLevelBox::Atomic { .. } => break false,
- InlineLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
- InlineLevelBox::OutOfFlowFloatBox(_) => {},
- InlineLevelBox::InlineBox(b) => {
- stack.push(inline_level_boxes);
- inline_level_boxes = b.children.iter().rev()
- },
- };}
- ()
+
+ let preserved = match whitespace_is_preserved(self.current_inline_level_boxes()) {
+ WhitespacePreservedResult::Unknown => {
+ // Paragraph start.
+ false
+ },
+ WhitespacePreservedResult::NotPreserved => false,
+ WhitespacePreservedResult::Preserved => true,
};
+
let text = text.trim_start_matches(|c: char| c.is_ascii_whitespace());
- (preserved, text)
+ 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;
+ },
+ InlineLevelBox::OutOfFlowAbsolutelyPositionedBox(_) |
+ InlineLevelBox::OutOfFlowFloatBox(_) => {},
+ InlineLevelBox::InlineBox(ref b) => {
+ match whitespace_is_preserved(&b.children) {
+ WhitespacePreservedResult::Unknown => {},
+ result => return result,
+ }
+ },
+ }
+ }
+
+ WhitespacePreservedResult::Unknown
+ }
+
+ #[derive(Clone, Copy, PartialEq)]
+ enum WhitespacePreservedResult {
+ Preserved,
+ NotPreserved,
+ Unknown,
+ }
}
fn handle_inline_level_element(