mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
Move box splitting by new-line to inline.rs
This commit is contained in:
parent
7c14d9f210
commit
d6dba5158a
2 changed files with 39 additions and 25 deletions
|
@ -1093,12 +1093,13 @@ impl Box {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Split box which includes new-line character.
|
/// Find the split of a box that includes a 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 is not splittable.
|
||||||
/// Otherwise the split boxes are returned. The right box is optional due
|
/// Otherwise the split information is returned. The right information is
|
||||||
/// to the possibility of it being whitespace.
|
/// optional due to the possibility of it being whitespace.
|
||||||
pub fn split_by_new_line(&self) -> Option<(Box, Option<Box>)> {
|
pub fn find_split_positions_by_new_line(&self)
|
||||||
|
-> Option<(SplitInfo, Option<SplitInfo>, 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,
|
||||||
|
@ -1113,26 +1114,22 @@ impl Box {
|
||||||
text_box_info.range.length() - (cur_new_line_pos + CharIndex(1)));
|
text_box_info.range.length() - (cur_new_line_pos + CharIndex(1)));
|
||||||
|
|
||||||
// Left box is for left text of first founded new-line character.
|
// Left box is for left text of first founded new-line character.
|
||||||
let left_box = {
|
let left_box = SplitInfo {
|
||||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range);
|
range: left_range,
|
||||||
let new_metrics = new_text_box_info.run.metrics_for_range(&left_range);
|
width: text_box_info.run.advance_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!();
|
|
||||||
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.
|
||||||
let right_box = if right_range.length() > CharIndex(0) {
|
let right_box = if right_range.length() > CharIndex(0) {
|
||||||
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), right_range);
|
Some(SplitInfo {
|
||||||
let new_metrics = new_text_box_info.run.metrics_for_range(&right_range);
|
range: right_range,
|
||||||
let mut new_box = self.transform(new_metrics.bounding_box.size, ScannedTextBox(new_text_box_info));
|
width: text_box_info.run.advance_for_range(&right_range),
|
||||||
new_box.new_line_pos = new_line_pos;
|
})
|
||||||
Some(new_box)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
Some((left_box, right_box))
|
Some((left_box, right_box, text_box_info.run.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,18 +419,35 @@ impl LineboxScanner {
|
||||||
|
|
||||||
fn try_append_to_line_by_new_line(&mut self, in_box: Box) -> bool {
|
fn try_append_to_line_by_new_line(&mut self, in_box: Box) -> bool {
|
||||||
if in_box.new_line_pos.len() == 0 {
|
if in_box.new_line_pos.len() == 0 {
|
||||||
// In case of box does not include new-line character
|
debug!("LineboxScanner: Did not find a new-line character, so pushing the box to \
|
||||||
|
the line without splitting.");
|
||||||
self.push_box_to_line(in_box);
|
self.push_box_to_line(in_box);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
// In case of box includes new-line character
|
debug!("LineboxScanner: Found a new-line character, so splitting theline.");
|
||||||
match in_box.split_by_new_line() {
|
match in_box.split_by_new_line() {
|
||||||
Some((left_box, Some(right_box))) => {
|
Some((left, right, run)) => {
|
||||||
self.push_box_to_line(left_box);
|
// TODO: Remove box splitting
|
||||||
self.work_list.push_front(right_box);
|
let split_box = |split: SplitInfo| {
|
||||||
},
|
let info = ScannedTextBoxInfo::new(run.clone(), split.range);
|
||||||
Some((left_box, None)) => {
|
let specific = ScannedTextBox(info);
|
||||||
self.push_box_to_line(left_box);
|
let size = Size2D(split.width, in_box.border_box.size.height);
|
||||||
|
in_box.transform(size, specific)
|
||||||
|
};
|
||||||
|
|
||||||
|
debug!("LineboxScanner: Pushing the box to the left of the new-line character \
|
||||||
|
to the line.");
|
||||||
|
let mut left = split_box(left);
|
||||||
|
left.new_line_pos = vec!();
|
||||||
|
self.push_box_to_line(left);
|
||||||
|
|
||||||
|
right.map(|right| {
|
||||||
|
debug!("LineboxScanner: Deferring the box to the right of the new-line \
|
||||||
|
character to the line.");
|
||||||
|
let mut right = split_box(right);
|
||||||
|
right.new_line_pos = in_box.new_line_pos.clone();
|
||||||
|
self.work_list.push_front(right);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
error!("LineboxScanner: This split case makes no sense!")
|
error!("LineboxScanner: This split case makes no sense!")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue