Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1570)

Unified Diff: Source/core/rendering/svg/RenderSVGImage.cpp

Issue 713263002: Use the viewBox when scaling <svg:image>s non-uniformly w/ pAR=none (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: The computeImageViewportSize approach. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/rendering/svg/RenderSVGImage.h ('k') | Source/platform/graphics/Image.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2f7849f6d695548ce67be709e40fc0cd3a1704e7 100644
--- a/Source/core/rendering/svg/RenderSVGImage.cpp
+++ b/Source/core/rendering/svg/RenderSVGImage.cpp
@@ -61,58 +61,43 @@ void RenderSVGImage::destroy()
RenderSVGModelObject::destroy();
}
-bool RenderSVGImage::forceNonUniformScaling(SVGImageElement* image) const
+FloatSize RenderSVGImage::computeImageViewportSize(ImageResource& cachedImage) const
{
+ if (toSVGImageElement(element())->preserveAspectRatio()->currentValue()->align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE)
+ return m_objectBoundingBox.size();
+
// 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.
+ // 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.
- 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;
+ cachedImage.computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
+ return intrinsicRatio;
}
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;
- 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;
+ ImageResource* cachedImage = m_imageResource->cachedImage();
+ if (cachedImage && cachedImage->usesImageContainerSize()) {
+ FloatSize imageViewportSize = computeImageViewportSize(*cachedImage);
+ if (imageViewportSize != m_imageResource->imageSize(style()->effectiveZoom())) {
+ m_imageResource->setContainerSizeForRenderer(roundedIntSize(imageViewportSize));
updatedViewport = true;
}
- } else if (boundsChanged) {
- newViewportSize = enclosingIntRect(m_objectBoundingBox).size();
- updatedViewport = true;
}
- if (updatedViewport)
- m_imageResource->setContainerSizeForRenderer(newViewportSize);
+
m_needsBoundariesUpdate |= boundsChanged;
- return updatedViewport;
+ return updatedViewport || boundsChanged;
}
void RenderSVGImage::layout()
« no previous file with comments | « Source/core/rendering/svg/RenderSVGImage.h ('k') | Source/platform/graphics/Image.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698