mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Move some of the box splitting logic into inline.rs
This commit is contained in:
parent
2717ab65ec
commit
6b8d46dc85
2 changed files with 35 additions and 20 deletions
|
@ -1131,12 +1131,22 @@ impl Box {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to split this box so that its width is no more than `max_width`.
|
/// Attempts to find the split positions of a text box so that its width is
|
||||||
|
/// 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 the split boxes are returned. The left and right boxes are
|
/// Otherwise tuples of the width of the splits, the index into the text
|
||||||
/// optional due to the possibility of them being whitespace.
|
/// boxes to the left and right side of the split, and the respective text
|
||||||
pub fn split_to_width(&self, max_width: Au, starts_line: bool) -> Option<(Option<Box>, Option<Box>)> {
|
/// box info are returned. The left and right boxes are optional due to the
|
||||||
|
/// possibility of them being whitespace.
|
||||||
|
///
|
||||||
|
// 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,
|
||||||
|
@ -1145,7 +1155,7 @@ impl Box {
|
||||||
ScannedTextBox(ref text_box_info) => {
|
ScannedTextBox(ref text_box_info) => {
|
||||||
let mut pieces_processed_count: uint = 0;
|
let mut pieces_processed_count: uint = 0;
|
||||||
let mut remaining_width: Au = max_width;
|
let mut remaining_width: Au = max_width;
|
||||||
let mut left_range = Range::new(text_box_info.range.begin(), CharIndex(0));
|
let mut left_range = Range::new(text_box_info.range.begin() + start, CharIndex(0));
|
||||||
let mut right_range: Option<Range<CharIndex>> = None;
|
let mut right_range: Option<Range<CharIndex>> = None;
|
||||||
|
|
||||||
debug!("split_to_width: splitting text box (strlen={:u}, range={}, \
|
debug!("split_to_width: splitting text box (strlen={:u}, range={}, \
|
||||||
|
@ -1217,25 +1227,17 @@ impl Box {
|
||||||
if (pieces_processed_count == 1 || !left_is_some) && !starts_line {
|
if (pieces_processed_count == 1 || !left_is_some) && !starts_line {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let left_box = if left_is_some {
|
let left = if left_is_some {
|
||||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range);
|
Some((left_range, text_box_info.run.advance_for_range(&left_range)))
|
||||||
let width = new_text_box_info.run.advance_for_range(&left_range);
|
|
||||||
let height = self.border_box.size.height;
|
|
||||||
let size = Size2D(width, height);
|
|
||||||
Some(self.transform(size, ScannedTextBox(new_text_box_info)))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let right_box = right_range.map(|right_range| {
|
let right = right_range.map(|right_range| {
|
||||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), right_range);
|
(right_range, text_box_info.run.advance_for_range(&right_range))
|
||||||
let width = new_text_box_info.run.advance_for_range(&right_range);
|
|
||||||
let height = self.border_box.size.height;
|
|
||||||
let size = Size2D(width, height);
|
|
||||||
(self.transform(size, ScannedTextBox(new_text_box_info)))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Some((left_box, right_box))
|
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;
|
use layout::box_::{Box, ScannedTextBox, ScannedTextBoxInfo};
|
||||||
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};
|
||||||
|
@ -492,7 +492,20 @@ 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.split_to_width(available_width, line_is_empty) {
|
match in_box.find_split_positions(CharIndex(0), available_width, line_is_empty).map(
|
||||||
|
|(left, right, run)| {
|
||||||
|
let make_box = |(range, width): (Range<CharIndex>, Au)| {
|
||||||
|
let info = ScannedTextBoxInfo::new(run.clone(), range);
|
||||||
|
let specific = ScannedTextBox(info);
|
||||||
|
let size = Size2D(width, in_box.border_box.size.height);
|
||||||
|
// TODO: Remove box splitting
|
||||||
|
in_box.transform(size, specific)
|
||||||
|
};
|
||||||
|
|
||||||
|
(left.map(|x| { debug!("LineboxScanner: Left split {}", x); make_box(x) }),
|
||||||
|
right.map(|x| { debug!("LineboxScanner: Right split {}", x); make_box(x) }))
|
||||||
|
}
|
||||||
|
) {
|
||||||
None => {
|
None => {
|
||||||
debug!("LineboxScanner: Tried to split unsplittable render box! Deferring to next \
|
debug!("LineboxScanner: Tried to split unsplittable render box! Deferring to next \
|
||||||
line. {}", in_box);
|
line. {}", in_box);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue