Replace usages of SplitBoxResult with option types

This commit is contained in:
Brendan Zabarauskas 2014-05-19 11:53:17 -07:00
parent 28e3c17340
commit 3d757cd9ce
2 changed files with 23 additions and 50 deletions

View file

@ -266,16 +266,6 @@ impl UnscannedTextBoxInfo {
}
}
/// Represents the outcome of attempting to split a box.
pub enum SplitBoxResult {
CannotSplit,
// in general, when splitting the left or right side can
// be zero length, due to leading/trailing trimmable whitespace
SplitDidFit(Option<Box>, Option<Box>),
SplitDidNotFit(Option<Box>, Option<Box>)
}
/// A box that represents a table column.
#[deriving(Clone)]
pub struct TableColumnBoxInfo {
@ -1097,10 +1087,10 @@ impl Box {
}
/// Split box which includes new-line character
pub fn split_by_new_line(&self) -> SplitBoxResult {
pub fn split_by_new_line(&self) -> Option<(Box, Option<Box>)> {
match self.specific {
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
TableRowBox | TableWrapperBox => CannotSplit,
TableRowBox | TableWrapperBox => None,
TableColumnBox(_) => fail!("Table column boxes do not need to split"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"),
ScannedTextBox(ref text_box_info) => {
@ -1117,7 +1107,7 @@ impl Box {
let new_metrics = new_text_box_info.run.metrics_for_range(&left_range);
let mut new_box = self.transform(new_metrics.bounding_box.size, ScannedTextBox(new_text_box_info));
new_box.new_line_pos = vec!();
Some(new_box)
new_box
};
// Right box is for right text of first founded new-line character.
@ -1131,16 +1121,16 @@ impl Box {
None
};
SplitDidFit(left_box, right_box)
Some((left_box, right_box))
}
}
}
/// Attempts to split this box so that its width is no more than `max_width`.
pub fn split_to_width(&self, max_width: Au, starts_line: bool) -> SplitBoxResult {
pub fn split_to_width(&self, max_width: Au, starts_line: bool) -> Option<(Option<Box>, Option<Box>)> {
match self.specific {
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
TableRowBox | TableWrapperBox => CannotSplit,
TableRowBox | TableWrapperBox => None,
TableColumnBox(_) => fail!("Table column boxes do not have width"),
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"),
ScannedTextBox(ref text_box_info) => {
@ -1231,10 +1221,10 @@ impl Box {
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
});
if pieces_processed_count == 1 || left_box.is_none() {
SplitDidNotFit(left_box, right_box)
if (pieces_processed_count == 1 || left_box.is_none()) && !starts_line {
None
} else {
SplitDidFit(left_box, right_box)
Some((left_box, right_box))
}
}
}

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use css::node_style::StyledNode;
use layout::box_::{Box, CannotSplit, SplitDidFit, SplitDidNotFit};
use layout::box_::Box;
use layout::context::LayoutContext;
use layout::floats::{FloatLeft, Floats, PlacementInfo};
use layout::flow::{BaseFlow, FlowClass, Flow, InlineFlowClass};
@ -425,19 +425,16 @@ impl LineboxScanner {
} else {
// In case of box includes new-line character
match in_box.split_by_new_line() {
SplitDidFit(left, right) => {
match (left, right) {
(Some(left_box), Some(right_box)) => {
self.push_box_to_line(left_box);
self.work_list.push_front(right_box);
}
(Some(left_box), None) => {
self.push_box_to_line(left_box);
}
_ => error!("LineboxScanner: This split case makes no sense!"),
}
}
_ => {}
Some((left_box, Some(right_box))) => {
self.push_box_to_line(left_box);
self.work_list.push_front(right_box);
},
Some((left_box, None)) => {
self.push_box_to_line(left_box);
},
None => {
error!("LineboxScanner: This split case makes no sense!")
},
}
false
}
@ -496,30 +493,16 @@ impl LineboxScanner {
let available_width = green_zone.width - self.pending_line.bounds.size.width;
let split = in_box.split_to_width(available_width, line_is_empty);
let (left, right) = match (split, line_is_empty) {
(CannotSplit, _) => {
let (left, right) = match split {
None => {
debug!("LineboxScanner: Tried to split unsplittable render box! {}",
in_box);
self.work_list.push_front(in_box);
return false
}
(SplitDidNotFit(_, _), false) => {
debug!("LineboxScanner: case=split box didn't fit, not appending and deferring \
original box.");
self.work_list.push_front(in_box);
return false
}
(SplitDidFit(left, right), _) => {
Some((left, right)) => {
debug!("LineboxScanner: case=split box did fit; deferring remainder box.");
(left, right)
// Fall through to push boxes to the line.
}
(SplitDidNotFit(left, right), true) => {
// TODO(eatkinson, issue #224): Signal that horizontal overflow happened?
debug!("LineboxScanner: case=split box didn't fit and line {:u} is empty, so \
overflowing and deferring remainder box.",
self.lines.len());
(left, right)
// Fall though to push boxes to the line.
}
};