From d5ca1a18dc110d2c6fbad69a517c5bca858c32be Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 8 May 2015 16:33:30 -0700 Subject: [PATCH] layout: Support percentage widths in inline-blocks. Improves Twitter. --- components/layout/block.rs | 6 +++--- components/layout/fragment.rs | 13 +++++++++++++ components/layout/inline.rs | 3 ++- tests/ref/basic.list | 1 + tests/ref/percentage_width_inline_block_a.html | 17 +++++++++++++++++ .../ref/percentage_width_inline_block_ref.html | 16 ++++++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 tests/ref/percentage_width_inline_block_a.html create mode 100644 tests/ref/percentage_width_inline_block_ref.html diff --git a/components/layout/block.rs b/components/layout/block.rs index fa3a13c58e7..c77c9266345 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -2134,9 +2134,9 @@ pub trait ISizeAndMarginsComputer { } fn containing_block_inline_size(&self, - _: &mut BlockFlow, - parent_flow_inline_size: Au, - _: &LayoutContext) + _: &mut BlockFlow, + parent_flow_inline_size: Au, + _: &LayoutContext) -> Au { parent_flow_inline_size } diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index b5c96816933..c8d496c04bf 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1897,6 +1897,19 @@ impl Fragment { } } + /// Determines the inline sizes of inline-block fragments. These cannot be fully computed until + /// inline size assignment has run for the child flow: thus it is computed "late", during + /// block size assignment. + pub fn update_late_computed_replaced_inline_size_if_necessary(&mut self) { + if let SpecificFragmentInfo::InlineBlock(ref mut inline_block_info) = self.specific { + let block_flow = inline_block_info.flow_ref.as_block(); + let margin = block_flow.fragment.style.logical_margin(); + self.border_box.size.inline = block_flow.fragment.border_box.size.inline + + MaybeAuto::from_style(margin.inline_start, Au(0)).specified_or_zero() + + MaybeAuto::from_style(margin.inline_end, Au(0)).specified_or_zero() + } + } + pub fn update_late_computed_inline_position_if_necessary(&mut self) { match self.specific { SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut info) => { diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 79d4db2fe5f..07a3068d65b 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -1283,10 +1283,11 @@ impl Flow for InlineFlow { // TODO(pcwalton): Cache the line scanner? debug!("assign_block_size_inline: floats in: {:?}", self.base.floats); - // Assign the block-size for the inline fragments. + // Assign the block-size and late-computed inline-sizes for the inline fragments. let containing_block_block_size = self.base.block_container_explicit_block_size.unwrap_or(Au(0)); for fragment in self.fragments.fragments.iter_mut() { + fragment.update_late_computed_replaced_inline_size_if_necessary(); fragment.assign_replaced_block_size_if_necessary( containing_block_block_size); } diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 9a9e015e4fb..07182d40582 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -233,6 +233,7 @@ experimental != overconstrained_block.html overconstrained_block_ref.html == percent_height.html percent_height_ref.html == percentage_height_float_a.html percentage_height_float_ref.html == percentage_height_root.html percentage_height_root_ref.html +== percentage_width_inline_block_a.html percentage_width_inline_block_ref.html == png_rgba_colorspace_a.html png_rgba_colorspace_b.html == position_abs_cb_with_non_cb_kid_a.html position_abs_cb_with_non_cb_kid_b.html == position_abs_height_width_a.html position_abs_height_width_b.html diff --git a/tests/ref/percentage_width_inline_block_a.html b/tests/ref/percentage_width_inline_block_a.html new file mode 100644 index 00000000000..0e04a34c0b1 --- /dev/null +++ b/tests/ref/percentage_width_inline_block_a.html @@ -0,0 +1,17 @@ + + + + + + +Y
X
+ + + diff --git a/tests/ref/percentage_width_inline_block_ref.html b/tests/ref/percentage_width_inline_block_ref.html new file mode 100644 index 00000000000..375c7c8354f --- /dev/null +++ b/tests/ref/percentage_width_inline_block_ref.html @@ -0,0 +1,16 @@ + + + + + + +Y
X
+ + +