Index: Source/core/rendering/svg/RenderSVGImage.cpp |
diff --git a/Source/core/rendering/svg/RenderSVGImage.cpp b/Source/core/rendering/svg/RenderSVGImage.cpp |
index 0dd6aa8942b9af18c799e3ea5363c1d2ed64cc8c..b0b1f521740b921213cdba5c4fb55431d3221d4b 100644 |
--- a/Source/core/rendering/svg/RenderSVGImage.cpp |
+++ b/Source/core/rendering/svg/RenderSVGImage.cpp |
@@ -61,48 +61,44 @@ void RenderSVGImage::destroy() |
RenderSVGModelObject::destroy(); |
} |
-bool RenderSVGImage::forceNonUniformScaling(SVGImageElement* image) const |
+LayoutSize RenderSVGImage::computeNonUniformScalingViewportSize() const |
{ |
- // Images with preserveAspectRatio=none should force non-uniform |
- // scaling. This can be achieved by setting the image's container size to |
- // its intrinsic size. If the image does not have an intrinsic size - or |
- // the intrinsic size is degenerate - set the container size to the bounds |
- // as in pAR!=none cases. |
- // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRatio’ attribute. |
- if (image->preserveAspectRatio()->currentValue()->align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) |
- return false; |
- ImageResource* cachedImage = m_imageResource->cachedImage(); |
- if (!cachedImage) |
- return false; |
- Length intrinsicWidth; |
- Length intrinsicHeight; |
- FloatSize intrinsicRatio; |
- cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio); |
- if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed()) |
- return false; |
- // If the viewport defined by the referenced image is zero in either |
- // dimension, then SVGImage will have computed an intrinsic size of 300x150. |
- if (!floatValueForLength(intrinsicWidth, 0) || !floatValueForLength(intrinsicHeight, 0)) |
- return false; |
- return true; |
+ // Note: This assumes that the 'intrinsic ratio' as returned by |
pdr.
2014/11/12 00:48:25
Could we document this on the Image interface inst
fs
2014/11/12 10:13:44
Done.
|
+ // ImageResource::computeIntrinsicDimensions (and indirectly the same |
+ // method on Image) is the viewport of the image. This is not documented to |
+ // be the case in the Image interface, but is what the current |
+ // implementations return. |
+ if (ImageResource* cachedImage = m_imageResource->cachedImage()) { |
+ Length intrinsicWidth; |
+ Length intrinsicHeight; |
+ FloatSize intrinsicRatio; |
+ cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio); |
+ if (!intrinsicRatio.isEmpty()) |
+ return roundedLayoutSize(intrinsicRatio); |
+ } |
+ return m_imageResource->intrinsicSize(style()->effectiveZoom()); |
pdr.
2014/11/12 00:48:25
It looks like this will end up just returning an e
fs
2014/11/12 10:13:45
Yes, true. Done.
|
} |
bool RenderSVGImage::updateImageViewport() |
{ |
SVGImageElement* image = toSVGImageElement(element()); |
FloatRect oldBoundaries = m_objectBoundingBox; |
- bool updatedViewport = false; |
SVGLengthContext lengthContext(image); |
m_objectBoundingBox = FloatRect(image->x()->currentValue()->value(lengthContext), image->y()->currentValue()->value(lengthContext), image->width()->currentValue()->value(lengthContext), image->height()->currentValue()->value(lengthContext)); |
bool boundsChanged = oldBoundaries != m_objectBoundingBox; |
+ // Images with preserveAspectRatio=none should force non-uniform |
+ // scaling. This can be achieved by setting the image's container size to |
+ // its viewport size (i.e. if a viewBox is available - use that - else use intrinsic size. |
+ // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRatio’ attribute. |
IntSize newViewportSize; |
- if (forceNonUniformScaling(image)) { |
- LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effectiveZoom()); |
- if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom())) { |
- newViewportSize = roundedIntSize(intrinsicSize); |
+ bool updatedViewport = false; |
+ if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) { |
pdr.
2014/11/12 00:48:25
Could we move the PAR_NONE check and the viewport
fs
2014/11/12 10:13:44
While it's possible to do that, you then get essen
|
+ LayoutSize computedViewportSize = computeNonUniformScalingViewportSize(); |
+ if (computedViewportSize != m_imageResource->imageSize(style()->effectiveZoom())) { |
+ newViewportSize = roundedIntSize(computedViewportSize); |
updatedViewport = true; |
} |
} else if (boundsChanged) { |
@@ -112,7 +108,7 @@ bool RenderSVGImage::updateImageViewport() |
if (updatedViewport) |
m_imageResource->setContainerSizeForRenderer(newViewportSize); |
m_needsBoundariesUpdate |= boundsChanged; |
- return updatedViewport; |
+ return updatedViewport || boundsChanged; |
pdr.
2014/11/12 00:48:25
Does it make sense for the bounds to change but th
fs
2014/11/12 10:13:45
Yes, this would even be expected in the pAR=none c
|
} |
void RenderSVGImage::layout() |