- Revision
- 116271
- Author
- [email protected]
- Date
- 2012-05-06 22:05:25 -0700 (Sun, 06 May 2012)
Log Message
Merge 114095 - Background width (or height) is wrong if width (or height) * zoom < 1.
https://bugs.webkit.org/show_bug.cgi?id=83350
Reviewed by Nikolas Zimmermann.
Source/WebCore:
calculateImageIntrinsicDimension will return wrong size if the calculated size is 0.
0 is used for expressing unspecfied, so the method returns the box width(height) instead.
Since CachedImage has already similar code, we moved it to IntSize and shared it.
Tests: fast/css/zoom-background-repeat-x-expected.html
fast/css/zoom-background-repeat-x.html
fast/css/zoom-background-repeat-y-expected.html
fast/css/zoom-background-repeat-y.html
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::imageSizeForRenderer):
* platform/graphics/IntSize.h:
(IntSize):
(WebCore::IntSize::scale):
(WebCore::IntSize::clampToMinimumSize):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::calculateImageIntrinsicDimensions):
LayoutTests:
* fast/css/zoom-background-repeat-x-expected.html: Added.
* fast/css/zoom-background-repeat-x.html: Added.
* fast/css/zoom-background-repeat-y-expected.html: Added.
* fast/css/zoom-background-repeat-y.html: Added.
[email protected]
Review URL: https://chromiumcodereview.appspot.com/10379031
Modified Paths
Added Paths
Diff
Copied: branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-x-expected.html (from rev 114095, trunk/LayoutTests/fast/css/zoom-background-repeat-x-expected.html) (0 => 116271)
--- branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-x-expected.html (rev 0)
+++ branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-x-expected.html 2012-05-07 05:05:25 UTC (rev 116271)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+ #content {
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABhJREFUeF4FwTEBAAAAgjD7FzESWfjYdgwEoAJ4lTsaxgAAAABJRU5ErkJggg==);
+ background-repeat: repeat-y;
+
+ background-color: green;
+
+ height: 1px;
+ width: 90px;
+ }
+</style>
+</head>
+<body>
+<div id="content"></div>
+</body></html>
Copied: branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-x.html (from rev 114095, trunk/LayoutTests/fast/css/zoom-background-repeat-x.html) (0 => 116271)
--- branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-x.html (rev 0)
+++ branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-x.html 2012-05-07 05:05:25 UTC (rev 116271)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+ #content {
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABhJREFUeF4FwTEBAAAAgjD7FzESWfjYdgwEoAJ4lTsaxgAAAABJRU5ErkJggg==);
+ background-repeat: repeat-y;
+
+ background-color: green;
+
+ height: 1px;
+ width: 100px;
+ zoom: 0.9;
+ }
+</style>
+</head>
+<body>
+<div id="content"></div>
+</body></html>
Copied: branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-y-expected.html (from rev 114095, trunk/LayoutTests/fast/css/zoom-background-repeat-y-expected.html) (0 => 116271)
--- branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-y-expected.html (rev 0)
+++ branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-y-expected.html 2012-05-07 05:05:25 UTC (rev 116271)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+ #content {
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABhJREFUeF4FwTEBAAAAgjD7FzESWfjYdgwEoAJ4lTsaxgAAAABJRU5ErkJggg==);
+ background-repeat: repeat-y;
+
+ background-color: green;
+
+ height: 90px;
+ }
+</style>
+</head>
+<body>
+<div id="content"></div>
+</body></html>
Copied: branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-y.html (from rev 114095, trunk/LayoutTests/fast/css/zoom-background-repeat-y.html) (0 => 116271)
--- branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-y.html (rev 0)
+++ branches/chromium/1084/LayoutTests/fast/css/zoom-background-repeat-y.html 2012-05-07 05:05:25 UTC (rev 116271)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+ #content {
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABhJREFUeF4FwTEBAAAAgjD7FzESWfjYdgwEoAJ4lTsaxgAAAABJRU5ErkJggg==);
+ background-repeat: repeat-y;
+
+ background-color: green;
+
+ height: 100px;
+ zoom: 0.9;
+ }
+</style>
+</head>
+<body>
+<div id="content"></div>
+</body></html>
Modified: branches/chromium/1084/Source/WebCore/loader/cache/CachedImage.cpp (116270 => 116271)
--- branches/chromium/1084/Source/WebCore/loader/cache/CachedImage.cpp 2012-05-07 04:41:50 UTC (rev 116270)
+++ branches/chromium/1084/Source/WebCore/loader/cache/CachedImage.cpp 2012-05-07 05:05:25 UTC (rev 116271)
@@ -259,15 +259,12 @@
return imageSize;
// Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
- bool hasWidth = imageSize.width() > 0;
- bool hasHeight = imageSize.height() > 0;
- int width = imageSize.width() * (m_image->hasRelativeWidth() ? 1.0f : multiplier);
- int height = imageSize.height() * (m_image->hasRelativeHeight() ? 1.0f : multiplier);
- if (hasWidth)
- width = max(1, width);
- if (hasHeight)
- height = max(1, height);
- return IntSize(width, height);
+ float widthScale = m_image->hasRelativeWidth() ? 1.0f : multiplier;
+ float heightScale = m_image->hasRelativeHeight() ? 1.0f : multiplier;
+ IntSize minimumSize(imageSize.width() > 0 ? 1 : 0, imageSize.height() > 0 ? 1 : 0);
+ imageSize.scale(widthScale, heightScale);
+ imageSize.clampToMinimumSize(minimumSize);
+ return imageSize;
}
void CachedImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio, float scaleFactor)
Modified: branches/chromium/1084/Source/WebCore/platform/graphics/IntSize.h (116270 => 116271)
--- branches/chromium/1084/Source/WebCore/platform/graphics/IntSize.h 2012-05-07 04:41:50 UTC (rev 116270)
+++ branches/chromium/1084/Source/WebCore/platform/graphics/IntSize.h 2012-05-07 05:05:25 UTC (rev 116271)
@@ -80,13 +80,18 @@
m_width += width;
m_height += height;
}
+
+ void scale(float widthScale, float heightScale)
+ {
+ m_width = static_cast<int>(static_cast<float>(m_width) * widthScale);
+ m_height = static_cast<int>(static_cast<float>(m_height) * heightScale);
+ }
void scale(float scale)
{
- m_width = static_cast<int>(static_cast<float>(m_width) * scale);
- m_height = static_cast<int>(static_cast<float>(m_height) * scale);
+ this->scale(scale, scale);
}
-
+
IntSize expandedTo(const IntSize& other) const
{
return IntSize(m_width > other.m_width ? m_width : other.m_width,
@@ -104,6 +109,14 @@
*this = expandedTo(IntSize());
}
+ void clampToMinimumSize(const IntSize& minimumSize)
+ {
+ if (m_width < minimumSize.width())
+ m_width = minimumSize.width();
+ if (m_height < minimumSize.height())
+ m_height = minimumSize.height();
+ }
+
int diagonalLengthSquared() const
{
return m_width * m_width + m_height * m_height;
Modified: branches/chromium/1084/Source/WebCore/rendering/RenderBoxModelObject.cpp (116270 => 116271)
--- branches/chromium/1084/Source/WebCore/rendering/RenderBoxModelObject.cpp 2012-05-07 04:41:50 UTC (rev 116270)
+++ branches/chromium/1084/Source/WebCore/rendering/RenderBoxModelObject.cpp 2012-05-07 05:05:25 UTC (rev 116271)
@@ -955,49 +955,45 @@
IntSize RenderBoxModelObject::calculateImageIntrinsicDimensions(StyleImage* image, const IntSize& positioningAreaSize) const
{
- int resolvedWidth = 0;
- int resolvedHeight = 0;
- FloatSize intrinsicRatio;
-
// A generated image without a fixed size, will always return the container size as intrinsic size.
- if (image->isGeneratedImage() && image->usesImageContainerSize()) {
- resolvedWidth = positioningAreaSize.width();
- resolvedHeight = positioningAreaSize.height();
- } else {
- Length intrinsicWidth;
- Length intrinsicHeight;
- image->computeIntrinsicDimensions(this, intrinsicWidth, intrinsicHeight, intrinsicRatio);
+ if (image->isGeneratedImage() && image->usesImageContainerSize())
+ return IntSize(positioningAreaSize.width(), positioningAreaSize.height());
- // Intrinsic dimensions expressed as percentages must be resolved relative to the dimensions of the rectangle
- // that establishes the coordinate system for the 'background-position' property.
+ Length intrinsicWidth;
+ Length intrinsicHeight;
+ FloatSize intrinsicRatio;
+ image->computeIntrinsicDimensions(this, intrinsicWidth, intrinsicHeight, intrinsicRatio);
- // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/63656
- if (intrinsicWidth.isPercent() && intrinsicHeight.isPercent() && intrinsicRatio.isEmpty()) {
- // Resolve width/height percentages against positioningAreaSize, only if no intrinsic ratio is provided.
- resolvedWidth = static_cast<int>(round(positioningAreaSize.width() * intrinsicWidth.percent() / 100));
- resolvedHeight = static_cast<int>(round(positioningAreaSize.height() * intrinsicHeight.percent() / 100));
- } else {
- if (intrinsicWidth.isFixed())
- resolvedWidth = static_cast<int>(intrinsicWidth.value() * style()->effectiveZoom());
- if (intrinsicHeight.isFixed())
- resolvedHeight = static_cast<int>(intrinsicHeight.value() * style()->effectiveZoom());
- }
+ // Intrinsic dimensions expressed as percentages must be resolved relative to the dimensions of the rectangle
+ // that establishes the coordinate system for the 'background-position' property.
+
+ // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/63656
+ if (intrinsicWidth.isPercent() && intrinsicHeight.isPercent() && intrinsicRatio.isEmpty()) {
+ // Resolve width/height percentages against positioningAreaSize, only if no intrinsic ratio is provided.
+ int resolvedWidth = static_cast<int>(round(positioningAreaSize.width() * intrinsicWidth.percent() / 100));
+ int resolvedHeight = static_cast<int>(round(positioningAreaSize.height() * intrinsicHeight.percent() / 100));
+ return IntSize(resolvedWidth, resolvedHeight);
}
- if (resolvedWidth > 0 && resolvedHeight > 0)
- return IntSize(resolvedWidth, resolvedHeight);
+ IntSize resolvedSize(intrinsicWidth.isFixed() ? intrinsicWidth.value() : 0, intrinsicHeight.isFixed() ? intrinsicHeight.value() : 0);
+ IntSize minimumSize(resolvedSize.width() > 0 ? 1 : 0, resolvedSize.height() > 0 ? 1 : 0);
+ resolvedSize.scale(style()->effectiveZoom());
+ resolvedSize.clampToMinimumSize(minimumSize);
+ if (!resolvedSize.isEmpty())
+ return resolvedSize;
+
// If the image has one of either an intrinsic width or an intrinsic height:
// * and an intrinsic aspect ratio, then the missing dimension is calculated from the given dimension and the ratio.
// * and no intrinsic aspect ratio, then the missing dimension is assumed to be the size of the rectangle that
// establishes the coordinate system for the 'background-position' property.
- if ((resolvedWidth && !resolvedHeight) || (!resolvedWidth && resolvedHeight))
- return resolveAgainstIntrinsicWidthOrHeightAndRatio(positioningAreaSize, intrinsicRatio, resolvedWidth, resolvedHeight);
+ if (resolvedSize.width() > 0 || resolvedSize.height() > 0)
+ return resolveAgainstIntrinsicWidthOrHeightAndRatio(positioningAreaSize, intrinsicRatio, resolvedSize.width(), resolvedSize.height());
// If the image has no intrinsic dimensions and has an intrinsic ratio the dimensions must be assumed to be the
// largest dimensions at that ratio such that neither dimension exceeds the dimensions of the rectangle that
// establishes the coordinate system for the 'background-position' property.
- if (!resolvedWidth && !resolvedHeight && !intrinsicRatio.isEmpty())
+ if (!intrinsicRatio.isEmpty())
return resolveAgainstIntrinsicRatio(positioningAreaSize, intrinsicRatio);
// If the image has no intrinsic ratio either, then the dimensions must be assumed to be the rectangle that