Skip to content

Commit

Permalink
Make box_ not Option in block flows.(fixes #2012)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpy committed Apr 6, 2014
1 parent 4386bae commit ce363ba
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 398 deletions.
519 changes: 221 additions & 298 deletions src/components/main/layout/block.rs

Large diffs are not rendered by default.

21 changes: 6 additions & 15 deletions src/components/main/layout/table.rs
Expand Up @@ -241,9 +241,7 @@ impl Flow for TableFlow {
let child_base = flow::mut_base(kid);
num_floats = num_floats + child_base.num_floats;
}
for box_ in self.block_flow.box_.iter() {
box_.compute_borders(box_.style());
}
self.block_flow.box_.compute_borders(self.block_flow.box_.style());
self.block_flow.base.num_floats = num_floats;
self.block_flow.base.intrinsic_widths.minimum_width = min_width;
self.block_flow.base.intrinsic_widths.preferred_width = geometry::max(min_width, pref_width);
Expand All @@ -256,8 +254,6 @@ impl Flow for TableFlow {

// The position was set to the containing block by the flow's parent.
let containing_block_width = self.block_flow.base.position.size.width;
let mut left_content_edge = Au::new(0);
let mut content_width = containing_block_width;

let mut num_unspecified_widths = 0;
let mut total_column_width = Au::new(0);
Expand All @@ -272,12 +268,10 @@ impl Flow for TableFlow {
let width_computer = InternalTable;
width_computer.compute_used_width(&mut self.block_flow, ctx, containing_block_width);

for box_ in self.block_flow.box_.iter() {
left_content_edge = box_.padding.get().left + box_.border.get().left;
let padding_and_borders = box_.padding.get().left + box_.padding.get().right +
box_.border.get().left + box_.border.get().right;
content_width = box_.border_box.get().size.width - padding_and_borders;
}
let left_content_edge = self.block_flow.box_.padding.get().left + self.block_flow.box_.border.get().left;
let padding_and_borders = self.block_flow.box_.padding.get().left + self.block_flow.box_.padding.get().right +
self.block_flow.box_.border.get().left + self.block_flow.box_.border.get().right;
let content_width = self.block_flow.box_.border_box.get().size.width - padding_and_borders;

match self.table_layout {
FixedLayout => {
Expand Down Expand Up @@ -319,10 +313,7 @@ impl Flow for TableFlow {

fn debug_str(&self) -> ~str {
let txt = ~"TableFlow: ";
txt.append(match self.block_flow.box_ {
Some(ref rb) => rb.debug_str(),
None => ~"",
})
txt.append(self.block_flow.box_.debug_str())
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/components/main/layout/table_caption.rs
Expand Up @@ -78,9 +78,6 @@ impl Flow for TableCaptionFlow {

fn debug_str(&self) -> ~str {
let txt = ~"TableCaptionFlow: ";
txt.append(match self.block_flow.box_ {
Some(ref rb) => rb.debug_str(),
None => ~"",
})
txt.append(self.block_flow.box_.debug_str())
}
}
39 changes: 15 additions & 24 deletions src/components/main/layout/table_cell.rs
Expand Up @@ -35,7 +35,7 @@ impl TableCellFlow {
self.block_flow.teardown()
}

pub fn box_<'a>(&'a mut self) -> &'a Option<Box>{
pub fn box_<'a>(&'a mut self) -> &'a Box {
&self.block_flow.box_
}

Expand Down Expand Up @@ -77,17 +77,15 @@ impl Flow for TableCellFlow {
/// Minimum/preferred widths set by this function are used in automatic table layout calculation.
fn bubble_widths(&mut self, ctx: &mut LayoutContext) {
self.block_flow.bubble_widths(ctx);
for box_ in self.block_flow.box_.iter() {
let specified_width = MaybeAuto::from_style(box_.style().Box.get().width,
Au::new(0)).specified_or_zero();
if self.block_flow.base.intrinsic_widths.minimum_width < specified_width {
self.block_flow.base.intrinsic_widths.minimum_width = specified_width;
}
if self.block_flow.base.intrinsic_widths.preferred_width <
self.block_flow.base.intrinsic_widths.minimum_width {
self.block_flow.base.intrinsic_widths.preferred_width =
self.block_flow.base.intrinsic_widths.minimum_width;
}
let specified_width = MaybeAuto::from_style(self.block_flow.box_.style().Box.get().width,
Au::new(0)).specified_or_zero();
if self.block_flow.base.intrinsic_widths.minimum_width < specified_width {
self.block_flow.base.intrinsic_widths.minimum_width = specified_width;
}
if self.block_flow.base.intrinsic_widths.preferred_width <
self.block_flow.base.intrinsic_widths.minimum_width {
self.block_flow.base.intrinsic_widths.preferred_width =
self.block_flow.base.intrinsic_widths.minimum_width;
}
}

Expand All @@ -98,18 +96,14 @@ impl Flow for TableCellFlow {

// The position was set to the column width by the parent flow, table row flow.
let containing_block_width = self.block_flow.base.position.size.width;
let mut left_content_edge = Au::new(0);
let mut content_width = containing_block_width;

let width_computer = InternalTable;
width_computer.compute_used_width(&mut self.block_flow, ctx, containing_block_width);

for box_ in self.block_flow.box_.iter() {
left_content_edge = box_.border_box.get().origin.x + box_.padding.get().left + box_.border.get().left;
let padding_and_borders = box_.padding.get().left + box_.padding.get().right +
box_.border.get().left + box_.border.get().right;
content_width = box_.border_box.get().size.width - padding_and_borders;
}
let left_content_edge = self.block_flow.box_.border_box.get().origin.x + self.block_flow.box_.padding.get().left + self.block_flow.box_.border.get().left;
let padding_and_borders = self.block_flow.box_.padding.get().left + self.block_flow.box_.padding.get().right +
self.block_flow.box_.border.get().left + self.block_flow.box_.border.get().right;
let content_width = self.block_flow.box_.border_box.get().size.width - padding_and_borders;

self.block_flow.propagate_assigned_width_to_children(left_content_edge, content_width, None);
}
Expand All @@ -130,10 +124,7 @@ impl Flow for TableCellFlow {

fn debug_str(&self) -> ~str {
let txt = ~"TableCellFlow: ";
txt.append(match self.block_flow.box_ {
Some(ref rb) => rb.debug_str(),
None => ~"",
})
txt.append(self.block_flow.box_.debug_str())
}
}

36 changes: 16 additions & 20 deletions src/components/main/layout/table_row.rs
Expand Up @@ -64,7 +64,7 @@ impl TableRowFlow {
self.col_pref_widths = ~[];
}

pub fn box_<'a>(&'a mut self) -> &'a Option<Box>{
pub fn box_<'a>(&'a mut self) -> &'a Box {
&self.block_flow.box_
}

Expand Down Expand Up @@ -93,7 +93,8 @@ impl TableRowFlow {
kid.assign_height_inorder(layout_context)
}

for child_box in kid.as_table_cell().box_().iter() {
{
let child_box = kid.as_table_cell().box_();
// TODO: Percentage height
let child_specified_height = MaybeAuto::from_style(child_box.style().Box.get().height,
Au::new(0)).specified_or_zero();
Expand All @@ -105,28 +106,25 @@ impl TableRowFlow {
}

let mut height = max_y;
for box_ in self.block_flow.box_.iter() {
// TODO: Percentage height
height = match MaybeAuto::from_style(box_.style().Box.get().height, Au(0)) {
Auto => height,
Specified(value) => geometry::max(value, height)
};
}
// TODO: Percentage height
height = match MaybeAuto::from_style(self.block_flow.box_.style().Box.get().height, Au(0)) {
Auto => height,
Specified(value) => geometry::max(value, height)
};
// cur_y = cur_y + height;

// Assign the height of own box
//
// FIXME(pcwalton): Take `cur_y` into account.
for box_ in self.block_flow.box_.iter() {
let mut position = box_.border_box.get();
position.size.height = height;
box_.border_box.set(position);
}
let mut position = self.block_flow.box_.border_box.get();
position.size.height = height;
self.block_flow.box_.border_box.set(position);
self.block_flow.base.position.size.height = height;

// Assign the height of kid boxes, which is the same value as own height.
for kid in self.block_flow.base.child_iter() {
for kid_box_ in kid.as_table_cell().box_().iter() {
{
let kid_box_ = kid.as_table_cell().box_();
let mut position = kid_box_.border_box.get();
position.size.height = height;
kid_box_.border_box.set(position);
Expand Down Expand Up @@ -185,7 +183,8 @@ impl Flow for TableRowFlow {
assert!(kid.is_table_cell());

// collect the specified column widths of cells. These are used in fixed table layout calculation.
for child_box in kid.as_table_cell().box_().iter() {
{
let child_box = kid.as_table_cell().box_();
let child_specified_width = MaybeAuto::from_style(child_box.style().Box.get().width,
Au::new(0)).specified_or_zero();
self.col_widths.push(child_specified_width);
Expand Down Expand Up @@ -237,10 +236,7 @@ impl Flow for TableRowFlow {

fn debug_str(&self) -> ~str {
let txt = ~"TableRowFlow: ";
txt.append(match self.block_flow.box_ {
Some(ref rb) => rb.debug_str(),
None => ~"",
})
txt.append(self.block_flow.box_.debug_str())
}
}

15 changes: 5 additions & 10 deletions src/components/main/layout/table_rowgroup.rs
Expand Up @@ -63,7 +63,7 @@ impl TableRowGroupFlow {
self.col_pref_widths = ~[];
}

pub fn box_<'a>(&'a mut self) -> &'a Option<Box>{
pub fn box_<'a>(&'a mut self) -> &'a Box {
&self.block_flow.box_
}

Expand Down Expand Up @@ -93,11 +93,9 @@ impl TableRowGroupFlow {

let height = cur_y - top_offset;

for box_ in self.block_flow.box_.iter() {
let mut position = box_.border_box.get();
position.size.height = height;
box_.border_box.set(position);
}
let mut position = self.block_flow.box_.border_box.get();
position.size.height = height;
self.block_flow.box_.border_box.set(position);
self.block_flow.base.position.size.height = height;
}

Expand Down Expand Up @@ -219,10 +217,7 @@ impl Flow for TableRowGroupFlow {

fn debug_str(&self) -> ~str {
let txt = ~"TableRowGroupFlow: ";
txt.append(match self.block_flow.box_ {
Some(ref rb) => rb.debug_str(),
None => ~"",
})
txt.append(self.block_flow.box_.debug_str())
}
}

45 changes: 18 additions & 27 deletions src/components/main/layout/table_wrapper.rs
Expand Up @@ -166,16 +166,12 @@ impl Flow for TableWrapperFlow {

// The position was set to the containing block by the flow's parent.
let containing_block_width = self.block_flow.base.position.size.width;
let mut left_content_edge = Au::new(0);
let mut content_width = containing_block_width;

let width_computer = TableWrapper;
width_computer.compute_used_width_table_wrapper(self, ctx, containing_block_width);

for box_ in self.block_flow.box_.iter() {
left_content_edge = box_.border_box.get().origin.x;
content_width = box_.border_box.get().size.width;
}
let left_content_edge = self.block_flow.box_.border_box.get().origin.x;
let content_width = self.block_flow.box_.border_box.get().size.width;

match self.table_layout {
FixedLayout | _ if self.is_float() =>
Expand Down Expand Up @@ -221,10 +217,7 @@ impl Flow for TableWrapperFlow {
} else {
~"TableWrapperFlow: "
};
txt.append(match self.block_flow.box_ {
Some(ref rb) => rb.debug_str(),
None => ~"",
})
txt.append(self.block_flow.box_.debug_str())
}
}

Expand Down Expand Up @@ -258,23 +251,21 @@ impl TableWrapper {
|sum, width| sum.add(width));

let mut computed_width = input.computed_width.specified_or_zero();
for box_ in table_wrapper.block_flow.box_.iter() {
let style = box_.style();

// Get left and right paddings, borders for table.
// We get these values from the box's style since table_wrapper doesn't have it's own border or padding.
// input.available_width is same as containing_block_width in table_wrapper.
let padding_left = specified(style.Padding.get().padding_left,
input.available_width);
let padding_right = specified(style.Padding.get().padding_right,
input.available_width);
let border_left = style.Border.get().border_left_width;
let border_right = style.Border.get().border_right_width;
let padding_and_borders = padding_left + padding_right + border_left + border_right;
// Compare border-edge widths. Because fixed_cells_width indicates content-width,
// padding and border values are added to fixed_cells_width.
computed_width = geometry::max(fixed_cells_width + padding_and_borders, computed_width);
}
let style = table_wrapper.block_flow.box_.style();

// Get left and right paddings, borders for table.
// We get these values from the box's style since table_wrapper doesn't have it's own border or padding.
// input.available_width is same as containing_block_width in table_wrapper.
let padding_left = specified(style.Padding.get().padding_left,
input.available_width);
let padding_right = specified(style.Padding.get().padding_right,
input.available_width);
let border_left = style.Border.get().border_left_width;
let border_right = style.Border.get().border_right_width;
let padding_and_borders = padding_left + padding_right + border_left + border_right;
// Compare border-edge widths. Because fixed_cells_width indicates content-width,
// padding and border values are added to fixed_cells_width.
computed_width = geometry::max(fixed_cells_width + padding_and_borders, computed_width);
computed_width
},
AutoLayout => {
Expand Down

13 comments on commit ce363ba

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lpy/servo/issue2012 = ce363ba into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpy/servo/issue2012 = ce363ba merged ok, testing candidate = 31930e4

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lpy/servo/issue2012 = ce363ba into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpy/servo/issue2012 = ce363ba merged ok, testing candidate = 9934884

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lpy/servo/issue2012 = ce363ba into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpy/servo/issue2012 = ce363ba merged ok, testing candidate = 4cac445

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4cac445

Please sign in to comment.