Clarify the invariants for InlineFlow's elems mapping. Only create NodeRanges for non-leaf elements in the inline flow. Fix the range length recorded in the NodeRanges.

This commit is contained in:
Brian J. Burg 2012-10-11 14:42:47 -07:00
parent 17e1780f86
commit be53bb14f7
2 changed files with 15 additions and 13 deletions

View file

@ -139,8 +139,8 @@ impl BoxConsumer {
match self.flow { match self.flow {
@InlineFlow(*) => { @InlineFlow(*) => {
if box.requires_inline_spacers() { if box.requires_inline_spacers() {
do box.create_inline_spacer_for_side(ctx, LogicalBefore).iter |b: &@RenderBox| { do box.create_inline_spacer_for_side(ctx, LogicalBefore).iter |spacer: &@RenderBox| {
self.flow.inline().boxes.push(*b); self.flow.inline().boxes.push(*spacer);
} }
} }
}, },
@ -160,29 +160,31 @@ impl BoxConsumer {
match self.flow { match self.flow {
@InlineFlow(*) => { @InlineFlow(*) => {
let pre_length = self.flow.inline().boxes.len() - entry.start_idx; let span_length = self.flow.inline().boxes.len() - entry.start_idx + 1;
match (pre_length, box.requires_inline_spacers()) { match (span_length, box.requires_inline_spacers()) {
// leaf box // leaf box
(0, _) => { self.flow.inline().boxes.push(box); }, (1, _) => { self.flow.inline().boxes.push(box); return; },
// if this non-leaf box generates extra horizontal // if this non-leaf box generates extra horizontal
// spacing, add a SpacerBox for it. // spacing, add a SpacerBox for it.
(_, true) => { (_, true) => {
do box.create_inline_spacer_for_side(ctx, LogicalAfter).iter |b: &@RenderBox| { do box.create_inline_spacer_for_side(ctx, LogicalAfter).iter |spacer: &@RenderBox| {
self.flow.inline().boxes.push(*b); self.flow.inline().boxes.push(*spacer);
} }
}, },
// non-leaf with no spacer; do nothing // non-leaf with no spacer; do nothing
(_, false) => { } (_, false) => { }
} }
let post_length = self.flow.inline().boxes.len() - entry.start_idx; // only create NodeRanges for non-leaf nodes.
let final_span_length = self.flow.inline().boxes.len() - entry.start_idx + 1;
assert final_span_length > 1;
let mapping = { node: copy box.d().node, let mapping = { node: copy box.d().node,
span: { span: {
start: entry.start_idx as u8, start: entry.start_idx as u8,
len: post_length as u8 len: final_span_length as u8
} }
}; };
debug!("BoxConsumer: adding element range %?", mapping.span); debug!("BoxConsumer: adding element range=%?", mapping.span);
self.flow.inline().elems.push(mapping); self.flow.inline().elems.push(mapping);
}, },
@BlockFlow(*) => { @BlockFlow(*) => {

View file

@ -193,9 +193,9 @@ struct InlineFlowData {
// vec of ranges into boxes that represents line positions. // vec of ranges into boxes that represents line positions.
// these ranges are disjoint, and are the result of inline layout. // these ranges are disjoint, and are the result of inline layout.
lines: DVec<BoxRange>, lines: DVec<BoxRange>,
// vec of ranges into boxes that represent elements. These // vec of ranges into boxes that represent elements. These ranges
// ranges must be disjoint or well-nested, and are only related to // must be well-nested, and are only related to the content of
// the content of boxes (not lines) // boxes (not lines). Ranges are only kept for non-leaf elements.
elems: DVec<NodeRange> elems: DVec<NodeRange>
} }