Commit 48c774d1 authored by Stephen Chenney's avatar Stephen Chenney Committed by Commit Bot

Fix background-size auto when no intrinsic size

According to the spec,
https://drafts.csswg.org/css-backgrounds-3/#background-size,
a background-size of "auto" with no intrinsic ratio or size
should use 100% for the auto value.

Instead we were using the positioning area's intrinsic ratio.
Fix it.

R=fmalita@chromium.org
BUG=828842

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Ia8d665ff2c725c9e40a89c0e160584feedc41b86
Reviewed-on: https://chromium-review.googlesource.com/996214
Commit-Queue: Stephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarFlorin Malita <fmalita@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548596}
parent 29cc37fa
<!DOCTYPE html>
<style>
div {
background-image: radial-gradient(red, yellow, green);
background-repeat: no-repeat;
border: solid 1px black;
margin: 10px;
}
.horizontal {
background-size: 100% 50%;
width: 200px;
height: 100px;
}
.vertical {
background-size: 50% 100%;
width: 100px;
height: 200px;
}
</style>
<div class="horizontal">
</div>
<div class="vertical">
</div>
<!DOCTYPE html>
<style>
div {
background-image: radial-gradient(red, yellow, green);
background-repeat: no-repeat;
border: solid 1px black;
margin: 10px;
}
.horizontal {
background-size: auto 50%;
width: 200px;
height: 100px;
}
.vertical {
background-size: 50% auto;
width: 100px;
height: 200px;
}
</style>
<div class="horizontal">
</div>
<div class="vertical">
</div>
......@@ -87,7 +87,11 @@ LayoutSize CalculateFillTileSize(const LayoutBoxModelObject& obj,
// If one of the values is auto we have to use the appropriate
// scale to maintain our aspect ratio.
if (layer_width.IsAuto() && !layer_height.IsAuto()) {
if (image_intrinsic_size.Height()) {
if (image->ImageHasRelativeSize()) {
// Spec says that auto should be 100% in the absence of
// an intrinsic ratio or size.
tile_size.SetWidth(positioning_area_size.Width());
} else if (image_intrinsic_size.Height()) {
LayoutUnit adjusted_width = image_intrinsic_size.Width() *
tile_size.Height() /
image_intrinsic_size.Height();
......@@ -96,7 +100,11 @@ LayoutSize CalculateFillTileSize(const LayoutBoxModelObject& obj,
tile_size.SetWidth(adjusted_width);
}
} else if (!layer_width.IsAuto() && layer_height.IsAuto()) {
if (image_intrinsic_size.Width()) {
if (image->ImageHasRelativeSize()) {
// Spec says that auto should be 100% in the absence of
// an intrinsic ratio or size.
tile_size.SetHeight(positioning_area_size.Height());
} else if (image_intrinsic_size.Width()) {
LayoutUnit adjusted_height = image_intrinsic_size.Height() *
tile_size.Width() /
image_intrinsic_size.Width();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment