diff options
author | Martin Robinson <mrobinson@igalia.com> | 2014-06-17 14:53:42 -0700 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2014-06-17 17:23:40 -0700 |
commit | 22ea9a634c767c09e6299495a1969fa8991d9dc2 (patch) | |
tree | b1466bbe9d3973c65a9a549a68777ca4d4578440 | |
parent | 897e39dcf35ff27bc41ccb7990c5d82bb2adf15c (diff) | |
download | servo-22ea9a634c767c09e6299495a1969fa8991d9dc2.tar.gz servo-22ea9a634c767c09e6299495a1969fa8991d9dc2.zip |
Add overflow to child layer size
When creating child layers it is important to consider overflow when
determining the size of the layer. This also means that overflow should
not be too large, so also shrink block width down to the size of their
contained fragment. This means that a block that has been explicitly
sized to width:100px should be 100 pixels wide instead of the width of
its containing block.
-rw-r--r-- | src/components/main/layout/block.rs | 35 | ||||
-rw-r--r-- | src/test/ref/basic.list | 1 | ||||
-rw-r--r-- | src/test/ref/position_fixed_overflow_a.html | 8 | ||||
-rw-r--r-- | src/test/ref/position_fixed_overflow_b.html | 6 |
4 files changed, 38 insertions, 12 deletions
diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 99bb0e076a8..d280e713ee1 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -1256,10 +1256,11 @@ impl BlockFlow { } // If we got here, then we need a new layer. - let size = Size2D(self.base.position.size.width.to_nearest_px() as uint, - self.base.position.size.height.to_nearest_px() as uint); - let origin = Point2D(self.base.abs_position.x.to_nearest_px() as uint, - self.base.abs_position.y.to_nearest_px() as uint); + let layer_rect = self.base.position.union(&self.base.overflow); + let size = Size2D(layer_rect.size.width.to_nearest_px() as uint, + layer_rect.size.height.to_nearest_px() as uint); + let origin = Point2D(layer_rect.origin.x.to_nearest_px() as uint, + layer_rect.origin.y.to_nearest_px() as uint); let scroll_policy = if self.is_fixed() { FixedPosition } else { @@ -1814,15 +1815,25 @@ pub trait WidthAndMarginsComputer { fn set_width_constraint_solutions(&self, block: &mut BlockFlow, solution: WidthConstraintSolution) { - let fragment = block.fragment(); - fragment.margin.left = solution.margin_left; - fragment.margin.right = solution.margin_right; + let mut width = Au(0); + { + let fragment = block.fragment(); + fragment.margin.left = solution.margin_left; + fragment.margin.right = solution.margin_right; + + // The associated fragment has the border box of this flow. + // Left border edge. + fragment.border_box.origin.x = fragment.margin.left; + // Border box width. + width = solution.width + fragment.border_padding.horizontal(); + fragment.border_box.size.width = width; + } - // The associated fragment has the border box of this flow. - // Left border edge. - fragment.border_box.origin.x = fragment.margin.left; - // Border box width. - fragment.border_box.size.width = solution.width + fragment.border_padding.horizontal(); + // We also resize the block itself, to ensure that overflow is not calculated + // as the width of our parent. We might be smaller and we might be larger if we + // overflow. + let flow = flow::mut_base(block); + flow.position.size.width = width; } /// Set the x coordinate of the given flow if it is absolutely positioned. diff --git a/src/test/ref/basic.list b/src/test/ref/basic.list index fe430010bd1..1b86220be0d 100644 --- a/src/test/ref/basic.list +++ b/src/test/ref/basic.list @@ -77,3 +77,4 @@ == linebreak_inline_span_a.html linebreak_inline_span_b.html == overconstrained_block.html overconstrained_block_ref.html == position_fixed_background_color_a.html position_fixed_background_color_b.html +== position_fixed_overflow_a.html position_fixed_overflow_b.html diff --git a/src/test/ref/position_fixed_overflow_a.html b/src/test/ref/position_fixed_overflow_a.html new file mode 100644 index 00000000000..edc21e7d347 --- /dev/null +++ b/src/test/ref/position_fixed_overflow_a.html @@ -0,0 +1,8 @@ +<html> +<body> + <div style="top: 5px; left: 5px; height: 5px; width: 5px; position: fixed;"> + <div style="height: 100px; width: 100px; background: black;"></div> + </div> +</body> +</html> + diff --git a/src/test/ref/position_fixed_overflow_b.html b/src/test/ref/position_fixed_overflow_b.html new file mode 100644 index 00000000000..a8947566153 --- /dev/null +++ b/src/test/ref/position_fixed_overflow_b.html @@ -0,0 +1,6 @@ +<html> +<body> + <div style="top: 5px; left: 5px; height: 100px; width: 100px; position: absolute; background: black;"></div> +</body> +</html> + |