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 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 , m_needsBoundariesUpdate(false) // Default is false, the cached rects are e
mpty from the beginning. | 49 , m_needsBoundariesUpdate(false) // Default is false, the cached rects are e
mpty from the beginning. |
50 , m_needsShapeUpdate(true) // Default is true, so we grab a Path object once
from SVGGeometryElement. | 50 , m_needsShapeUpdate(true) // Default is true, so we grab a Path object once
from SVGGeometryElement. |
51 , m_needsTransformUpdate(true) // Default is true, so we grab a AffineTransf
orm object once from SVGGeometryElement. | 51 , m_needsTransformUpdate(true) // Default is true, so we grab a AffineTransf
orm object once from SVGGeometryElement. |
52 { | 52 { |
53 } | 53 } |
54 | 54 |
55 LayoutSVGShape::~LayoutSVGShape() | 55 LayoutSVGShape::~LayoutSVGShape() |
56 { | 56 { |
57 } | 57 } |
58 | 58 |
59 void LayoutSVGShape::createPath() | 59 void LayoutSVGShape::updateShapeFromElement() |
60 { | 60 { |
61 if (!m_path) | 61 if (!m_path) |
62 m_path = adoptPtr(new Path()); | 62 m_path = adoptPtr(new Path()); |
63 *m_path = toSVGGeometryElement(element())->asPath(); | 63 *m_path = toSVGGeometryElement(element())->asPath(); |
64 } | 64 } |
65 | 65 |
66 void LayoutSVGShape::updateShapeFromElement() | 66 void LayoutSVGShape::updateStrokeAndFillBoundingBoxes() |
67 { | 67 { |
68 createPath(); | 68 m_fillBoundingBox = path().boundingRect(); |
69 | 69 |
70 m_fillBoundingBox = calculateObjectBoundingBox(); | 70 m_strokeBoundingBox = m_fillBoundingBox; |
71 m_strokeBoundingBox = calculateStrokeBoundingBox(); | 71 if (style()->svgStyle().hasStroke()) { |
| 72 StrokeData strokeData; |
| 73 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *
this); |
| 74 if (hasNonScalingStroke()) { |
| 75 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); |
| 76 if (nonScalingTransform.isInvertible()) { |
| 77 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTra
nsform); |
| 78 FloatRect strokeBoundingRect = usePath->strokeBoundingRect(strok
eData); |
| 79 strokeBoundingRect = nonScalingTransform.inverse().mapRect(strok
eBoundingRect); |
| 80 m_strokeBoundingBox.unite(strokeBoundingRect); |
| 81 } |
| 82 } else { |
| 83 m_strokeBoundingBox.unite(path().strokeBoundingRect(strokeData)); |
| 84 } |
| 85 } |
72 } | 86 } |
73 | 87 |
74 FloatRect LayoutSVGShape::hitTestStrokeBoundingBox() const | 88 FloatRect LayoutSVGShape::hitTestStrokeBoundingBox() const |
75 { | 89 { |
76 if (style()->svgStyle().hasStroke()) | 90 if (style()->svgStyle().hasStroke()) |
77 return m_strokeBoundingBox; | 91 return m_strokeBoundingBox; |
78 | 92 |
79 // Implementation of http://dev.w3.org/fxtf/css-masking-1/#compute-stroke-bo
unding-box | 93 // Implementation of http://dev.w3.org/fxtf/css-masking-1/#compute-stroke-bo
unding-box |
80 // for the <rect> / <ellipse> / <circle> case except that we ignore whether | 94 // for the <rect> / <ellipse> / <circle> case except that we ignore whether |
81 // the stroke is none. | 95 // the stroke is none. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } else { | 159 } else { |
146 m_localTransform = 0; | 160 m_localTransform = 0; |
147 } | 161 } |
148 } | 162 } |
149 | 163 |
150 void LayoutSVGShape::layout() | 164 void LayoutSVGShape::layout() |
151 { | 165 { |
152 bool updateCachedBoundariesInParents = false; | 166 bool updateCachedBoundariesInParents = false; |
153 LayoutAnalyzer::Scope analyzer(*this); | 167 LayoutAnalyzer::Scope analyzer(*this); |
154 | 168 |
155 if (m_needsShapeUpdate || m_needsBoundariesUpdate) { | 169 if (m_needsShapeUpdate) |
156 updateShapeFromElement(); | 170 updateShapeFromElement(); |
157 m_needsShapeUpdate = false; | 171 |
| 172 if (m_needsBoundariesUpdate || m_needsShapeUpdate) { |
| 173 updateStrokeAndFillBoundingBoxes(); |
158 updatePaintInvalidationBoundingBox(); | 174 updatePaintInvalidationBoundingBox(); |
159 m_needsBoundariesUpdate = false; | 175 m_needsBoundariesUpdate = false; |
| 176 m_needsShapeUpdate = false; |
160 updateCachedBoundariesInParents = true; | 177 updateCachedBoundariesInParents = true; |
161 } | 178 } |
162 | 179 |
163 if (m_needsTransformUpdate) { | 180 if (m_needsTransformUpdate) { |
164 updateLocalTransform(); | 181 updateLocalTransform(); |
165 m_needsTransformUpdate = false; | 182 m_needsTransformUpdate = false; |
166 updateCachedBoundariesInParents = true; | 183 updateCachedBoundariesInParents = true; |
167 } | 184 } |
168 | 185 |
169 // Invalidate all resources of this client if our layout changed. | 186 // Invalidate all resources of this client if our layout changed. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (request.svgClipContent()) | 251 if (request.svgClipContent()) |
235 fillRule = svgStyle.clipRule(); | 252 fillRule = svgStyle.clipRule(); |
236 if ((hitRules.canHitBoundingBox && objectBoundingBox().contains(localPoi
nt)) | 253 if ((hitRules.canHitBoundingBox && objectBoundingBox().contains(localPoi
nt)) |
237 || (hitRules.canHitStroke && (svgStyle.hasStroke() || !hitRules.requ
ireStroke) && strokeContains(localPoint, hitRules.requireStroke)) | 254 || (hitRules.canHitStroke && (svgStyle.hasStroke() || !hitRules.requ
ireStroke) && strokeContains(localPoint, hitRules.requireStroke)) |
238 || (hitRules.canHitFill && (svgStyle.hasFill() || !hitRules.requireF
ill) && fillContains(localPoint, hitRules.requireFill, fillRule))) | 255 || (hitRules.canHitFill && (svgStyle.hasFill() || !hitRules.requireF
ill) && fillContains(localPoint, hitRules.requireFill, fillRule))) |
239 return true; | 256 return true; |
240 } | 257 } |
241 return false; | 258 return false; |
242 } | 259 } |
243 | 260 |
244 FloatRect LayoutSVGShape::calculateObjectBoundingBox() const | |
245 { | |
246 return path().boundingRect(); | |
247 } | |
248 | |
249 FloatRect LayoutSVGShape::calculateStrokeBoundingBox() const | |
250 { | |
251 ASSERT(m_path); | |
252 FloatRect strokeBoundingBox = m_fillBoundingBox; | |
253 | |
254 if (style()->svgStyle().hasStroke()) { | |
255 StrokeData strokeData; | |
256 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *
this); | |
257 if (hasNonScalingStroke()) { | |
258 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); | |
259 if (nonScalingTransform.isInvertible()) { | |
260 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTra
nsform); | |
261 FloatRect strokeBoundingRect = usePath->strokeBoundingRect(strok
eData); | |
262 strokeBoundingRect = nonScalingTransform.inverse().mapRect(strok
eBoundingRect); | |
263 strokeBoundingBox.unite(strokeBoundingRect); | |
264 } | |
265 } else { | |
266 strokeBoundingBox.unite(path().strokeBoundingRect(strokeData)); | |
267 } | |
268 } | |
269 | |
270 return strokeBoundingBox; | |
271 } | |
272 | |
273 void LayoutSVGShape::updatePaintInvalidationBoundingBox() | 261 void LayoutSVGShape::updatePaintInvalidationBoundingBox() |
274 { | 262 { |
275 m_paintInvalidationBoundingBox = strokeBoundingBox(); | 263 m_paintInvalidationBoundingBox = strokeBoundingBox(); |
276 if (strokeWidth() < 1.0f && !m_paintInvalidationBoundingBox.isEmpty()) | 264 if (strokeWidth() < 1.0f && !m_paintInvalidationBoundingBox.isEmpty()) |
277 m_paintInvalidationBoundingBox.inflate(1); | 265 m_paintInvalidationBoundingBox.inflate(1); |
278 SVGLayoutSupport::intersectPaintInvalidationRectWithResources(this, m_paintI
nvalidationBoundingBox); | 266 SVGLayoutSupport::intersectPaintInvalidationRectWithResources(this, m_paintI
nvalidationBoundingBox); |
279 } | 267 } |
280 | 268 |
281 float LayoutSVGShape::strokeWidth() const | 269 float LayoutSVGShape::strokeWidth() const |
282 { | 270 { |
283 SVGLengthContext lengthContext(element()); | 271 SVGLengthContext lengthContext(element()); |
284 return lengthContext.valueForLength(style()->svgStyle().strokeWidth()); | 272 return lengthContext.valueForLength(style()->svgStyle().strokeWidth()); |
285 } | 273 } |
286 | 274 |
287 } | 275 } |
OLD | NEW |