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

Unified Diff: third_party/WebKit/Source/core/paint/SVGImagePainter.cpp

Issue 1427943002: Wrap SVGImage for container during paint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use IntSize for SVGImageForContainer Created 5 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
Index: third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
diff --git a/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp b/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
index 1f1be3863911238d9340fbb289e22b3cfab9f0a9..fec17f72e67ea3e15047f5894ccbece6e66dd19b 100644
--- a/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
+++ b/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
@@ -51,7 +51,12 @@ void SVGImagePainter::paint(const PaintInfo& paintInfo)
void SVGImagePainter::paintForeground(const PaintInfo& paintInfo)
{
- RefPtr<Image> image = m_layoutSVGImage.imageResource()->image(IntSize());
+ const LayoutImageResource* imageResource = m_layoutSVGImage.imageResource();
+ IntSize imageViewportSize = expandedIntSize(computeImageViewportSize());
+ if (imageViewportSize.isEmpty())
+ return;
+
+ RefPtr<Image> image = imageResource->image(imageViewportSize, m_layoutSVGImage.style()->effectiveZoom());
FloatRect destRect = m_layoutSVGImage.objectBoundingBox();
FloatRect srcRect(0, 0, image->width(), image->height());
@@ -67,4 +72,24 @@ void SVGImagePainter::paintForeground(const PaintInfo& paintInfo)
paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality);
}
+FloatSize SVGImagePainter::computeImageViewportSize() const
+{
+ ASSERT(m_layoutSVGImage.imageResource()->hasImage());
+
+ if (toSVGImageElement(m_layoutSVGImage.element())->preserveAspectRatio()->currentValue()->align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE)
+ return m_layoutSVGImage.objectBoundingBox().size();
+
+ ImageResource* cachedImage = m_layoutSVGImage.imageResource()->cachedImage();
+
+ // 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.
+ Length intrinsicWidth;
+ Length intrinsicHeight;
+ FloatSize intrinsicRatio;
+ cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
+ return intrinsicRatio;
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/paint/SVGImagePainter.h ('k') | third_party/WebKit/Source/core/style/StyleFetchedImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698