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

Side by Side Diff: Source/core/layout/svg/LayoutSVGImage.cpp

Issue 927583002: Moving RenderSVG* files from rendering/ to layout/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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/layout/svg/LayoutSVGImage.h ('k') | Source/core/layout/svg/LayoutSVGInline.h » ('j') | 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
11 * modify it under the terms of the GNU Library General Public 11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either 12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version. 13 * version 2 of the License, or (at your option) any later version.
14 * 14 *
15 * This library is distributed in the hope that it will be useful, 15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details. 18 * Library General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU Library General Public License 20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to 21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA. 23 * Boston, MA 02110-1301, USA.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 27
28 #include "core/rendering/svg/RenderSVGImage.h" 28 #include "core/layout/svg/LayoutSVGImage.h"
29 29
30 #include "core/layout/ImageQualityController.h" 30 #include "core/layout/ImageQualityController.h"
31 #include "core/layout/LayoutImageResource.h" 31 #include "core/layout/LayoutImageResource.h"
32 #include "core/layout/PointerEventsHitRules.h" 32 #include "core/layout/PointerEventsHitRules.h"
33 #include "core/layout/svg/LayoutSVGResourceContainer.h" 33 #include "core/layout/svg/LayoutSVGResourceContainer.h"
34 #include "core/layout/svg/SVGLayoutSupport.h" 34 #include "core/layout/svg/SVGLayoutSupport.h"
35 #include "core/layout/svg/SVGResources.h" 35 #include "core/layout/svg/SVGResources.h"
36 #include "core/layout/svg/SVGResourcesCache.h" 36 #include "core/layout/svg/SVGResourcesCache.h"
37 #include "core/paint/SVGImagePainter.h" 37 #include "core/paint/SVGImagePainter.h"
38 #include "core/svg/SVGImageElement.h" 38 #include "core/svg/SVGImageElement.h"
39 #include "platform/LengthFunctions.h" 39 #include "platform/LengthFunctions.h"
40 #include "third_party/skia/include/core/SkPicture.h" 40 #include "third_party/skia/include/core/SkPicture.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 RenderSVGImage::RenderSVGImage(SVGImageElement* impl) 44 LayoutSVGImage::LayoutSVGImage(SVGImageElement* impl)
45 : RenderSVGModelObject(impl) 45 : RenderSVGModelObject(impl)
46 , m_needsBoundariesUpdate(true) 46 , m_needsBoundariesUpdate(true)
47 , m_needsTransformUpdate(true) 47 , m_needsTransformUpdate(true)
48 , m_imageResource(LayoutImageResource::create()) 48 , m_imageResource(LayoutImageResource::create())
49 { 49 {
50 m_imageResource->initialize(this); 50 m_imageResource->initialize(this);
51 } 51 }
52 52
53 RenderSVGImage::~RenderSVGImage() 53 LayoutSVGImage::~LayoutSVGImage()
54 { 54 {
55 } 55 }
56 56
57 void RenderSVGImage::destroy() 57 void LayoutSVGImage::destroy()
58 { 58 {
59 ImageQualityController::remove(this); 59 ImageQualityController::remove(this);
60 m_imageResource->shutdown(); 60 m_imageResource->shutdown();
61 RenderSVGModelObject::destroy(); 61 RenderSVGModelObject::destroy();
62 } 62 }
63 63
64 FloatSize RenderSVGImage::computeImageViewportSize(ImageResource& cachedImage) c onst 64 FloatSize LayoutSVGImage::computeImageViewportSize(ImageResource& cachedImage) c onst
65 { 65 {
66 if (toSVGImageElement(element())->preserveAspectRatio()->currentValue()->ali gn() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) 66 if (toSVGImageElement(element())->preserveAspectRatio()->currentValue()->ali gn() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE)
67 return m_objectBoundingBox.size(); 67 return m_objectBoundingBox.size();
68 68
69 // Images with preserveAspectRatio=none should force non-uniform 69 // Images with preserveAspectRatio=none should force non-uniform
70 // scaling. This can be achieved by setting the image's container size to 70 // scaling. This can be achieved by setting the image's container size to
71 // its viewport size (i.e. if a viewBox is available - use that - else use i ntrinsic size.) 71 // its viewport size (i.e. if a viewBox is available - use that - else use i ntrinsic size.)
72 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The 'preserveAspectRa tio' attribute. 72 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The 'preserveAspectRa tio' attribute.
73 Length intrinsicWidth; 73 Length intrinsicWidth;
74 Length intrinsicHeight; 74 Length intrinsicHeight;
75 FloatSize intrinsicRatio; 75 FloatSize intrinsicRatio;
76 cachedImage.computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intr insicRatio); 76 cachedImage.computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intr insicRatio);
77 return intrinsicRatio; 77 return intrinsicRatio;
78 } 78 }
79 79
80 static bool containerSizeIsSetForRenderer(ImageResource& cachedImage, const Layo utObject* renderer) 80 static bool containerSizeIsSetForRenderer(ImageResource& cachedImage, const Layo utObject* renderer)
81 { 81 {
82 const Image* image = cachedImage.image(); 82 const Image* image = cachedImage.image();
83 // If a container size has been specified for this renderer, then 83 // If a container size has been specified for this renderer, then
84 // imageForRenderer() will return the SVGImageForContainer while image() 84 // imageForRenderer() will return the SVGImageForContainer while image()
85 // will return the underlying SVGImage. 85 // will return the underlying SVGImage.
86 return !image->isSVGImage() || image != cachedImage.imageForRenderer(rendere r); 86 return !image->isSVGImage() || image != cachedImage.imageForRenderer(rendere r);
87 } 87 }
88 88
89 bool RenderSVGImage::updateImageViewport() 89 bool LayoutSVGImage::updateImageViewport()
90 { 90 {
91 SVGImageElement* image = toSVGImageElement(element()); 91 SVGImageElement* image = toSVGImageElement(element());
92 FloatRect oldBoundaries = m_objectBoundingBox; 92 FloatRect oldBoundaries = m_objectBoundingBox;
93 93
94 SVGLengthContext lengthContext(image); 94 SVGLengthContext lengthContext(image);
95 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)); 95 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));
96 bool boundsChanged = oldBoundaries != m_objectBoundingBox; 96 bool boundsChanged = oldBoundaries != m_objectBoundingBox;
97 97
98 bool updatedViewport = false; 98 bool updatedViewport = false;
99 ImageResource* cachedImage = m_imageResource->cachedImage(); 99 ImageResource* cachedImage = m_imageResource->cachedImage();
100 if (cachedImage && cachedImage->usesImageContainerSize()) { 100 if (cachedImage && cachedImage->usesImageContainerSize()) {
101 FloatSize imageViewportSize = computeImageViewportSize(*cachedImage); 101 FloatSize imageViewportSize = computeImageViewportSize(*cachedImage);
102 if (LayoutSize(imageViewportSize) != m_imageResource->imageSize(style()- >effectiveZoom()) 102 if (LayoutSize(imageViewportSize) != m_imageResource->imageSize(style()- >effectiveZoom())
103 || !containerSizeIsSetForRenderer(*cachedImage, this)) { 103 || !containerSizeIsSetForRenderer(*cachedImage, this)) {
104 m_imageResource->setContainerSizeForRenderer(roundedIntSize(imageVie wportSize)); 104 m_imageResource->setContainerSizeForRenderer(roundedIntSize(imageVie wportSize));
105 updatedViewport = true; 105 updatedViewport = true;
106 } 106 }
107 } 107 }
108 108
109 m_needsBoundariesUpdate |= boundsChanged; 109 m_needsBoundariesUpdate |= boundsChanged;
110 return updatedViewport || boundsChanged; 110 return updatedViewport || boundsChanged;
111 } 111 }
112 112
113 void RenderSVGImage::layout() 113 void LayoutSVGImage::layout()
114 { 114 {
115 ASSERT(needsLayout()); 115 ASSERT(needsLayout());
116 116
117 updateImageViewport(); 117 updateImageViewport();
118 118
119 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari esUpdate; 119 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundari esUpdate;
120 if (m_needsTransformUpdate) { 120 if (m_needsTransformUpdate) {
121 m_localTransform = toSVGImageElement(element())->calculateAnimatedLocalT ransform(); 121 m_localTransform = toSVGImageElement(element())->calculateAnimatedLocalT ransform();
122 m_needsTransformUpdate = false; 122 m_needsTransformUpdate = false;
123 } 123 }
(...skipping 11 matching lines...) Expand all
135 if (everHadLayout() && selfNeedsLayout()) 135 if (everHadLayout() && selfNeedsLayout())
136 SVGResourcesCache::clientLayoutChanged(this); 136 SVGResourcesCache::clientLayoutChanged(this);
137 137
138 // If our bounds changed, notify the parents. 138 // If our bounds changed, notify the parents.
139 if (transformOrBoundariesUpdate) 139 if (transformOrBoundariesUpdate)
140 RenderSVGModelObject::setNeedsBoundariesUpdate(); 140 RenderSVGModelObject::setNeedsBoundariesUpdate();
141 141
142 clearNeedsLayout(); 142 clearNeedsLayout();
143 } 143 }
144 144
145 void RenderSVGImage::paint(const PaintInfo& paintInfo, const LayoutPoint&) 145 void LayoutSVGImage::paint(const PaintInfo& paintInfo, const LayoutPoint&)
146 { 146 {
147 SVGImagePainter(*this).paint(paintInfo); 147 SVGImagePainter(*this).paint(paintInfo);
148 } 148 }
149 149
150 bool RenderSVGImage::nodeAtFloatPoint(const HitTestRequest& request, HitTestResu lt& result, const FloatPoint& pointInParent, HitTestAction hitTestAction) 150 bool LayoutSVGImage::nodeAtFloatPoint(const HitTestRequest& request, HitTestResu lt& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
151 { 151 {
152 // We only draw in the forground phase, so we only hit-test then. 152 // We only draw in the forground phase, so we only hit-test then.
153 if (hitTestAction != HitTestForeground) 153 if (hitTestAction != HitTestForeground)
154 return false; 154 return false;
155 155
156 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_IMAGE_HITTESTING, request, style()->pointerEvents()); 156 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_IMAGE_HITTESTING, request, style()->pointerEvents());
157 bool isVisible = (style()->visibility() == VISIBLE); 157 bool isVisible = (style()->visibility() == VISIBLE);
158 if (isVisible || !hitRules.requireVisible) { 158 if (isVisible || !hitRules.requireVisible) {
159 FloatPoint localPoint; 159 FloatPoint localPoint;
160 if (!SVGLayoutSupport::transformToUserSpaceAndCheckClipping(this, localT oParentTransform(), pointInParent, localPoint)) 160 if (!SVGLayoutSupport::transformToUserSpaceAndCheckClipping(this, localT oParentTransform(), pointInParent, localPoint))
161 return false; 161 return false;
162 162
163 if (hitRules.canHitFill || hitRules.canHitBoundingBox) { 163 if (hitRules.canHitFill || hitRules.canHitBoundingBox) {
164 if (m_objectBoundingBox.contains(localPoint)) { 164 if (m_objectBoundingBox.contains(localPoint)) {
165 updateHitTestResult(result, roundedLayoutPoint(localPoint)); 165 updateHitTestResult(result, roundedLayoutPoint(localPoint));
166 return true; 166 return true;
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 return false; 171 return false;
172 } 172 }
173 173
174 void RenderSVGImage::imageChanged(WrappedImagePtr, const IntRect*) 174 void LayoutSVGImage::imageChanged(WrappedImagePtr, const IntRect*)
175 { 175 {
176 // The image resource defaults to nullImage until the resource arrives. 176 // The image resource defaults to nullImage until the resource arrives.
177 // This empty image may be cached by SVG resources which must be invalidated . 177 // This empty image may be cached by SVG resources which must be invalidated .
178 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(this)) 178 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(this))
179 resources->removeClientFromCache(this); 179 resources->removeClientFromCache(this);
180 180
181 // Eventually notify parent resources, that we've changed. 181 // Eventually notify parent resources, that we've changed.
182 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this, false); 182 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(this, false);
183 183
184 // Update the SVGImageCache sizeAndScales entry in case image loading finish ed after layout. 184 // Update the SVGImageCache sizeAndScales entry in case image loading finish ed after layout.
185 // (https://bugs.webkit.org/show_bug.cgi?id=99489) 185 // (https://bugs.webkit.org/show_bug.cgi?id=99489)
186 m_objectBoundingBox = FloatRect(); 186 m_objectBoundingBox = FloatRect();
187 updateImageViewport(); 187 updateImageViewport();
188 188
189 m_bufferedForeground.clear(); 189 m_bufferedForeground.clear();
190 190
191 setShouldDoFullPaintInvalidation(); 191 setShouldDoFullPaintInvalidation();
192 } 192 }
193 193
194 void RenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo int&) const 194 void LayoutSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo int&) const
195 { 195 {
196 // this is called from paint() after the localTransform has already been app lied 196 // this is called from paint() after the localTransform has already been app lied
197 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates( )); 197 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates( ));
198 if (!contentRect.isEmpty()) 198 if (!contentRect.isEmpty())
199 rects.append(contentRect); 199 rects.append(contentRect);
200 } 200 }
201 201
202 } // namespace blink 202 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/svg/LayoutSVGImage.h ('k') | Source/core/layout/svg/LayoutSVGInline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698