From 7cd0fd06dedddc8271390ac6f38a34bf6503226f Mon Sep 17 00:00:00 2001 From: Matthew Rasmus Date: Mon, 2 Feb 2015 17:45:50 -0700 Subject: [PATCH] servo: Merge #4783 - Fix 'inline-block' sizing issues (from mttr:inline_block_percentage); r=mbrubeck The first commit fixes #3624, and the second commit fixes a bug uncovered by the first fix and caught by a reftest (according to CSS 2.1, inline-blocks should have the shrink-to-fit algorithm run on them when size is set to 'auto'). The two new reftests included here fail before the fix and pass afterwards. Source-Repo: https://github.com/servo/servo Source-Revision: 986f9cb5432dc51e37e0c47a4f430c0353c6dc75 --- servo/components/layout/block.rs | 11 +++++++++-- servo/components/layout/inline.rs | 13 ++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/servo/components/layout/block.rs b/servo/components/layout/block.rs index f7f7dde2b482..167e3d99ddca 100644 --- a/servo/components/layout/block.rs +++ b/servo/components/layout/block.rs @@ -2153,7 +2153,7 @@ pub trait ISizeAndMarginsComputer { /// available_inline-size /// where available_inline-size = CB inline-size - (horizontal border + padding) fn solve_block_inline_size_constraints(&self, - _: &mut BlockFlow, + block: &mut BlockFlow, input: &ISizeConstraintInput) -> ISizeConstraintSolution { let (computed_inline_size, inline_start_margin, inline_end_margin, available_inline_size) = @@ -2180,7 +2180,7 @@ pub trait ISizeAndMarginsComputer { // Invariant: inline-start_margin + inline-size + inline-end_margin == // available_inline-size - let (inline_start_margin, inline_size, inline_end_margin) = + let (inline_start_margin, mut inline_size, inline_end_margin) = match (inline_start_margin, computed_inline_size, inline_end_margin) { // If all have a computed value other than 'auto', the system is // over-constrained so we discard the end margin. @@ -2213,6 +2213,13 @@ pub trait ISizeAndMarginsComputer { (margin, inline_size, margin) } }; + + // If inline-size is set to 'auto', and this is an inline block, use the + // shrink to fit algorithm (see CSS 2.1 ยง 10.3.9) + if computed_inline_size == MaybeAuto::Auto && block.is_inline_block() { + inline_size = block.get_shrink_to_fit_inline_size(inline_size); + } + ISizeConstraintSolution::new(inline_size, inline_start_margin, inline_end_margin) } } diff --git a/servo/components/layout/inline.rs b/servo/components/layout/inline.rs index c1a518dbfe96..722acc51d15e 100644 --- a/servo/components/layout/inline.rs +++ b/servo/components/layout/inline.rs @@ -1117,10 +1117,10 @@ impl Flow for InlineFlow { debug!("InlineFlow::assign_inline_sizes: floats in: {:?}", self.base.floats); - self.base.position.size.inline = self.base.block_container_inline_size; + let inline_size = self.base.block_container_inline_size; + self.base.position.size.inline = inline_size; { - let inline_size = self.base.position.size.inline; let this = &mut *self; for fragment in this.fragments.fragments.iter_mut() { fragment.compute_border_and_padding(inline_size); @@ -1130,11 +1130,14 @@ impl Flow for InlineFlow { } } - // If there are any inline-block kids, propagate explicit block sizes down to them. + // If there are any inline-block kids, propagate explicit block and inline + // sizes down to them. let block_container_explicit_block_size = self.base.block_container_explicit_block_size; for kid in self.base.child_iter() { - flow::mut_base(kid).block_container_explicit_block_size = - block_container_explicit_block_size; + let kid_base = flow::mut_base(kid); + + kid_base.block_container_inline_size = inline_size; + kid_base.block_container_explicit_block_size = block_container_explicit_block_size; } }