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

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

Issue 14964004: Implement preserveAspectRatio=none for SVG images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months 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 | « LayoutTests/svg/custom/image-with-preserveAspectRatio-none-expected.html ('k') | no next file » | 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 8ed9a1a845b97b51efc1370e708d0bf7d9a8b16a..18928e9bf07af04cb13045a4c233fb3179f94cbf 100644
--- a/Source/core/rendering/svg/RenderSVGImage.cpp
+++ b/Source/core/rendering/svg/RenderSVGImage.cpp
@@ -67,16 +67,32 @@ bool RenderSVGImage::updateImageViewport()
{
SVGImageElement* image = static_cast<SVGImageElement*>(node());
FloatRect oldBoundaries = m_objectBoundingBox;
+ bool updatedViewport = false;
SVGLengthContext lengthContext(image);
m_objectBoundingBox = FloatRect(image->x().value(lengthContext), image->y().value(lengthContext), image->width().value(lengthContext), image->height().value(lengthContext));
- if (oldBoundaries == m_objectBoundingBox)
- return false;
+ // Images with preserveAspectRatio=none should force non-uniform scaling. This can be achieved
+ // by setting the image's container size to its intrinsic size.
+ // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRatio’ attribute.
+ if (image->preserveAspectRatio().align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) {
+ if (CachedImage* cachedImage = m_imageResource->cachedImage()) {
+ LayoutSize intrinsicSize = cachedImage->imageSizeForRenderer(0, style()->effectiveZoom());
+ if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom())) {
+ m_imageResource->setContainerSizeForRenderer(roundedIntSize(intrinsicSize));
+ updatedViewport = true;
+ }
+ }
+ }
+
+ if (oldBoundaries != m_objectBoundingBox) {
+ if (!updatedViewport)
+ m_imageResource->setContainerSizeForRenderer(enclosingIntRect(m_objectBoundingBox).size());
+ updatedViewport = true;
+ m_needsBoundariesUpdate = true;
+ }
- m_imageResource->setContainerSizeForRenderer(enclosingIntRect(m_objectBoundingBox).size());
- m_needsBoundariesUpdate = true;
- return true;
+ return updatedViewport;
}
void RenderSVGImage::layout()
« no previous file with comments | « LayoutTests/svg/custom/image-with-preserveAspectRatio-none-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698