OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2008 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2008 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2005, 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2005, 2007 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2009 Google, Inc. | 5 * Copyright (C) 2009 Google, Inc. |
6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
8 * Copyright (C) 2009 Jeff Schiller <codedread@gmail.com> | 8 * Copyright (C) 2009 Jeff Schiller <codedread@gmail.com> |
9 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> | 9 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> |
10 * Copyright (C) 2011 University of Szeged | 10 * Copyright (C) 2011 University of Szeged |
11 * | 11 * |
12 * This library is free software; you can redistribute it and/or | 12 * This library is free software; you can redistribute it and/or |
13 * modify it under the terms of the GNU Library General Public | 13 * modify it under the terms of the GNU Library General Public |
14 * License as published by the Free Software Foundation; either | 14 * License as published by the Free Software Foundation; either |
15 * version 2 of the License, or (at your option) any later version. | 15 * version 2 of the License, or (at your option) any later version. |
16 * | 16 * |
17 * This library is distributed in the hope that it will be useful, | 17 * This library is distributed in the hope that it will be useful, |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 * Library General Public License for more details. | 20 * Library General Public License for more details. |
21 * | 21 * |
22 * You should have received a copy of the GNU Library General Public License | 22 * You should have received a copy of the GNU Library General Public License |
23 * along with this library; see the file COPYING.LIB. If not, write to | 23 * along with this library; see the file COPYING.LIB. If not, write to |
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 * Boston, MA 02110-1301, USA. | 25 * Boston, MA 02110-1301, USA. |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/rendering/svg/RenderSVGShape.h" | 29 #include "core/layout/svg/LayoutSVGShape.h" |
30 | 30 |
31 #include "core/layout/HitTestRequest.h" | 31 #include "core/layout/HitTestRequest.h" |
32 #include "core/layout/PointerEventsHitRules.h" | 32 #include "core/layout/PointerEventsHitRules.h" |
33 #include "core/layout/svg/SVGLayoutSupport.h" | 33 #include "core/layout/svg/SVGLayoutSupport.h" |
34 #include "core/layout/svg/SVGPathData.h" | 34 #include "core/layout/svg/SVGPathData.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/SVGShapePainter.h" | 37 #include "core/paint/SVGShapePainter.h" |
38 #include "core/svg/SVGGraphicsElement.h" | 38 #include "core/svg/SVGGraphicsElement.h" |
39 #include "platform/geometry/FloatPoint.h" | 39 #include "platform/geometry/FloatPoint.h" |
40 #include "platform/graphics/StrokeData.h" | 40 #include "platform/graphics/StrokeData.h" |
41 #include "wtf/MathExtras.h" | 41 #include "wtf/MathExtras.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 RenderSVGShape::RenderSVGShape(SVGGraphicsElement* node) | 45 LayoutSVGShape::LayoutSVGShape(SVGGraphicsElement* node) |
46 : RenderSVGModelObject(node) | 46 : RenderSVGModelObject(node) |
47 , m_needsBoundariesUpdate(false) // Default is false, the cached rects are e
mpty from the beginning. | 47 , m_needsBoundariesUpdate(false) // Default is false, the cached rects are e
mpty from the beginning. |
48 , m_needsShapeUpdate(true) // Default is true, so we grab a Path object once
from SVGGraphicsElement. | 48 , m_needsShapeUpdate(true) // Default is true, so we grab a Path object once
from SVGGraphicsElement. |
49 , m_needsTransformUpdate(true) // Default is true, so we grab a AffineTransf
orm object once from SVGGraphicsElement. | 49 , m_needsTransformUpdate(true) // Default is true, so we grab a AffineTransf
orm object once from SVGGraphicsElement. |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 RenderSVGShape::~RenderSVGShape() | 53 LayoutSVGShape::~LayoutSVGShape() |
54 { | 54 { |
55 } | 55 } |
56 | 56 |
57 void RenderSVGShape::createPath() | 57 void LayoutSVGShape::createPath() |
58 { | 58 { |
59 clearPath(); | 59 clearPath(); |
60 m_path = adoptPtr(new Path); | 60 m_path = adoptPtr(new Path); |
61 ASSERT(RenderSVGShape::isShapeEmpty()); | 61 ASSERT(LayoutSVGShape::isShapeEmpty()); |
62 | 62 |
63 updatePathFromGraphicsElement(toSVGGraphicsElement(element()), path()); | 63 updatePathFromGraphicsElement(toSVGGraphicsElement(element()), path()); |
64 processMarkerPositions(); | 64 processMarkerPositions(); |
65 } | 65 } |
66 | 66 |
67 void RenderSVGShape::updateShapeFromElement() | 67 void LayoutSVGShape::updateShapeFromElement() |
68 { | 68 { |
69 createPath(); | 69 createPath(); |
70 | 70 |
71 m_fillBoundingBox = calculateObjectBoundingBox(); | 71 m_fillBoundingBox = calculateObjectBoundingBox(); |
72 m_strokeBoundingBox = calculateStrokeBoundingBox(); | 72 m_strokeBoundingBox = calculateStrokeBoundingBox(); |
73 } | 73 } |
74 | 74 |
75 bool RenderSVGShape::shapeDependentStrokeContains(const FloatPoint& point) | 75 bool LayoutSVGShape::shapeDependentStrokeContains(const FloatPoint& point) |
76 { | 76 { |
77 ASSERT(m_path); | 77 ASSERT(m_path); |
78 StrokeData strokeData; | 78 StrokeData strokeData; |
79 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this
); | 79 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this
); |
80 | 80 |
81 if (hasNonScalingStroke()) { | 81 if (hasNonScalingStroke()) { |
82 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); | 82 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); |
83 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTransform); | 83 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTransform); |
84 | 84 |
85 return usePath->strokeContains(nonScalingTransform.mapPoint(point), stro
keData); | 85 return usePath->strokeContains(nonScalingTransform.mapPoint(point), stro
keData); |
86 } | 86 } |
87 | 87 |
88 return m_path->strokeContains(point, strokeData); | 88 return m_path->strokeContains(point, strokeData); |
89 } | 89 } |
90 | 90 |
91 bool RenderSVGShape::shapeDependentFillContains(const FloatPoint& point, const W
indRule fillRule) const | 91 bool LayoutSVGShape::shapeDependentFillContains(const FloatPoint& point, const W
indRule fillRule) const |
92 { | 92 { |
93 return path().contains(point, fillRule); | 93 return path().contains(point, fillRule); |
94 } | 94 } |
95 | 95 |
96 bool RenderSVGShape::fillContains(const FloatPoint& point, bool requiresFill, co
nst WindRule fillRule) | 96 bool LayoutSVGShape::fillContains(const FloatPoint& point, bool requiresFill, co
nst WindRule fillRule) |
97 { | 97 { |
98 if (!m_fillBoundingBox.contains(point)) | 98 if (!m_fillBoundingBox.contains(point)) |
99 return false; | 99 return false; |
100 | 100 |
101 if (requiresFill && !SVGPaintServer::existsForRenderer(*this, styleRef(), Ap
plyToFillMode)) | 101 if (requiresFill && !SVGPaintServer::existsForRenderer(*this, styleRef(), Ap
plyToFillMode)) |
102 return false; | 102 return false; |
103 | 103 |
104 return shapeDependentFillContains(point, fillRule); | 104 return shapeDependentFillContains(point, fillRule); |
105 } | 105 } |
106 | 106 |
107 bool RenderSVGShape::strokeContains(const FloatPoint& point, bool requiresStroke
) | 107 bool LayoutSVGShape::strokeContains(const FloatPoint& point, bool requiresStroke
) |
108 { | 108 { |
109 if (!strokeBoundingBox().contains(point)) | 109 if (!strokeBoundingBox().contains(point)) |
110 return false; | 110 return false; |
111 | 111 |
112 if (requiresStroke && !SVGPaintServer::existsForRenderer(*this, styleRef(),
ApplyToStrokeMode)) | 112 if (requiresStroke && !SVGPaintServer::existsForRenderer(*this, styleRef(),
ApplyToStrokeMode)) |
113 return false; | 113 return false; |
114 | 114 |
115 return shapeDependentStrokeContains(point); | 115 return shapeDependentStrokeContains(point); |
116 } | 116 } |
117 | 117 |
118 void RenderSVGShape::updateLocalTransform() | 118 void LayoutSVGShape::updateLocalTransform() |
119 { | 119 { |
120 SVGGraphicsElement* graphicsElement = toSVGGraphicsElement(element()); | 120 SVGGraphicsElement* graphicsElement = toSVGGraphicsElement(element()); |
121 if (graphicsElement->hasAnimatedLocalTransform()) { | 121 if (graphicsElement->hasAnimatedLocalTransform()) { |
122 if (m_localTransform) | 122 if (m_localTransform) |
123 m_localTransform->setTransform(graphicsElement->calculateAnimatedLoc
alTransform()); | 123 m_localTransform->setTransform(graphicsElement->calculateAnimatedLoc
alTransform()); |
124 else | 124 else |
125 m_localTransform = adoptPtr(new AffineTransform(graphicsElement->cal
culateAnimatedLocalTransform())); | 125 m_localTransform = adoptPtr(new AffineTransform(graphicsElement->cal
culateAnimatedLocalTransform())); |
126 } else { | 126 } else { |
127 m_localTransform = 0; | 127 m_localTransform = 0; |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 void RenderSVGShape::layout() | 131 void LayoutSVGShape::layout() |
132 { | 132 { |
133 bool updateCachedBoundariesInParents = false; | 133 bool updateCachedBoundariesInParents = false; |
134 | 134 |
135 if (m_needsShapeUpdate || m_needsBoundariesUpdate) { | 135 if (m_needsShapeUpdate || m_needsBoundariesUpdate) { |
136 updateShapeFromElement(); | 136 updateShapeFromElement(); |
137 m_needsShapeUpdate = false; | 137 m_needsShapeUpdate = false; |
138 updatePaintInvalidationBoundingBox(); | 138 updatePaintInvalidationBoundingBox(); |
139 m_needsBoundariesUpdate = false; | 139 m_needsBoundariesUpdate = false; |
140 updateCachedBoundariesInParents = true; | 140 updateCachedBoundariesInParents = true; |
141 } | 141 } |
142 | 142 |
143 if (m_needsTransformUpdate) { | 143 if (m_needsTransformUpdate) { |
144 updateLocalTransform(); | 144 updateLocalTransform(); |
145 m_needsTransformUpdate = false; | 145 m_needsTransformUpdate = false; |
146 updateCachedBoundariesInParents = true; | 146 updateCachedBoundariesInParents = true; |
147 } | 147 } |
148 | 148 |
149 // Invalidate all resources of this client if our layout changed. | 149 // Invalidate all resources of this client if our layout changed. |
150 if (everHadLayout() && selfNeedsLayout()) | 150 if (everHadLayout() && selfNeedsLayout()) |
151 SVGResourcesCache::clientLayoutChanged(this); | 151 SVGResourcesCache::clientLayoutChanged(this); |
152 | 152 |
153 // If our bounds changed, notify the parents. | 153 // If our bounds changed, notify the parents. |
154 if (updateCachedBoundariesInParents) | 154 if (updateCachedBoundariesInParents) |
155 RenderSVGModelObject::setNeedsBoundariesUpdate(); | 155 RenderSVGModelObject::setNeedsBoundariesUpdate(); |
156 | 156 |
157 clearNeedsLayout(); | 157 clearNeedsLayout(); |
158 } | 158 } |
159 | 159 |
160 Path* RenderSVGShape::nonScalingStrokePath(const Path* path, const AffineTransfo
rm& strokeTransform) const | 160 Path* LayoutSVGShape::nonScalingStrokePath(const Path* path, const AffineTransfo
rm& strokeTransform) const |
161 { | 161 { |
162 DEFINE_STATIC_LOCAL(Path, tempPath, ()); | 162 DEFINE_STATIC_LOCAL(Path, tempPath, ()); |
163 | 163 |
164 tempPath = *path; | 164 tempPath = *path; |
165 tempPath.transform(strokeTransform); | 165 tempPath.transform(strokeTransform); |
166 | 166 |
167 return &tempPath; | 167 return &tempPath; |
168 } | 168 } |
169 | 169 |
170 AffineTransform RenderSVGShape::nonScalingStrokeTransform() const | 170 AffineTransform LayoutSVGShape::nonScalingStrokeTransform() const |
171 { | 171 { |
172 return toSVGGraphicsElement(element())->getScreenCTM(SVGGraphicsElement::Dis
allowStyleUpdate); | 172 return toSVGGraphicsElement(element())->getScreenCTM(SVGGraphicsElement::Dis
allowStyleUpdate); |
173 } | 173 } |
174 | 174 |
175 void RenderSVGShape::paint(const PaintInfo& paintInfo, const LayoutPoint&) | 175 void LayoutSVGShape::paint(const PaintInfo& paintInfo, const LayoutPoint&) |
176 { | 176 { |
177 SVGShapePainter(*this).paint(paintInfo); | 177 SVGShapePainter(*this).paint(paintInfo); |
178 } | 178 } |
179 | 179 |
180 // This method is called from inside paintOutline() since we call paintOutline() | 180 // This method is called from inside paintOutline() since we call paintOutline() |
181 // while transformed to our coord system, return local coords | 181 // while transformed to our coord system, return local coords |
182 void RenderSVGShape::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo
int&) const | 182 void LayoutSVGShape::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPo
int&) const |
183 { | 183 { |
184 LayoutRect rect = LayoutRect(paintInvalidationRectInLocalCoordinates()); | 184 LayoutRect rect = LayoutRect(paintInvalidationRectInLocalCoordinates()); |
185 if (!rect.isEmpty()) | 185 if (!rect.isEmpty()) |
186 rects.append(rect); | 186 rects.append(rect); |
187 } | 187 } |
188 | 188 |
189 bool RenderSVGShape::nodeAtFloatPoint(const HitTestRequest& request, HitTestResu
lt& result, const FloatPoint& pointInParent, HitTestAction hitTestAction) | 189 bool LayoutSVGShape::nodeAtFloatPoint(const HitTestRequest& request, HitTestResu
lt& result, const FloatPoint& pointInParent, HitTestAction hitTestAction) |
190 { | 190 { |
191 // We only draw in the foreground phase, so we only hit-test then. | 191 // We only draw in the foreground phase, so we only hit-test then. |
192 if (hitTestAction != HitTestForeground) | 192 if (hitTestAction != HitTestForeground) |
193 return false; | 193 return false; |
194 | 194 |
195 FloatPoint localPoint; | 195 FloatPoint localPoint; |
196 if (!SVGLayoutSupport::transformToUserSpaceAndCheckClipping(this, localToPar
entTransform(), pointInParent, localPoint)) | 196 if (!SVGLayoutSupport::transformToUserSpaceAndCheckClipping(this, localToPar
entTransform(), pointInParent, localPoint)) |
197 return false; | 197 return false; |
198 | 198 |
199 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_GEOMETRY_HITTESTIN
G, request, style()->pointerEvents()); | 199 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_GEOMETRY_HITTESTIN
G, request, style()->pointerEvents()); |
200 if (nodeAtFloatPointInternal(request, localPoint, hitRules)) { | 200 if (nodeAtFloatPointInternal(request, localPoint, hitRules)) { |
201 updateHitTestResult(result, roundedLayoutPoint(localPoint)); | 201 updateHitTestResult(result, roundedLayoutPoint(localPoint)); |
202 return true; | 202 return true; |
203 } | 203 } |
204 | 204 |
205 return false; | 205 return false; |
206 } | 206 } |
207 | 207 |
208 bool RenderSVGShape::nodeAtFloatPointInternal(const HitTestRequest& request, con
st FloatPoint& localPoint, PointerEventsHitRules hitRules) | 208 bool LayoutSVGShape::nodeAtFloatPointInternal(const HitTestRequest& request, con
st FloatPoint& localPoint, PointerEventsHitRules hitRules) |
209 { | 209 { |
210 bool isVisible = (style()->visibility() == VISIBLE); | 210 bool isVisible = (style()->visibility() == VISIBLE); |
211 if (isVisible || !hitRules.requireVisible) { | 211 if (isVisible || !hitRules.requireVisible) { |
212 const SVGLayoutStyle& svgStyle = style()->svgStyle(); | 212 const SVGLayoutStyle& svgStyle = style()->svgStyle(); |
213 WindRule fillRule = svgStyle.fillRule(); | 213 WindRule fillRule = svgStyle.fillRule(); |
214 if (request.svgClipContent()) | 214 if (request.svgClipContent()) |
215 fillRule = svgStyle.clipRule(); | 215 fillRule = svgStyle.clipRule(); |
216 if ((hitRules.canHitBoundingBox && objectBoundingBox().contains(localPoi
nt)) | 216 if ((hitRules.canHitBoundingBox && objectBoundingBox().contains(localPoi
nt)) |
217 || (hitRules.canHitStroke && (svgStyle.hasStroke() || !hitRules.requ
ireStroke) && strokeContains(localPoint, hitRules.requireStroke)) | 217 || (hitRules.canHitStroke && (svgStyle.hasStroke() || !hitRules.requ
ireStroke) && strokeContains(localPoint, hitRules.requireStroke)) |
218 || (hitRules.canHitFill && (svgStyle.hasFill() || !hitRules.requireF
ill) && fillContains(localPoint, hitRules.requireFill, fillRule))) | 218 || (hitRules.canHitFill && (svgStyle.hasFill() || !hitRules.requireF
ill) && fillContains(localPoint, hitRules.requireFill, fillRule))) |
219 return true; | 219 return true; |
220 } | 220 } |
221 return false; | 221 return false; |
222 } | 222 } |
223 | 223 |
224 FloatRect RenderSVGShape::calculateObjectBoundingBox() const | 224 FloatRect LayoutSVGShape::calculateObjectBoundingBox() const |
225 { | 225 { |
226 return path().boundingRect(); | 226 return path().boundingRect(); |
227 } | 227 } |
228 | 228 |
229 FloatRect RenderSVGShape::calculateStrokeBoundingBox() const | 229 FloatRect LayoutSVGShape::calculateStrokeBoundingBox() const |
230 { | 230 { |
231 ASSERT(m_path); | 231 ASSERT(m_path); |
232 FloatRect strokeBoundingBox = m_fillBoundingBox; | 232 FloatRect strokeBoundingBox = m_fillBoundingBox; |
233 | 233 |
234 if (style()->svgStyle().hasStroke()) { | 234 if (style()->svgStyle().hasStroke()) { |
235 StrokeData strokeData; | 235 StrokeData strokeData; |
236 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *
this); | 236 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *
this); |
237 if (hasNonScalingStroke()) { | 237 if (hasNonScalingStroke()) { |
238 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); | 238 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); |
239 if (nonScalingTransform.isInvertible()) { | 239 if (nonScalingTransform.isInvertible()) { |
240 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTra
nsform); | 240 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTra
nsform); |
241 FloatRect strokeBoundingRect = usePath->strokeBoundingRect(strok
eData); | 241 FloatRect strokeBoundingRect = usePath->strokeBoundingRect(strok
eData); |
242 strokeBoundingRect = nonScalingTransform.inverse().mapRect(strok
eBoundingRect); | 242 strokeBoundingRect = nonScalingTransform.inverse().mapRect(strok
eBoundingRect); |
243 strokeBoundingBox.unite(strokeBoundingRect); | 243 strokeBoundingBox.unite(strokeBoundingRect); |
244 } | 244 } |
245 } else { | 245 } else { |
246 strokeBoundingBox.unite(path().strokeBoundingRect(strokeData)); | 246 strokeBoundingBox.unite(path().strokeBoundingRect(strokeData)); |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 return strokeBoundingBox; | 250 return strokeBoundingBox; |
251 } | 251 } |
252 | 252 |
253 void RenderSVGShape::updatePaintInvalidationBoundingBox() | 253 void LayoutSVGShape::updatePaintInvalidationBoundingBox() |
254 { | 254 { |
255 m_paintInvalidationBoundingBox = strokeBoundingBox(); | 255 m_paintInvalidationBoundingBox = strokeBoundingBox(); |
256 if (strokeWidth() < 1.0f && !m_paintInvalidationBoundingBox.isEmpty()) | 256 if (strokeWidth() < 1.0f && !m_paintInvalidationBoundingBox.isEmpty()) |
257 m_paintInvalidationBoundingBox.inflate(1); | 257 m_paintInvalidationBoundingBox.inflate(1); |
258 SVGLayoutSupport::intersectPaintInvalidationRectWithResources(this, m_paintI
nvalidationBoundingBox); | 258 SVGLayoutSupport::intersectPaintInvalidationRectWithResources(this, m_paintI
nvalidationBoundingBox); |
259 } | 259 } |
260 | 260 |
261 float RenderSVGShape::strokeWidth() const | 261 float LayoutSVGShape::strokeWidth() const |
262 { | 262 { |
263 SVGLengthContext lengthContext(element()); | 263 SVGLengthContext lengthContext(element()); |
264 return style()->svgStyle().strokeWidth()->value(lengthContext); | 264 return style()->svgStyle().strokeWidth()->value(lengthContext); |
265 } | 265 } |
266 | 266 |
267 } | 267 } |
OLD | NEW |