Rename Box.position to border_box

This commit is contained in:
Keegan McAllister 2014-02-18 16:52:18 -08:00
parent bad4f16c3a
commit b7dea86283
4 changed files with 37 additions and 37 deletions

View file

@ -386,7 +386,7 @@ impl BlockFlow {
let mut noncontent_height = Au::new(0); let mut noncontent_height = Au::new(0);
for box_ in self.box_.iter() { for box_ in self.box_.iter() {
let mut position = box_.position.get(); let mut position = box_.border_box.get();
let mut margin = box_.margin.get(); let mut margin = box_.margin.get();
// The associated box is the border box of this flow. // The associated box is the border box of this flow.
@ -421,7 +421,7 @@ impl BlockFlow {
noncontent_height = noncontent_height + clearance + margin.top + margin.bottom; noncontent_height = noncontent_height + clearance + margin.top + margin.bottom;
box_.position.set(position); box_.border_box.set(position);
box_.margin.set(margin); box_.margin.set(margin);
} }
@ -450,7 +450,7 @@ impl BlockFlow {
let mut margin_height = Au(0); let mut margin_height = Au(0);
for box_ in self.box_.iter() { for box_ in self.box_.iter() {
height = box_.position.get().size.height; height = box_.border_box.get().size.height;
clearance = match box_.clear() { clearance = match box_.clear() {
None => Au(0), None => Au(0),
Some(clear) => self.base.floats_in.clearance(clear), Some(clear) => self.base.floats_in.clearance(clear),
@ -507,7 +507,7 @@ impl BlockFlow {
let mut noncontent_height; let mut noncontent_height;
let box_ = self.box_.as_ref().unwrap(); let box_ = self.box_.as_ref().unwrap();
let mut position = box_.position.get(); let mut position = box_.border_box.get();
// The associated box is the border box of this flow. // The associated box is the border box of this flow.
position.origin.y = box_.margin.get().top; position.origin.y = box_.margin.get().top;
@ -523,7 +523,7 @@ impl BlockFlow {
debug!("assign_height_float -- height: {}", height); debug!("assign_height_float -- height: {}", height);
position.size.height = height; position.size.height = height;
box_.position.set(position); box_.border_box.set(position);
} }
pub fn build_display_list_block<E:ExtraDisplayListData>( pub fn build_display_list_block<E:ExtraDisplayListData>(
@ -756,7 +756,7 @@ impl Flow for BlockFlow {
remaining_width = w; remaining_width = w;
// The associated box is the border box of this flow. // The associated box is the border box of this flow.
let mut position_ref = box_.position.borrow_mut(); let mut position_ref = box_.border_box.borrow_mut();
if self.is_fixed { if self.is_fixed {
position_ref.get().origin.x = x_offset + box_.margin.get().left; position_ref.get().origin.x = x_offset + box_.margin.get().left;
x_offset = x_offset + box_.padding.get().left; x_offset = x_offset + box_.padding.get().left;

View file

@ -73,7 +73,7 @@ pub struct Box {
/// The position of this box relative to its owning flow. /// The position of this box relative to its owning flow.
/// The size includes padding and border, but not margin. /// The size includes padding and border, but not margin.
position: RefCell<Rect<Au>>, border_box: RefCell<Rect<Au>>,
/// The border of the content box. /// The border of the content box.
/// ///
@ -386,7 +386,7 @@ impl Box {
Box { Box {
node: OpaqueNode::from_thread_safe_layout_node(&node), node: OpaqueNode::from_thread_safe_layout_node(&node),
style: node.style().clone(), style: node.style().clone(),
position: RefCell::new(Au::zero_rect()), border_box: RefCell::new(Au::zero_rect()),
border: RefCell::new(Zero::zero()), border: RefCell::new(Zero::zero()),
padding: RefCell::new(Zero::zero()), padding: RefCell::new(Zero::zero()),
margin: RefCell::new(Zero::zero()), margin: RefCell::new(Zero::zero()),
@ -405,7 +405,7 @@ impl Box {
Box { Box {
node: node, node: node,
style: style, style: style,
position: RefCell::new(Au::zero_rect()), border_box: RefCell::new(Au::zero_rect()),
border: RefCell::new(Zero::zero()), border: RefCell::new(Zero::zero()),
padding: RefCell::new(Zero::zero()), padding: RefCell::new(Zero::zero()),
margin: RefCell::new(Zero::zero()), margin: RefCell::new(Zero::zero()),
@ -502,7 +502,7 @@ impl Box {
Box { Box {
node: self.node, node: self.node,
style: self.style.clone(), style: self.style.clone(),
position: RefCell::new(Rect(self.position.get().origin, size)), border_box: RefCell::new(Rect(self.border_box.get().origin, size)),
border: RefCell::new(self.border.get()), border: RefCell::new(self.border.get()),
padding: RefCell::new(self.padding.get()), padding: RefCell::new(self.padding.get()),
margin: RefCell::new(self.margin.get()), margin: RefCell::new(self.margin.get()),
@ -992,7 +992,7 @@ impl Box {
flow: &Flow, flow: &Flow,
index: uint, index: uint,
lists: &RefCell<DisplayListCollection<E>>) { lists: &RefCell<DisplayListCollection<E>>) {
let box_bounds = self.position.get(); let box_bounds = self.border_box.get();
let absolute_box_bounds = box_bounds.translate(&offset); let absolute_box_bounds = box_bounds.translate(&offset);
debug!("Box::build_display_list at rel={}, abs={}: {:s}", debug!("Box::build_display_list at rel={}, abs={}: {:s}",
box_bounds, absolute_box_bounds, self.debug_str()); box_bounds, absolute_box_bounds, self.debug_str());
@ -1395,7 +1395,7 @@ impl Box {
let left_box = if left_range.length() > 0 { let left_box = if left_range.length() > 0 {
let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range); let new_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), left_range);
let mut new_metrics = new_text_box_info.run.get().metrics_for_range(&left_range); let mut new_metrics = new_text_box_info.run.get().metrics_for_range(&left_range);
new_metrics.bounding_box.size.height = self.position.get().size.height; new_metrics.bounding_box.size.height = self.border_box.get().size.height;
Some(self.transform(new_metrics.bounding_box.size, Some(self.transform(new_metrics.bounding_box.size,
ScannedTextBox(new_text_box_info))) ScannedTextBox(new_text_box_info)))
} else { } else {
@ -1405,7 +1405,7 @@ impl Box {
let right_box = right_range.map_default(None, |range: Range| { 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_text_box_info = ScannedTextBoxInfo::new(text_box_info.run.clone(), range);
let mut new_metrics = new_text_box_info.run.get().metrics_for_range(&range); let mut new_metrics = new_text_box_info.run.get().metrics_for_range(&range);
new_metrics.bounding_box.size.height = self.position.get().size.height; new_metrics.bounding_box.size.height = self.border_box.get().size.height;
Some(self.transform(new_metrics.bounding_box.size, Some(self.transform(new_metrics.bounding_box.size,
ScannedTextBox(new_text_box_info))) ScannedTextBox(new_text_box_info)))
}); });
@ -1464,14 +1464,14 @@ impl Box {
} }
}; };
let mut position = self.position.borrow_mut(); let mut position = self.border_box.borrow_mut();
position.get().size.width = width + self.noncontent_width() + position.get().size.width = width + self.noncontent_width() +
self.noncontent_inline_left() + self.noncontent_inline_right(); self.noncontent_inline_left() + self.noncontent_inline_right();
image_box_info.computed_width.set(Some(width)); image_box_info.computed_width.set(Some(width));
} }
ScannedTextBox(_) => { ScannedTextBox(_) => {
// Scanned text boxes will have already had their content_widths assigned by this point. // Scanned text boxes will have already had their content_widths assigned by this point.
let mut position = self.position.borrow_mut(); let mut position = self.border_box.borrow_mut();
position.get().size.width = position.get().size.width + self.noncontent_width() + position.get().size.width = position.get().size.width + self.noncontent_width() +
self.noncontent_inline_left() + self.noncontent_inline_right(); self.noncontent_inline_left() + self.noncontent_inline_right();
} }
@ -1508,13 +1508,13 @@ impl Box {
} }
}; };
let mut position = self.position.borrow_mut(); let mut position = self.border_box.borrow_mut();
image_box_info.computed_height.set(Some(height)); image_box_info.computed_height.set(Some(height));
position.get().size.height = height + self.noncontent_height() position.get().size.height = height + self.noncontent_height()
} }
ScannedTextBox(_) => { ScannedTextBox(_) => {
// Scanned text boxes will have already had their widths assigned by this point // Scanned text boxes will have already had their widths assigned by this point
let mut position = self.position.borrow_mut(); let mut position = self.border_box.borrow_mut();
position.get().size.height position.get().size.height
= position.get().size.height + self.noncontent_height() = position.get().size.height + self.noncontent_height()
} }
@ -1589,8 +1589,8 @@ impl Box {
self.padding.get().left; self.padding.get().left;
let top = offset.y + self.margin.get().top + self.border.get().top + let top = offset.y + self.margin.get().top + self.border.get().top +
self.padding.get().top; self.padding.get().top;
let width = self.position.get().size.width - self.noncontent_width(); let width = self.border_box.get().size.width - self.noncontent_width();
let height = self.position.get().size.height - self.noncontent_height(); let height = self.border_box.get().size.height - self.noncontent_height();
let origin = Point2D(geometry::to_frac_px(left) as f32, geometry::to_frac_px(top) as f32); let origin = Point2D(geometry::to_frac_px(left) as f32, geometry::to_frac_px(top) as f32);
let size = Size2D(geometry::to_frac_px(width) as f32, geometry::to_frac_px(height) as f32); let size = Size2D(geometry::to_frac_px(width) as f32, geometry::to_frac_px(height) as f32);
let rect = Rect(origin, size); let rect = Rect(origin, size);

View file

@ -757,7 +757,7 @@ impl<'a> MutableFlowUtils for &'a mut Flow {
let container_block_size = match self.class() { let container_block_size = match self.class() {
BlockFlowClass => { BlockFlowClass => {
if self.as_block().box_.is_some() { if self.as_block().box_.is_some() {
self.as_block().box_.get_ref().position.get().size self.as_block().box_.get_ref().border_box.get().size
} else { } else {
base(self).position.size base(self).position.size
} }

View file

@ -179,7 +179,7 @@ impl LineboxScanner {
-> (Rect<Au>, Au) { -> (Rect<Au>, Au) {
debug!("LineboxScanner: Trying to place first box of line {}", self.lines.len()); debug!("LineboxScanner: Trying to place first box of line {}", self.lines.len());
let first_box_size = first_box.position.get().size; let first_box_size = first_box.border_box.get().size;
let splittable = first_box.can_split(); let splittable = first_box.can_split();
debug!("LineboxScanner: box size: {}, splittable: {}", first_box_size, splittable); debug!("LineboxScanner: box size: {}, splittable: {}", first_box_size, splittable);
let line_is_empty: bool = self.pending_line.range.length() == 0; let line_is_empty: bool = self.pending_line.range.length() == 0;
@ -234,9 +234,9 @@ impl LineboxScanner {
debug!("LineboxScanner: case=box split and fit"); debug!("LineboxScanner: case=box split and fit");
let actual_box_width = match (left, right) { let actual_box_width = match (left, right) {
(Some(l_box), Some(_)) => l_box.position.get().size.width, (Some(l_box), Some(_)) => l_box.border_box.get().size.width,
(Some(l_box), None) => l_box.position.get().size.width, (Some(l_box), None) => l_box.border_box.get().size.width,
(None, Some(r_box)) => r_box.position.get().size.width, (None, Some(r_box)) => r_box.border_box.get().size.width,
(None, None) => fail!("This case makes no sense.") (None, None) => fail!("This case makes no sense.")
}; };
return (line_bounds, actual_box_width); return (line_bounds, actual_box_width);
@ -248,9 +248,9 @@ impl LineboxScanner {
debug!("LineboxScanner: case=box split and fit didn't fit; trying to push it down"); debug!("LineboxScanner: case=box split and fit didn't fit; trying to push it down");
let actual_box_width = match (left, right) { let actual_box_width = match (left, right) {
(Some(l_box), Some(_)) => l_box.position.get().size.width, (Some(l_box), Some(_)) => l_box.border_box.get().size.width,
(Some(l_box), None) => l_box.position.get().size.width, (Some(l_box), None) => l_box.border_box.get().size.width,
(None, Some(r_box)) => r_box.position.get().size.width, (None, Some(r_box)) => r_box.border_box.get().size.width,
(None, None) => fail!("This case makes no sense.") (None, None) => fail!("This case makes no sense.")
}; };
@ -349,7 +349,7 @@ impl LineboxScanner {
debug!("LineboxScanner: Trying to append box to line {:u} (box size: {}, green zone: \ debug!("LineboxScanner: Trying to append box to line {:u} (box size: {}, green zone: \
{}): {:s}", {}): {:s}",
self.lines.len(), self.lines.len(),
in_box.position.get().size, in_box.border_box.get().size,
self.pending_line.green_zone, self.pending_line.green_zone,
in_box.debug_str()); in_box.debug_str());
@ -369,7 +369,7 @@ impl LineboxScanner {
// horizontally. We'll try to place the whole box on this line and break somewhere if it // horizontally. We'll try to place the whole box on this line and break somewhere if it
// doesn't fit. // doesn't fit.
let new_width = self.pending_line.bounds.size.width + in_box.position.get().size.width; let new_width = self.pending_line.bounds.size.width + in_box.border_box.get().size.width;
if new_width <= green_zone.width { if new_width <= green_zone.width {
debug!("LineboxScanner: case=box fits without splitting"); debug!("LineboxScanner: case=box fits without splitting");
self.push_box_to_line(in_box); self.push_box_to_line(in_box);
@ -440,9 +440,9 @@ impl LineboxScanner {
} }
self.pending_line.range.extend_by(1); self.pending_line.range.extend_by(1);
self.pending_line.bounds.size.width = self.pending_line.bounds.size.width + self.pending_line.bounds.size.width = self.pending_line.bounds.size.width +
box_.position.get().size.width; box_.border_box.get().size.width;
self.pending_line.bounds.size.height = Au::max(self.pending_line.bounds.size.height, self.pending_line.bounds.size.height = Au::max(self.pending_line.bounds.size.height,
box_.position.get().size.height); box_.border_box.get().size.height);
self.new_boxes.push(box_); self.new_boxes.push(box_);
} }
} }
@ -603,8 +603,8 @@ impl InlineFlow {
for i in line.range.eachi() { for i in line.range.eachi() {
let box_ = &boxes[i]; let box_ = &boxes[i];
let size = box_.position.get().size; let size = box_.border_box.get().size;
box_.position.set(Rect(Point2D(offset_x, box_.position.get().origin.y), size)); box_.border_box.set(Rect(Point2D(offset_x, box_.border_box.get().origin.y), size));
offset_x = offset_x + size.width; offset_x = offset_x + size.width;
} }
} }
@ -764,12 +764,12 @@ impl Flow for InlineFlow {
// Offset from the top of the box is 1/2 of the leading + ascent // Offset from the top of the box is 1/2 of the leading + ascent
let text_offset = text_ascent + (line_height - em_size).scale_by(0.5); let text_offset = text_ascent + (line_height - em_size).scale_by(0.5);
text_bounds.translate(&Point2D(cur_box.position.get().origin.x, Au(0))); text_bounds.translate(&Point2D(cur_box.border_box.get().origin.x, Au(0)));
(text_offset, line_height - text_offset, text_ascent) (text_offset, line_height - text_offset, text_ascent)
}, },
GenericBox | IframeBox(_) => { GenericBox | IframeBox(_) => {
let height = cur_box.position.get().size.height; let height = cur_box.border_box.get().size.height;
(height, Au::new(0), height) (height, Au::new(0), height)
}, },
UnscannedTextBox(_) => { UnscannedTextBox(_) => {
@ -824,7 +824,7 @@ impl Flow for InlineFlow {
bottommost = bottom_from_base; bottommost = bottom_from_base;
} }
cur_box.position.borrow_mut().get().origin.y = line.bounds.origin.y + offset + top; cur_box.border_box.borrow_mut().get().origin.y = line.bounds.origin.y + offset + top;
} }
// Calculate the distance from baseline to the top of the biggest box with 'bottom' // Calculate the distance from baseline to the top of the biggest box with 'bottom'
@ -853,7 +853,7 @@ impl Flow for InlineFlow {
_ => baseline_offset, _ => baseline_offset,
}; };
cur_box.position.borrow_mut().get().origin.y = cur_box.position.get().origin.y + cur_box.border_box.borrow_mut().get().origin.y = cur_box.border_box.get().origin.y +
adjust_offset; adjust_offset;
if cur_box.inline_info.with(|info| info.is_none()) { if cur_box.inline_info.with(|info| info.is_none()) {