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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/svg/RenderSVGImage.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 2 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
3 * Copyright (C) 2006 Apple Computer, Inc. 3 * Copyright (C) 2006 Apple Computer, Inc.
4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
5 * Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org>
6 * Copyright (C) 2009 Google, Inc. 6 * Copyright (C) 2009 Google, Inc.
7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
8 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> 8 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 19 matching lines...) Expand all
30 #include "core/rendering/GraphicsContextAnnotator.h" 30 #include "core/rendering/GraphicsContextAnnotator.h"
31 #include "core/rendering/ImageQualityController.h" 31 #include "core/rendering/ImageQualityController.h"
32 #include "core/rendering/PointerEventsHitRules.h" 32 #include "core/rendering/PointerEventsHitRules.h"
33 #include "core/rendering/RenderImageResource.h" 33 #include "core/rendering/RenderImageResource.h"
34 #include "core/rendering/svg/RenderSVGResource.h" 34 #include "core/rendering/svg/RenderSVGResource.h"
35 #include "core/rendering/svg/SVGRenderSupport.h" 35 #include "core/rendering/svg/SVGRenderSupport.h"
36 #include "core/rendering/svg/SVGRenderingContext.h" 36 #include "core/rendering/svg/SVGRenderingContext.h"
37 #include "core/rendering/svg/SVGResources.h" 37 #include "core/rendering/svg/SVGResources.h"
38 #include "core/rendering/svg/SVGResourcesCache.h" 38 #include "core/rendering/svg/SVGResourcesCache.h"
39 #include "core/svg/SVGImageElement.h" 39 #include "core/svg/SVGImageElement.h"
40 #include "platform/LengthFunctions.h"
40 #include "platform/graphics/GraphicsContextStateSaver.h" 41 #include "platform/graphics/GraphicsContextStateSaver.h"
41 42
42 namespace blink { 43 namespace blink {
43 44
44 RenderSVGImage::RenderSVGImage(SVGImageElement* impl) 45 RenderSVGImage::RenderSVGImage(SVGImageElement* impl)
45 : RenderSVGModelObject(impl) 46 : RenderSVGModelObject(impl)
46 , m_needsBoundariesUpdate(true) 47 , m_needsBoundariesUpdate(true)
47 , m_needsTransformUpdate(true) 48 , m_needsTransformUpdate(true)
48 , m_imageResource(RenderImageResource::create()) 49 , m_imageResource(RenderImageResource::create())
49 { 50 {
50 m_imageResource->initialize(this); 51 m_imageResource->initialize(this);
51 } 52 }
52 53
53 RenderSVGImage::~RenderSVGImage() 54 RenderSVGImage::~RenderSVGImage()
54 { 55 {
55 } 56 }
56 57
57 void RenderSVGImage::destroy() 58 void RenderSVGImage::destroy()
58 { 59 {
59 ImageQualityController::remove(this); 60 ImageQualityController::remove(this);
60 m_imageResource->shutdown(); 61 m_imageResource->shutdown();
61 RenderSVGModelObject::destroy(); 62 RenderSVGModelObject::destroy();
62 } 63 }
63 64
65 bool RenderSVGImage::forceNonUniformScaling(SVGImageElement* image) const
66 {
67 // Images with preserveAspectRatio=none should force non-uniform
68 // scaling. This can be achieved by setting the image's container size to
69 // its intrinsic size. If the image does not have an intrinsic size - or
70 // the intrinsic size is degenerate - set the container size to the bounds
71 // as in pAR!=none cases.
72 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa tio’ attribute.
73 if (image->preserveAspectRatio()->currentValue()->align() != SVGPreserveAspe ctRatio::SVG_PRESERVEASPECTRATIO_NONE)
74 return false;
75 ImageResource* cachedImage = m_imageResource->cachedImage();
76 if (!cachedImage)
77 return false;
78 Length intrinsicWidth;
79 Length intrinsicHeight;
80 FloatSize intrinsicRatio;
81 cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int rinsicRatio);
82 if (!intrinsicWidth.isFixed() || !intrinsicHeight.isFixed())
83 return false;
84 // If the viewport defined by the referenced image is zero in either
85 // dimension, then SVGImage will have computed an intrinsic size of 300x150.
86 if (!floatValueForLength(intrinsicWidth, 0) || !floatValueForLength(intrinsi cHeight, 0))
87 return false;
88 return true;
89 }
90
64 bool RenderSVGImage::updateImageViewport() 91 bool RenderSVGImage::updateImageViewport()
65 { 92 {
66 SVGImageElement* image = toSVGImageElement(element()); 93 SVGImageElement* image = toSVGImageElement(element());
67 FloatRect oldBoundaries = m_objectBoundingBox; 94 FloatRect oldBoundaries = m_objectBoundingBox;
68 bool updatedViewport = false; 95 bool updatedViewport = false;
69 96
70 SVGLengthContext lengthContext(image); 97 SVGLengthContext lengthContext(image);
71 m_objectBoundingBox = FloatRect(image->x()->currentValue()->value(lengthCont ext), image->y()->currentValue()->value(lengthContext), image->width()->currentV alue()->value(lengthContext), image->height()->currentValue()->value(lengthConte xt)); 98 m_objectBoundingBox = FloatRect(image->x()->currentValue()->value(lengthCont ext), image->y()->currentValue()->value(lengthContext), image->width()->currentV alue()->value(lengthContext), image->height()->currentValue()->value(lengthConte xt));
72 99
73 bool boundsChanged = oldBoundaries != m_objectBoundingBox; 100 bool boundsChanged = oldBoundaries != m_objectBoundingBox;
74 101
75 // Images with preserveAspectRatio=none should force non-uniform scaling. Th is can be achieved
76 // by setting the image's container size to its intrinsic size.
77 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRa tio’ attribute.
78 IntSize newViewportSize; 102 IntSize newViewportSize;
79 if (image->preserveAspectRatio()->currentValue()->align() == SVGPreserveAspe ctRatio::SVG_PRESERVEASPECTRATIO_NONE) { 103 if (forceNonUniformScaling(image)) {
80 LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effec tiveZoom()); 104 LayoutSize intrinsicSize = m_imageResource->intrinsicSize(style()->effec tiveZoom());
81 if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom() )) { 105 if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom() )) {
82 newViewportSize = roundedIntSize(intrinsicSize); 106 newViewportSize = roundedIntSize(intrinsicSize);
83 updatedViewport = true; 107 updatedViewport = true;
84 } 108 }
85 } else if (boundsChanged) { 109 } else if (boundsChanged) {
86 newViewportSize = enclosingIntRect(m_objectBoundingBox).size(); 110 newViewportSize = enclosingIntRect(m_objectBoundingBox).size();
87 updatedViewport = true; 111 updatedViewport = true;
88 } 112 }
89 if (updatedViewport) 113 if (updatedViewport)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 253
230 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo int&, const RenderLayerModelObject*) const 254 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo int&, const RenderLayerModelObject*) const
231 { 255 {
232 // this is called from paint() after the localTransform has already been app lied 256 // this is called from paint() after the localTransform has already been app lied
233 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates( )); 257 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates( ));
234 if (!contentRect.isEmpty()) 258 if (!contentRect.isEmpty())
235 rects.append(contentRect); 259 rects.append(contentRect);
236 } 260 }
237 261
238 } // namespace blink 262 } // namespace blink
OLDNEW
« 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