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

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: 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 | « LayoutTests/svg/custom/svg-image-par-none-no-intrinsic-size-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 842319d72e3da3cdb116fbfda47fb4e1c7062ba4..a9cf83413a48fd51fd58e01637956ed73d9a38a0 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,21 @@ void RenderSVGImage::destroy()
RenderSVGModelObject::destroy();
}
+static bool hasIntrinsicSize(ImageResource* imageResource)
+{
+ if (!imageResource)
+ return false;
+ Length intrinsicWidth;
+ Length intrinsicHeight;
+ FloatSize intrinsicRatio;
+ imageResource->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
+ if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed())
+ return false;
+ if (!floatValueForLength(intrinsicWidth, 0) || !floatValueForLength(intrinsicHeight, 0))
pdr. 2014/09/10 03:21:48 Are these checks correct when the user does want a
fs 2014/09/10 09:31:00 This could be considered a "counter-weight" to how
+ return false;
+ return true;
+}
+
bool RenderSVGImage::updateImageViewport()
{
SVGImageElement* image = toSVGImageElement(element());
@@ -72,11 +88,14 @@ 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.
+ // 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, 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.
IntSize newViewportSize;
- if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) {
+ if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE
pdr. 2014/09/10 03:21:48 The code change here looks good but I think we can
fs 2014/09/10 09:31:00 Certainly looks better. Done.
+ && hasIntrinsicSize(m_imageResource->cachedImage())) {
LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effectiveZoom());
if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom())) {
newViewportSize = roundedIntSize(intrinsicSize);
« no previous file with comments | « LayoutTests/svg/custom/svg-image-par-none-no-intrinsic-size-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698