mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Use a SplitInfo struct instead of a tuple to make the code more self-documenting
This commit is contained in:
parent
6b8d46dc85
commit
7c14d9f210
2 changed files with 27 additions and 22 deletions
|
@ -241,6 +241,12 @@ impl ScannedTextBoxInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Show)]
|
||||||
|
pub struct SplitInfo {
|
||||||
|
pub range: Range<CharIndex>,
|
||||||
|
pub width: Au,
|
||||||
|
}
|
||||||
|
|
||||||
/// Data for an unscanned text box. Unscanned text boxes are the results of flow construction that
|
/// Data for an unscanned text box. Unscanned text boxes are the results of flow construction that
|
||||||
/// have not yet had their width determined.
|
/// have not yet had their width determined.
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
|
@ -1090,7 +1096,7 @@ impl Box {
|
||||||
/// Split box which includes new-line character.
|
/// Split box which includes new-line character.
|
||||||
///
|
///
|
||||||
/// A return value of `None` indicates that the box could not be split.
|
/// A return value of `None` indicates that the box could not be split.
|
||||||
/// Otherwise the split boxes are returned. The right boxe is optional due
|
/// Otherwise the split boxes are returned. The right box is optional due
|
||||||
/// to the possibility of it being whitespace.
|
/// to the possibility of it being whitespace.
|
||||||
pub fn split_by_new_line(&self) -> Option<(Box, Option<Box>)> {
|
pub fn split_by_new_line(&self) -> Option<(Box, Option<Box>)> {
|
||||||
match self.specific {
|
match self.specific {
|
||||||
|
@ -1135,18 +1141,11 @@ impl Box {
|
||||||
/// no more than `max_width`.
|
/// no more than `max_width`.
|
||||||
///
|
///
|
||||||
/// A return value of `None` indicates that the box could not be split.
|
/// A return value of `None` indicates that the box could not be split.
|
||||||
/// Otherwise tuples of the width of the splits, the index into the text
|
/// Otherwise the information pertaining to the split is returned. The left
|
||||||
/// boxes to the left and right side of the split, and the respective text
|
/// and right split information are both optional due to the possibility of
|
||||||
/// box info are returned. The left and right boxes are optional due to the
|
/// them being whitespace.
|
||||||
/// possibility of them being whitespace.
|
pub fn find_split_positions(&self, start: CharIndex, max_width: Au, starts_line: bool)
|
||||||
///
|
-> Option<(Option<SplitInfo>, Option<SplitInfo>, Arc<~TextRun> /* TODO: remove */)> {
|
||||||
// TODO: The returned box info values should be removed along with the box
|
|
||||||
// splitting logic in inline.rs
|
|
||||||
pub fn find_split_positions(&self, start: CharIndex, max_width: Au, starts_line: bool) -> Option<(
|
|
||||||
Option<(Range<CharIndex>, Au)>,
|
|
||||||
Option<(Range<CharIndex>, Au)>,
|
|
||||||
Arc<~TextRun>, // TODO: remove
|
|
||||||
)> {
|
|
||||||
match self.specific {
|
match self.specific {
|
||||||
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
|
GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox |
|
||||||
TableRowBox | TableWrapperBox => None,
|
TableRowBox | TableWrapperBox => None,
|
||||||
|
@ -1228,13 +1227,19 @@ impl Box {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let left = if left_is_some {
|
let left = if left_is_some {
|
||||||
Some((left_range, text_box_info.run.advance_for_range(&left_range)))
|
Some(SplitInfo {
|
||||||
|
range: left_range,
|
||||||
|
width: text_box_info.run.advance_for_range(&left_range),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let right = right_range.map(|right_range| {
|
let right = right_range.map(|right_range| {
|
||||||
(right_range, text_box_info.run.advance_for_range(&right_range))
|
SplitInfo {
|
||||||
|
range: right_range,
|
||||||
|
width: text_box_info.run.advance_for_range(&right_range),
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Some((left, right, text_box_info.run.clone()))
|
Some((left, right, text_box_info.run.clone()))
|
||||||
|
|
|
@ -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, ScannedTextBox, ScannedTextBoxInfo};
|
use layout::box_::{Box, ScannedTextBox, ScannedTextBoxInfo, SplitInfo};
|
||||||
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};
|
||||||
|
@ -494,16 +494,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;
|
||||||
match in_box.find_split_positions(CharIndex(0), available_width, line_is_empty).map(
|
match in_box.find_split_positions(CharIndex(0), available_width, line_is_empty).map(
|
||||||
|(left, right, run)| {
|
|(left, right, run)| {
|
||||||
let make_box = |(range, width): (Range<CharIndex>, Au)| {
|
// TODO: Remove box splitting
|
||||||
let info = ScannedTextBoxInfo::new(run.clone(), range);
|
let split_box = |split: SplitInfo| {
|
||||||
|
let info = ScannedTextBoxInfo::new(run.clone(), split.range);
|
||||||
let specific = ScannedTextBox(info);
|
let specific = ScannedTextBox(info);
|
||||||
let size = Size2D(width, in_box.border_box.size.height);
|
let size = Size2D(split.width, in_box.border_box.size.height);
|
||||||
// TODO: Remove box splitting
|
|
||||||
in_box.transform(size, specific)
|
in_box.transform(size, specific)
|
||||||
};
|
};
|
||||||
|
|
||||||
(left.map(|x| { debug!("LineboxScanner: Left split {}", x); make_box(x) }),
|
(left.map(|x| { debug!("LineboxScanner: Left split {}", x); split_box(x) }),
|
||||||
right.map(|x| { debug!("LineboxScanner: Right split {}", x); make_box(x) }))
|
right.map(|x| { debug!("LineboxScanner: Right split {}", x); split_box(x) }))
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
None => {
|
None => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue