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

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

Issue 551043006: Use correct viewport for intrinsic size-less SVG images in <svg:image> (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Shuffle code; Add additional test. Created 6 years, 3 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 | « Source/core/rendering/svg/RenderSVGImage.h ('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 91d82103edfe93a200e96f7f6c931d083bef9c87..292f2614835de40828487e1c23e9cf517cf315f9 100644
--- a/Source/core/rendering/svg/RenderSVGImage.cpp
+++ b/Source/core/rendering/svg/RenderSVGImage.cpp
@@ -37,6 +37,7 @@
#include "core/rendering/svg/SVGResources.h"
#include "core/rendering/svg/SVGResourcesCache.h"
#include "core/svg/SVGImageElement.h"
+#include "platform/LengthFunctions.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
namespace blink {
@@ -61,6 +62,32 @@ void RenderSVGImage::destroy()
RenderSVGModelObject::destroy();
}
+bool RenderSVGImage::forceNonUniformScaling(SVGImageElement* image) 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;
+}
+
bool RenderSVGImage::updateImageViewport()
{
SVGImageElement* image = toSVGImageElement(element());
@@ -72,11 +99,8 @@ bool RenderSVGImage::updateImageViewport()
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 intrinsic size.
- // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRatio’ attribute.
IntSize newViewportSize;
- if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) {
+ if (forceNonUniformScaling(image)) {
LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effectiveZoom());
if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom())) {
newViewportSize = roundedIntSize(intrinsicSize);
« no previous file with comments | « Source/core/rendering/svg/RenderSVGImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698