mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Replace usages of SplitBoxResult with option types
This commit is contained in:
parent
28e3c17340
commit
3d757cd9ce
2 changed files with 23 additions and 50 deletions
|
@ -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.
|
/// A box that represents a table column.
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
pub struct TableColumnBoxInfo {
|
pub struct TableColumnBoxInfo {
|
||||||
|
@ -1097,10 +1087,10 @@ impl Box {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Split box which includes new-line character
|
/// 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 {
|
match self.specific {
|
||||||
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
|
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
|
||||||
TableRowBox | TableWrapperBox => CannotSplit,
|
TableRowBox | TableWrapperBox => None,
|
||||||
TableColumnBox(_) => fail!("Table column boxes do not need to split"),
|
TableColumnBox(_) => fail!("Table column boxes do not need to split"),
|
||||||
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"),
|
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"),
|
||||||
ScannedTextBox(ref text_box_info) => {
|
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 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));
|
let mut new_box = self.transform(new_metrics.bounding_box.size, ScannedTextBox(new_text_box_info));
|
||||||
new_box.new_line_pos = vec!();
|
new_box.new_line_pos = vec!();
|
||||||
Some(new_box)
|
new_box
|
||||||
};
|
};
|
||||||
|
|
||||||
// Right box is for right text of first founded new-line character.
|
// Right box is for right text of first founded new-line character.
|
||||||
|
@ -1131,16 +1121,16 @@ impl Box {
|
||||||
None
|
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`.
|
/// 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 {
|
match self.specific {
|
||||||
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
|
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
|
||||||
TableRowBox | TableWrapperBox => CannotSplit,
|
TableRowBox | TableWrapperBox => None,
|
||||||
TableColumnBox(_) => fail!("Table column boxes do not have width"),
|
TableColumnBox(_) => fail!("Table column boxes do not have width"),
|
||||||
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"),
|
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"),
|
||||||
ScannedTextBox(ref text_box_info) => {
|
ScannedTextBox(ref text_box_info) => {
|
||||||
|
@ -1231,10 +1221,10 @@ impl Box {
|
||||||
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
|
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
|
||||||
});
|
});
|
||||||
|
|
||||||
if pieces_processed_count == 1 || left_box.is_none() {
|
if (pieces_processed_count == 1 || left_box.is_none()) && !starts_line {
|
||||||
SplitDidNotFit(left_box, right_box)
|
None
|
||||||
} else {
|
} else {
|
||||||
SplitDidFit(left_box, right_box)
|
Some((left_box, right_box))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use css::node_style::StyledNode;
|
use css::node_style::StyledNode;
|
||||||
use layout::box_::{Box, CannotSplit, SplitDidFit, SplitDidNotFit};
|
use layout::box_::Box;
|
||||||
use layout::context::LayoutContext;
|
use layout::context::LayoutContext;
|
||||||
use layout::floats::{FloatLeft, Floats, PlacementInfo};
|
use layout::floats::{FloatLeft, Floats, PlacementInfo};
|
||||||
use layout::flow::{BaseFlow, FlowClass, Flow, InlineFlowClass};
|
use layout::flow::{BaseFlow, FlowClass, Flow, InlineFlowClass};
|
||||||
|
@ -425,19 +425,16 @@ impl LineboxScanner {
|
||||||
} else {
|
} else {
|
||||||
// In case of box includes new-line character
|
// In case of box includes new-line character
|
||||||
match in_box.split_by_new_line() {
|
match in_box.split_by_new_line() {
|
||||||
SplitDidFit(left, right) => {
|
Some((left_box, Some(right_box))) => {
|
||||||
match (left, right) {
|
self.push_box_to_line(left_box);
|
||||||
(Some(left_box), Some(right_box)) => {
|
self.work_list.push_front(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);
|
||||||
(Some(left_box), None) => {
|
},
|
||||||
self.push_box_to_line(left_box);
|
None => {
|
||||||
}
|
error!("LineboxScanner: This split case makes no sense!")
|
||||||
_ => error!("LineboxScanner: This split case makes no sense!"),
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -496,30 +493,16 @@ impl LineboxScanner {
|
||||||
|
|
||||||
let available_width = green_zone.width - self.pending_line.bounds.size.width;
|
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 split = in_box.split_to_width(available_width, line_is_empty);
|
||||||
let (left, right) = match (split, line_is_empty) {
|
let (left, right) = match split {
|
||||||
(CannotSplit, _) => {
|
None => {
|
||||||
debug!("LineboxScanner: Tried to split unsplittable render box! {}",
|
debug!("LineboxScanner: Tried to split unsplittable render box! {}",
|
||||||
in_box);
|
in_box);
|
||||||
self.work_list.push_front(in_box);
|
self.work_list.push_front(in_box);
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
(SplitDidNotFit(_, _), false) => {
|
Some((left, right)) => {
|
||||||
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), _) => {
|
|
||||||
debug!("LineboxScanner: case=split box did fit; deferring remainder box.");
|
debug!("LineboxScanner: case=split box did fit; deferring remainder box.");
|
||||||
(left, right)
|
(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.
|
// Fall though to push boxes to the line.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue