diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2014-09-19 17:19:18 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2014-09-19 17:20:56 -0700 |
commit | 39d7bf93d6122a1f4a849dbd2528f39d772c4839 (patch) | |
tree | 5e7e809b8eea661c9d3c4fa6bb2d1143ecbcda61 | |
parent | 08e004d10650f36af60818fd3c57ca461a97a678 (diff) | |
download | servo-39d7bf93d6122a1f4a849dbd2528f39d772c4839.tar.gz servo-39d7bf93d6122a1f4a849dbd2528f39d772c4839.zip |
layout: Make percentage heights propagate through inline flows.
I found this random bug during an attempt to improve Wikipedia.
-rw-r--r-- | components/layout/block.rs | 30 | ||||
-rw-r--r-- | components/layout/flow.rs | 5 | ||||
-rw-r--r-- | components/layout/inline.rs | 7 | ||||
-rw-r--r-- | tests/ref/basic.list | 1 | ||||
-rw-r--r-- | tests/ref/inline_block_percentage_height_a.html | 13 | ||||
-rw-r--r-- | tests/ref/inline_block_percentage_height_ref.html | 13 |
6 files changed, 51 insertions, 18 deletions
diff --git a/components/layout/block.rs b/components/layout/block.rs index c527412156f..a3611bd639a 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -513,10 +513,6 @@ pub struct BlockFlow { /// block formatting contexts. previous_float_inline_size: Option<Au>, - /// The block-size of the block container of this block, if it is an explicit size (does not - /// depend on content heights). Used for computing percentage values for `height`. - block_container_explicit_block_size: Option<Au>, - /// Additional floating flow members. pub float: Option<Box<FloatedBlockInfo>> } @@ -529,7 +525,6 @@ impl BlockFlow { is_root: false, static_b_offset: Au::new(0), previous_float_inline_size: None, - block_container_explicit_block_size: None, float: None } } @@ -541,7 +536,6 @@ impl BlockFlow { is_root: false, static_b_offset: Au::new(0), previous_float_inline_size: None, - block_container_explicit_block_size: None, float: None } } @@ -556,7 +550,6 @@ impl BlockFlow { is_root: false, static_b_offset: Au::new(0), previous_float_inline_size: None, - block_container_explicit_block_size: None, float: Some(box FloatedBlockInfo::new(float_kind, base.writing_mode)), base: base, } @@ -983,7 +976,7 @@ impl BlockFlow { let mut candidate_block_size_iterator = CandidateBSizeIterator::new( self.fragment.style(), - self.block_container_explicit_block_size); + self.base.block_container_explicit_block_size); for candidate_block_size in candidate_block_size_iterator { candidate_block_size_iterator.candidate_value = match candidate_block_size { Auto => block_size, @@ -1324,11 +1317,11 @@ impl BlockFlow { self.base.position.start.b } - /// Assigns the computed inline-start content edge and inline-size to all the children of this block flow. - /// Also computes whether each child will be impacted by floats. + /// Assigns the computed inline-start content edge and inline-size to all the children of this + /// block flow. Also computes whether each child will be impacted by floats. /// - /// `#[inline(always)]` because this is called only from block or table inline-size assignment and - /// the code for block layout is significantly simpler. + /// `#[inline(always)]` because this is called only from block or table inline-size assignment + /// and the code for block layout is significantly simpler. #[inline(always)] pub fn propagate_assigned_inline_size_to_children(&mut self, inline_start_content_edge: Au, @@ -1355,16 +1348,16 @@ impl BlockFlow { // This value is used only for table cells. let mut inline_start_margin_edge = inline_start_content_edge; - // The inline-size of the last float, if there was one. This is used for estimating the inline-sizes of - // block formatting contexts. (We estimate that the inline-size of any block formatting context - // that we see will be based on the inline-size of the containing block as well as the last float - // seen before it.) + // The inline-size of the last float, if there was one. This is used for estimating the + // inline-sizes of block formatting contexts. (We estimate that the inline-size of any + // block formatting context that we see will be based on the inline-size of the containing + // block as well as the last float seen before it.) let mut last_float_inline_size = None; // Calculate non-auto block size to pass to children. let content_block_size = self.fragment.style().content_block_size(); let explicit_content_size = match (content_block_size, - self.block_container_explicit_block_size) { + self.base.block_container_explicit_block_size) { (LPA_Percentage(percent), Some(container_size)) => { Some(container_size.scale_by(percent)) } @@ -1373,6 +1366,8 @@ impl BlockFlow { }; for (i, kid) in self.base.child_iter().enumerate() { + flow::mut_base(kid).block_container_explicit_block_size = explicit_content_size; + if kid.is_block_flow() { let kid_block = kid.as_block(); kid_block.base.absolute_static_i_offset = absolute_static_i_offset; @@ -1383,7 +1378,6 @@ impl BlockFlow { } else { kid_block.previous_float_inline_size = last_float_inline_size } - kid_block.block_container_explicit_block_size = explicit_content_size; } // The inline-start margin edge of the child flow is at our inline-start content edge, and its inline-size diff --git a/components/layout/flow.rs b/components/layout/flow.rs index e5e869dcc15..9b1a4d7dc02 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -704,6 +704,10 @@ pub struct BaseFlow { /// containing block. This is in tree order. This includes any direct children. pub abs_descendants: AbsDescendants, + /// The block-size of the block container of this flow, if it is an explicit size (does not + /// depend on content heights). Used for computing percentage values for `height`. + pub block_container_explicit_block_size: Option<Au>, + /// Offset wrt the nearest positioned ancestor - aka the Containing Block /// for any absolutely positioned elements. pub absolute_static_i_offset: Au, @@ -786,6 +790,7 @@ impl BaseFlow { abs_descendants: Descendants::new(), absolute_static_i_offset: Au::new(0), fixed_static_i_offset: Au::new(0), + block_container_explicit_block_size: None, absolute_cb: ContainingBlockLink::new(), display_list: DisplayList::new(), layers: DList::new(), diff --git a/components/layout/inline.rs b/components/layout/inline.rs index a4ec4a8d230..ae47937a037 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -957,6 +957,13 @@ impl Flow for InlineFlow { fragment.assign_replaced_inline_size_if_necessary(inline_size); } } + + // If there are any inline-block kids, propagate explicit block 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; + } } /// Calculate and set the block-size of this flow. See CSS 2.1 § 10.6.1. diff --git a/tests/ref/basic.list b/tests/ref/basic.list index ab2bd1c94a4..a758798823a 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -134,3 +134,4 @@ flaky_gpu,flaky_linux == acid2_noscroll.html acid2_ref_broken.html == table_padding_a.html table_padding_ref.html == img_block_display_a.html img_block_display_ref.html == after_block_iteration.html after_block_iteration_ref.html +== inline_block_percentage_height_a.html inline_block_percentage_height_ref.html diff --git a/tests/ref/inline_block_percentage_height_a.html b/tests/ref/inline_block_percentage_height_a.html new file mode 100644 index 00000000000..ce3f98323b8 --- /dev/null +++ b/tests/ref/inline_block_percentage_height_a.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html> +<head> +<title>Hello</title> +</head> +<body> + <div style="height: 100px;"> + <span style="height: 100%;"> + <li style="height: 100%; background: red;"><span>Edit</span></li> + </span> + </div> +</body> +</html> diff --git a/tests/ref/inline_block_percentage_height_ref.html b/tests/ref/inline_block_percentage_height_ref.html new file mode 100644 index 00000000000..b8cbe8c4afd --- /dev/null +++ b/tests/ref/inline_block_percentage_height_ref.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html> +<head> +<title>Hello</title> +</head> +<body> + <div style="height: 100px;"> + <div style="height: 100%;"> + <li style="height: 100%; background: red;"><span>Edit</span></li> + </div> + </div> +</body> +</html> |