Don't try to remove whitespace twice if it's the only node.

Fixes a failure on Wikipedia.
This commit is contained in:
Patrick Walton 2013-05-29 18:30:40 -07:00
parent 02c57728c5
commit dcfabb71d1

View file

@ -370,43 +370,46 @@ pub impl LayoutTreeBuilder {
// of its RenderBox or FlowContext children, and possibly keep alive other junk // of its RenderBox or FlowContext children, and possibly keep alive other junk
let parent_flow = parent_ctx.default_collector.flow; let parent_flow = parent_ctx.default_collector.flow;
let (first_child, last_child) = do parent_flow.with_base |parent_node| {
(parent_node.first_child, parent_node.last_child)
};
// check first/last child for whitespace-ness // check first/last child for whitespace-ness
let first_child = do parent_flow.with_base |parent_node| {
parent_node.first_child
};
for first_child.each |first_flow| { for first_child.each |first_flow| {
if first_flow.starts_inline_flow() { if first_flow.starts_inline_flow() {
// FIXME: workaround for rust#6393 // FIXME: workaround for rust#6393
let mut do_remove = false; let mut do_remove = false;
{ {
let boxes = &first_flow.inline().boxes; let boxes = &first_flow.inline().boxes;
if boxes.len() == 1 && boxes[0].is_whitespace_only() { if boxes.len() == 1 && boxes[0].is_whitespace_only() {
debug!("LayoutTreeBuilder: pruning whitespace-only first child flow \ debug!("LayoutTreeBuilder: pruning whitespace-only first child \
f%d from parent f%d", flow f%d from parent f%d",
first_flow.id(), first_flow.id(),
parent_flow.id()); parent_flow.id());
do_remove = true; do_remove = true;
} }
} }
if (do_remove) { if (do_remove) {
parent_flow.remove_child(*first_flow); parent_flow.remove_child(*first_flow);
} }
} }
} }
let last_child = do parent_flow.with_base |parent_node| {
parent_node.last_child
};
for last_child.each |last_flow| { for last_child.each |last_flow| {
if last_flow.starts_inline_flow() { if last_flow.starts_inline_flow() {
// FIXME: workaround for rust#6393 // FIXME: workaround for rust#6393
let mut do_remove = false; let mut do_remove = false;
{ {
let boxes = &last_flow.inline().boxes; let boxes = &last_flow.inline().boxes;
if boxes.len() == 1 && boxes.last().is_whitespace_only() { if boxes.len() == 1 && boxes.last().is_whitespace_only() {
debug!("LayoutTreeBuilder: pruning whitespace-only last child flow \ debug!("LayoutTreeBuilder: pruning whitespace-only last child \
f%d from parent f%d", flow f%d from parent f%d",
last_flow.id(), last_flow.id(),
parent_flow.id()); parent_flow.id());
do_remove = true; do_remove = true;
} }
} }
if (do_remove) { if (do_remove) {
parent_flow.remove_child(*last_flow); parent_flow.remove_child(*last_flow);