layout: Make percentage heights propagate through inline flows.

I found this random bug during an attempt to improve Wikipedia.
This commit is contained in:
Patrick Walton 2014-09-19 17:19:18 -07:00
parent 08e004d106
commit 39d7bf93d6
6 changed files with 51 additions and 18 deletions

View file

@ -513,10 +513,6 @@ pub struct BlockFlow {
/// block formatting contexts. /// block formatting contexts.
previous_float_inline_size: Option<Au>, 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. /// Additional floating flow members.
pub float: Option<Box<FloatedBlockInfo>> pub float: Option<Box<FloatedBlockInfo>>
} }
@ -529,7 +525,6 @@ impl BlockFlow {
is_root: false, is_root: false,
static_b_offset: Au::new(0), static_b_offset: Au::new(0),
previous_float_inline_size: None, previous_float_inline_size: None,
block_container_explicit_block_size: None,
float: None float: None
} }
} }
@ -541,7 +536,6 @@ impl BlockFlow {
is_root: false, is_root: false,
static_b_offset: Au::new(0), static_b_offset: Au::new(0),
previous_float_inline_size: None, previous_float_inline_size: None,
block_container_explicit_block_size: None,
float: None float: None
} }
} }
@ -556,7 +550,6 @@ impl BlockFlow {
is_root: false, is_root: false,
static_b_offset: Au::new(0), static_b_offset: Au::new(0),
previous_float_inline_size: None, previous_float_inline_size: None,
block_container_explicit_block_size: None,
float: Some(box FloatedBlockInfo::new(float_kind, base.writing_mode)), float: Some(box FloatedBlockInfo::new(float_kind, base.writing_mode)),
base: base, base: base,
} }
@ -983,7 +976,7 @@ impl BlockFlow {
let mut candidate_block_size_iterator = CandidateBSizeIterator::new( let mut candidate_block_size_iterator = CandidateBSizeIterator::new(
self.fragment.style(), 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 { for candidate_block_size in candidate_block_size_iterator {
candidate_block_size_iterator.candidate_value = match candidate_block_size { candidate_block_size_iterator.candidate_value = match candidate_block_size {
Auto => block_size, Auto => block_size,
@ -1324,11 +1317,11 @@ impl BlockFlow {
self.base.position.start.b self.base.position.start.b
} }
/// Assigns the computed inline-start content edge and inline-size to all the children of this block flow. /// Assigns the computed inline-start content edge and inline-size to all the children of this
/// Also computes whether each child will be impacted by floats. /// 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 /// `#[inline(always)]` because this is called only from block or table inline-size assignment
/// the code for block layout is significantly simpler. /// and the code for block layout is significantly simpler.
#[inline(always)] #[inline(always)]
pub fn propagate_assigned_inline_size_to_children(&mut self, pub fn propagate_assigned_inline_size_to_children(&mut self,
inline_start_content_edge: Au, inline_start_content_edge: Au,
@ -1355,16 +1348,16 @@ impl BlockFlow {
// This value is used only for table cells. // This value is used only for table cells.
let mut inline_start_margin_edge = inline_start_content_edge; 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 // The inline-size of the last float, if there was one. This is used for estimating the
// block formatting contexts. (We estimate that the inline-size of any block formatting context // inline-sizes of block formatting contexts. (We estimate that the inline-size of any
// that we see will be based on the inline-size of the containing block as well as the last float // block formatting context that we see will be based on the inline-size of the containing
// seen before it.) // block as well as the last float seen before it.)
let mut last_float_inline_size = None; let mut last_float_inline_size = None;
// Calculate non-auto block size to pass to children. // Calculate non-auto block size to pass to children.
let content_block_size = self.fragment.style().content_block_size(); let content_block_size = self.fragment.style().content_block_size();
let explicit_content_size = match (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)) => { (LPA_Percentage(percent), Some(container_size)) => {
Some(container_size.scale_by(percent)) Some(container_size.scale_by(percent))
} }
@ -1373,6 +1366,8 @@ impl BlockFlow {
}; };
for (i, kid) in self.base.child_iter().enumerate() { 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() { if kid.is_block_flow() {
let kid_block = kid.as_block(); let kid_block = kid.as_block();
kid_block.base.absolute_static_i_offset = absolute_static_i_offset; kid_block.base.absolute_static_i_offset = absolute_static_i_offset;
@ -1383,7 +1378,6 @@ impl BlockFlow {
} else { } else {
kid_block.previous_float_inline_size = last_float_inline_size 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 // The inline-start margin edge of the child flow is at our inline-start content edge, and its inline-size

View file

@ -704,6 +704,10 @@ pub struct BaseFlow {
/// containing block. This is in tree order. This includes any direct children. /// containing block. This is in tree order. This includes any direct children.
pub abs_descendants: AbsDescendants, 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 /// Offset wrt the nearest positioned ancestor - aka the Containing Block
/// for any absolutely positioned elements. /// for any absolutely positioned elements.
pub absolute_static_i_offset: Au, pub absolute_static_i_offset: Au,
@ -786,6 +790,7 @@ impl BaseFlow {
abs_descendants: Descendants::new(), abs_descendants: Descendants::new(),
absolute_static_i_offset: Au::new(0), absolute_static_i_offset: Au::new(0),
fixed_static_i_offset: Au::new(0), fixed_static_i_offset: Au::new(0),
block_container_explicit_block_size: None,
absolute_cb: ContainingBlockLink::new(), absolute_cb: ContainingBlockLink::new(),
display_list: DisplayList::new(), display_list: DisplayList::new(),
layers: DList::new(), layers: DList::new(),

View file

@ -957,6 +957,13 @@ impl Flow for InlineFlow {
fragment.assign_replaced_inline_size_if_necessary(inline_size); 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. /// Calculate and set the block-size of this flow. See CSS 2.1 § 10.6.1.

View file

@ -134,3 +134,4 @@ flaky_gpu,flaky_linux == acid2_noscroll.html acid2_ref_broken.html
== table_padding_a.html table_padding_ref.html == table_padding_a.html table_padding_ref.html
== img_block_display_a.html img_block_display_ref.html == img_block_display_a.html img_block_display_ref.html
== after_block_iteration.html after_block_iteration_ref.html == after_block_iteration.html after_block_iteration_ref.html
== inline_block_percentage_height_a.html inline_block_percentage_height_ref.html

View file

@ -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>

View file

@ -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>