diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 125817264f1..fbf805bb1c0 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -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. - /// Otherwise the split boxes are returned. The left and right boxes are - /// optional due to the possibility of them being whitespace. - pub fn split_to_width(&self, max_width: Au, starts_line: bool) -> Option<(Option, Option)> { + /// Otherwise tuples of the width of the splits, the index into the text + /// boxes to the left and right side of the split, and the respective text + /// 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, Au)>, + Option<(Range, Au)>, + Arc<~TextRun>, // TODO: remove + )> { match self.specific { GenericBox | IframeBox(_) | ImageBox(_) | TableBox | TableCellBox | TableRowBox | TableWrapperBox => None, @@ -1145,7 +1155,7 @@ impl Box { ScannedTextBox(ref text_box_info) => { let mut pieces_processed_count: uint = 0; 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> = None; 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 { None } else { - let left_box = if left_is_some { - let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), 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))) + let left = if left_is_some { + Some((left_range, text_box_info.run.advance_for_range(&left_range))) } else { None }; - let right_box = right_range.map(|right_range| { - let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), 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))) + let right = right_range.map(|right_range| { + (right_range, text_box_info.run.advance_for_range(&right_range)) }); - Some((left_box, right_box)) + Some((left, right, text_box_info.run.clone())) } } } diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index 58e21329f95..42a3210a56c 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -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; +use layout::box_::{Box, ScannedTextBox, ScannedTextBoxInfo}; use layout::context::LayoutContext; use layout::floats::{FloatLeft, Floats, PlacementInfo}; 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; - 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, 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 => { debug!("LineboxScanner: Tried to split unsplittable render box! Deferring to next \ line. {}", in_box);