layout: Change ~Box to Box.

63% improvement in box building on the rainbow page.
This commit is contained in:
Patrick Walton 2013-12-10 18:00:38 -08:00
parent 4b3defb282
commit 1ba71432ee
7 changed files with 40 additions and 40 deletions

View file

@ -53,7 +53,7 @@ pub struct BlockFlow {
base: FlowData,
/// The associated box.
box: Option<~Box>,
box: Option<Box>,
/// Whether this block flow is the root flow.
is_root: bool,
@ -72,7 +72,7 @@ impl BlockFlow {
}
}
pub fn from_box(base: FlowData, box: ~Box) -> BlockFlow {
pub fn from_box(base: FlowData, box: Box) -> BlockFlow {
BlockFlow {
base: base,
box: Some(box),
@ -81,7 +81,7 @@ impl BlockFlow {
}
}
pub fn float_from_box(base: FlowData, float_type: FloatType, box: ~Box) -> BlockFlow {
pub fn float_from_box(base: FlowData, float_type: FloatType, box: Box) -> BlockFlow {
BlockFlow {
base: base,
box: Some(box),
@ -643,9 +643,9 @@ impl Flow for BlockFlow {
remaining_width).specified_or_zero();
let (width, margin_left, margin_right) = if self.is_float() {
self.compute_float_margins(*box, remaining_width)
self.compute_float_margins(box, remaining_width)
} else {
self.compute_block_margins(*box, remaining_width, available_width)
self.compute_block_margins(box, remaining_width, available_width)
};
box.margin.set(SideOffsets2D::new(margin_top,

View file

@ -205,8 +205,8 @@ 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>)
SplitDidFit(Option<Box>, Option<Box>),
SplitDidNotFit(Option<Box>, Option<Box>)
}
impl Box {
@ -909,7 +909,7 @@ impl Box {
let left_box = if left_range.length() > 0 {
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range);
let new_metrics = new_text_box_info.run.get().metrics_for_range(&left_range);
let new_text_box = ~Box::new(self.node, ScannedTextBox(new_text_box_info));
let new_text_box = Box::new(self.node, ScannedTextBox(new_text_box_info));
new_text_box.set_size(new_metrics.bounding_box.size);
Some(new_text_box)
} else {
@ -919,7 +919,7 @@ impl Box {
let right_box = right_range.map_default(None, |range: Range| {
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), range);
let new_metrics = new_text_box_info.run.get().metrics_for_range(&range);
let new_text_box = ~Box::new(self.node, ScannedTextBox(new_text_box_info));
let new_text_box = Box::new(self.node, ScannedTextBox(new_text_box_info));
new_text_box.set_size(new_metrics.bounding_box.size);
Some(new_text_box)
});

View file

@ -70,7 +70,7 @@ struct InlineBoxesConstructionResult {
splits: Option<~[InlineBlockSplit]>,
/// Any boxes that succeed the {ib} splits.
boxes: ~[~Box],
boxes: ~[Box],
}
/// Represents an {ib} split that has not yet found the containing block that it belongs to. This
@ -99,7 +99,7 @@ struct InlineBlockSplit {
/// The inline boxes that precede the flow.
///
/// TODO(pcwalton): Small vector optimization.
predecessor_boxes: ~[~Box],
predecessor_boxes: ~[Box],
/// The flow that caused this {ib} split.
flow: ~Flow:,
@ -215,7 +215,7 @@ impl<'self> FlowConstructor<'self> {
}
/// Builds a `Box` for the given node.
fn build_box_for_node(&self, node: AbstractNode<LayoutView>) -> ~Box {
fn build_box_for_node(&self, node: AbstractNode<LayoutView>) -> Box {
let specific = match node.type_id() {
ElementNodeTypeId(HTMLImageElementTypeId) => {
match self.build_box_info_for_image(node) {
@ -226,7 +226,7 @@ impl<'self> FlowConstructor<'self> {
TextNodeTypeId => UnscannedTextBox(UnscannedTextBoxInfo::new(&node)),
_ => GenericBox,
};
~Box::new(node, specific)
Box::new(node, specific)
}
/// Creates an inline flow from a set of inline boxes and adds it as a child of the given flow.
@ -235,7 +235,7 @@ impl<'self> FlowConstructor<'self> {
/// otherwise.
#[inline(always)]
fn flush_inline_boxes_to_flow(&self,
boxes: ~[~Box],
boxes: ~[Box],
flow: &mut ~Flow:,
node: AbstractNode<LayoutView>) {
if boxes.len() > 0 {
@ -249,7 +249,7 @@ impl<'self> FlowConstructor<'self> {
/// Creates an inline flow from a set of inline boxes, if present, and adds it as a child of
/// the given flow.
fn flush_inline_boxes_to_flow_if_necessary(&self,
opt_boxes: &mut Option<~[~Box]>,
opt_boxes: &mut Option<~[Box]>,
flow: &mut ~Flow:,
node: AbstractNode<LayoutView>) {
let opt_boxes = util::replace(opt_boxes, None);
@ -564,7 +564,7 @@ impl NodeUtils for AbstractNode<LayoutView> {
}
/// Strips ignorable whitespace from the start of a list of boxes.
fn strip_ignorable_whitespace_from_start(opt_boxes: &mut Option<~[~Box]>) {
fn strip_ignorable_whitespace_from_start(opt_boxes: &mut Option<~[Box]>) {
match util::replace(opt_boxes, None) {
None => return,
Some(boxes) => {
@ -586,7 +586,7 @@ fn strip_ignorable_whitespace_from_start(opt_boxes: &mut Option<~[~Box]>) {
}
/// Strips ignorable whitespace from the end of a list of boxes.
fn strip_ignorable_whitespace_from_end(opt_boxes: &mut Option<~[~Box]>) {
fn strip_ignorable_whitespace_from_end(opt_boxes: &mut Option<~[Box]>) {
match *opt_boxes {
None => {}
Some(ref mut boxes) => {

View file

@ -17,8 +17,8 @@
/// * `BlockFlow`: A flow that establishes a block context. It has several child flows, each of
/// which are positioned according to block formatting context rules (CSS block boxes). Block
/// flows also contain a single `GenericBox` to represent their rendered borders, padding, etc.
/// (In the future, this box may be folded into `BlockFlow` to save space.) The BlockFlow at the
/// root of the tree has special behavior: it stretches to the boundaries of the viewport.
/// The BlockFlow at the root of the tree has special behavior: it stretches to the boundaries of
/// the viewport.
///
/// * `InlineFlow`: A flow that establishes an inline context. It has a flat list of child
/// boxes/flows that are subject to inline layout and line breaking and structs to represent

View file

@ -58,8 +58,8 @@ struct LineBox {
struct LineboxScanner {
floats: FloatContext,
new_boxes: ~[~Box],
work_list: RingBuf<~Box>,
new_boxes: ~[Box],
work_list: RingBuf<Box>,
pending_line: LineBox,
lines: ~[LineBox],
cur_y: Au,
@ -288,7 +288,7 @@ impl LineboxScanner {
///
/// Returns false if and only if we should break the line.
fn avoid_floats(&mut self,
in_box: ~Box,
in_box: Box,
flow: &mut InlineFlow,
new_height: Au,
line_is_empty: bool)
@ -297,7 +297,7 @@ impl LineboxScanner {
// First predict where the next line is going to be.
let this_line_y = self.pending_line.bounds.origin.y;
let (next_line, first_box_width) = self.initial_line_placement(in_box, this_line_y, flow);
let (next_line, first_box_width) = self.initial_line_placement(&in_box, this_line_y, flow);
let next_green_zone = next_line.size;
let new_width = self.pending_line.bounds.size.width + first_box_width;
@ -321,10 +321,10 @@ impl LineboxScanner {
/// Tries to append the given box to the line, splitting it if necessary. Returns false only if
/// we should break the line.
fn try_append_to_line(&mut self, in_box: ~Box, flow: &mut InlineFlow) -> bool {
fn try_append_to_line(&mut self, in_box: Box, flow: &mut InlineFlow) -> bool {
let line_is_empty = self.pending_line.range.length() == 0;
if line_is_empty {
let (line_bounds, _) = self.initial_line_placement(in_box, self.cur_y, flow);
let (line_bounds, _) = self.initial_line_placement(&in_box, self.cur_y, flow);
self.pending_line.bounds.origin = line_bounds.origin;
self.pending_line.green_zone = line_bounds.size;
}
@ -342,7 +342,7 @@ impl LineboxScanner {
// `green_zone.height < self.pending_line.bounds.size.height`, then we committed a line
// that overlaps with floats.
let new_height = self.new_height_for_line(in_box);
let new_height = self.new_height_for_line(&in_box);
if new_height > green_zone.height {
// Uh-oh. Float collision imminent. Enter the float collision avoider
return self.avoid_floats(in_box, flow, new_height, line_is_empty)
@ -415,7 +415,7 @@ impl LineboxScanner {
}
// An unconditional push
fn push_box_to_line(&mut self, box: ~Box) {
fn push_box_to_line(&mut self, box: Box) {
debug!("LineboxScanner: Pushing box {} to line {:u}", box.debug_id(), self.lines.len());
if self.pending_line.range.length() == 0 {
@ -436,7 +436,7 @@ pub struct InlineFlow {
base: FlowData,
/// A vector of all inline render boxes. Several boxes may correspond to one node/element.
boxes: ~[~Box],
boxes: ~[Box],
// vec of ranges into boxes that represents line positions.
// these ranges are disjoint, and are the result of inline layout.
@ -458,7 +458,7 @@ impl InlineFlow {
}
}
pub fn from_boxes(base: FlowData, boxes: ~[~Box]) -> InlineFlow {
pub fn from_boxes(base: FlowData, boxes: ~[Box]) -> InlineFlow {
InlineFlow {
base: base,
boxes: boxes,
@ -579,7 +579,7 @@ impl InlineFlow {
}
/// Sets box X positions based on alignment for one line.
fn set_horizontal_box_positions(boxes: &[~Box], line: &LineBox) {
fn set_horizontal_box_positions(boxes: &[Box], line: &LineBox) {
// Figure out how much width we have.
let slack_width = Au::max(Au(0), line.green_zone.width - line.bounds.size.width);
@ -733,7 +733,7 @@ impl Flow for InlineFlow {
// FIXME(pcwalton): Move into `box.rs` like the rest of box-specific layout code?
let (top_from_base, bottom_from_base, ascent) = match cur_box.specific {
ImageBox(ref image_box) => {
let mut height = image_box.image_height(*cur_box);
let mut height = image_box.image_height(cur_box);
// TODO: margin, border, padding's top and bottom should be calculated in
// advance, since baseline of image is bottom margin edge.
@ -814,7 +814,7 @@ impl Flow for InlineFlow {
// updated or not. That is, if the box has a `top` or `bottom` value,
// `no_update_flag` becomes true.
let (offset, no_update_flag) =
InlineFlow::relative_offset_from_baseline(*cur_box,
InlineFlow::relative_offset_from_baseline(cur_box,
ascent,
parent_text_top,
parent_text_bottom,

View file

@ -56,11 +56,11 @@ impl TextRunScanner {
flow.as_inline().boxes = out_boxes;
// A helper function.
fn can_coalesce_text_nodes(boxes: &[~Box], left_i: uint, right_i: uint) -> bool {
fn can_coalesce_text_nodes(boxes: &[Box], left_i: uint, right_i: uint) -> bool {
assert!(left_i < boxes.len());
assert!(right_i > 0 && right_i < boxes.len());
assert!(left_i != right_i);
boxes[left_i].can_merge_with_box(boxes[right_i])
boxes[left_i].can_merge_with_box(&boxes[right_i])
}
}
@ -78,7 +78,7 @@ impl TextRunScanner {
ctx: &LayoutContext,
flow: &mut Flow,
last_whitespace: bool,
out_boxes: &mut ~[~Box])
out_boxes: &mut ~[Box])
-> bool {
let inline = flow.as_inline();
let in_boxes = &mut inline.boxes;
@ -135,7 +135,7 @@ impl TextRunScanner {
let range = Range::new(0, run.char_len());
let new_metrics = run.metrics_for_range(&range);
let new_text_box_info = ScannedTextBoxInfo::new(Arc::new(run), range);
let new_box = ~old_box.transform(new_metrics.bounding_box.size,
let new_box = old_box.transform(new_metrics.bounding_box.size,
ScannedTextBox(new_text_box_info));
out_boxes.push(new_box)
}
@ -212,7 +212,7 @@ impl TextRunScanner {
let new_text_box_info = ScannedTextBoxInfo::new(run.get_ref().clone(), range);
let new_metrics = new_text_box_info.run.get().metrics_for_range(&range);
let new_box = ~in_boxes[i].transform(new_metrics.bounding_box.size,
let new_box = in_boxes[i].transform(new_metrics.bounding_box.size,
ScannedTextBox(new_text_box_info));
out_boxes.push(new_box)
}

View file

@ -56,7 +56,7 @@ impl ElementMapping {
self.entries.iter().enumerate()
}
pub fn repair_for_box_changes(&mut self, old_boxes: &[~Box], new_boxes: &[~Box]) {
pub fn repair_for_box_changes(&mut self, old_boxes: &[Box], new_boxes: &[Box]) {
let entries = &mut self.entries;
debug!("--- Old boxes: ---");