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 19 matching lines...) Expand all Loading... |
30 #include "core/layout/HitTestResult.h" | 30 #include "core/layout/HitTestResult.h" |
31 #include "core/layout/LayoutAnalyzer.h" | 31 #include "core/layout/LayoutAnalyzer.h" |
32 #include "core/layout/PointerEventsHitRules.h" | 32 #include "core/layout/PointerEventsHitRules.h" |
33 #include "core/layout/svg/LayoutSVGResourcePaintServer.h" | 33 #include "core/layout/svg/LayoutSVGResourcePaintServer.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/SVGShapePainter.h" | 37 #include "core/paint/SVGShapePainter.h" |
38 #include "core/svg/SVGGeometryElement.h" | 38 #include "core/svg/SVGGeometryElement.h" |
39 #include "core/svg/SVGLengthContext.h" | 39 #include "core/svg/SVGLengthContext.h" |
| 40 #include "core/svg/SVGPathElement.h" |
40 #include "platform/geometry/FloatPoint.h" | 41 #include "platform/geometry/FloatPoint.h" |
41 #include "platform/graphics/StrokeData.h" | 42 #include "platform/graphics/StrokeData.h" |
42 #include "wtf/MathExtras.h" | 43 #include "wtf/MathExtras.h" |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 LayoutSVGShape::LayoutSVGShape(SVGGeometryElement* node) | 47 LayoutSVGShape::LayoutSVGShape(SVGGeometryElement* node) |
47 : LayoutSVGModelObject(node) | 48 : LayoutSVGModelObject(node) |
48 , 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. |
49 , 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. |
50 , 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. |
51 { | 52 { |
52 } | 53 } |
53 | 54 |
54 LayoutSVGShape::~LayoutSVGShape() | 55 LayoutSVGShape::~LayoutSVGShape() |
55 { | 56 { |
56 } | 57 } |
57 | 58 |
58 void LayoutSVGShape::createPath() | 59 void LayoutSVGShape::createPath() |
59 { | 60 { |
60 if (!m_path) | 61 if (!m_path) |
61 m_path = adoptPtr(new Path()); | 62 m_path = adoptPtr(new Path()); |
62 *m_path = toSVGGeometryElement(element())->asPath(); | 63 *m_path = toSVGGeometryElement(element())->asPath(); |
63 if (m_rareData.get()) | 64 if (m_rareData.get()) |
64 m_rareData->m_cachedNonScalingStrokePath.clear(); | 65 m_rareData->m_cachedNonScalingStrokePath.clear(); |
65 } | 66 } |
66 | 67 |
| 68 float LayoutSVGShape::dashScaleFactor() const |
| 69 { |
| 70 if (!isSVGPathElement(element())) |
| 71 return 1; |
| 72 SVGPathElement& pathElement = toSVGPathElement(*element()); |
| 73 if (!pathElement.pathLength()->isSpecified()) |
| 74 return 1; |
| 75 const SVGComputedStyle& svgStyle = styleRef().svgStyle(); |
| 76 float authorPathLength = pathElement.pathLength()->currentValue()->value(); |
| 77 if (authorPathLength < 0 || !svgStyle.strokeDashArray()->size()) |
| 78 return 1; |
| 79 if (!authorPathLength) |
| 80 return 0; |
| 81 // Since we know this is a <path> element, we also know the source of the |
| 82 // path - the 'd' presentation attribute. Since the StylePath already |
| 83 // caches the computed path length for use, use that here directly. |
| 84 float computedPathLength = svgStyle.d()->length(); |
| 85 if (!computedPathLength) |
| 86 return 1; |
| 87 return computedPathLength / authorPathLength; |
| 88 } |
| 89 |
67 void LayoutSVGShape::updateShapeFromElement() | 90 void LayoutSVGShape::updateShapeFromElement() |
68 { | 91 { |
69 createPath(); | 92 createPath(); |
70 | 93 |
71 m_fillBoundingBox = calculateObjectBoundingBox(); | 94 m_fillBoundingBox = calculateObjectBoundingBox(); |
72 m_strokeBoundingBox = calculateStrokeBoundingBox(); | 95 m_strokeBoundingBox = calculateStrokeBoundingBox(); |
73 } | 96 } |
74 | 97 |
75 FloatRect LayoutSVGShape::hitTestStrokeBoundingBox() const | 98 FloatRect LayoutSVGShape::hitTestStrokeBoundingBox() const |
76 { | 99 { |
77 if (style()->svgStyle().hasStroke()) | 100 if (style()->svgStyle().hasStroke()) |
78 return m_strokeBoundingBox; | 101 return m_strokeBoundingBox; |
79 | 102 |
80 // Implementation of http://dev.w3.org/fxtf/css-masking-1/#compute-stroke-bo
unding-box | 103 // Implementation of http://dev.w3.org/fxtf/css-masking-1/#compute-stroke-bo
unding-box |
81 // for the <rect> / <ellipse> / <circle> case except that we ignore whether | 104 // for the <rect> / <ellipse> / <circle> case except that we ignore whether |
82 // the stroke is none. | 105 // the stroke is none. |
83 | 106 |
84 FloatRect box = m_fillBoundingBox; | 107 FloatRect box = m_fillBoundingBox; |
85 const float strokeWidth = this->strokeWidth(); | 108 const float strokeWidth = this->strokeWidth(); |
86 box.inflate(strokeWidth / 2); | 109 box.inflate(strokeWidth / 2); |
87 return box; | 110 return box; |
88 } | 111 } |
89 | 112 |
90 bool LayoutSVGShape::shapeDependentStrokeContains(const FloatPoint& point) | 113 bool LayoutSVGShape::shapeDependentStrokeContains(const FloatPoint& point) |
91 { | 114 { |
92 ASSERT(m_path); | 115 ASSERT(m_path); |
93 StrokeData strokeData; | 116 StrokeData strokeData; |
94 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this
); | 117 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this
, dashScaleFactor()); |
95 | 118 |
96 if (hasNonScalingStroke()) { | 119 if (hasNonScalingStroke()) { |
97 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); | 120 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); |
98 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTransform); | 121 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTransform); |
99 | 122 |
100 return usePath->strokeContains(nonScalingTransform.mapPoint(point), stro
keData); | 123 return usePath->strokeContains(nonScalingTransform.mapPoint(point), stro
keData); |
101 } | 124 } |
102 | 125 |
103 return m_path->strokeContains(point, strokeData); | 126 return m_path->strokeContains(point, strokeData); |
104 } | 127 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 return path().boundingRect(); | 273 return path().boundingRect(); |
251 } | 274 } |
252 | 275 |
253 FloatRect LayoutSVGShape::calculateStrokeBoundingBox() const | 276 FloatRect LayoutSVGShape::calculateStrokeBoundingBox() const |
254 { | 277 { |
255 ASSERT(m_path); | 278 ASSERT(m_path); |
256 FloatRect strokeBoundingBox = m_fillBoundingBox; | 279 FloatRect strokeBoundingBox = m_fillBoundingBox; |
257 | 280 |
258 if (style()->svgStyle().hasStroke()) { | 281 if (style()->svgStyle().hasStroke()) { |
259 StrokeData strokeData; | 282 StrokeData strokeData; |
260 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *
this); | 283 SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *
this, dashScaleFactor()); |
261 if (hasNonScalingStroke()) { | 284 if (hasNonScalingStroke()) { |
262 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); | 285 AffineTransform nonScalingTransform = nonScalingStrokeTransform(); |
263 if (nonScalingTransform.isInvertible()) { | 286 if (nonScalingTransform.isInvertible()) { |
264 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTra
nsform); | 287 Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTra
nsform); |
265 FloatRect strokeBoundingRect = usePath->strokeBoundingRect(strok
eData); | 288 FloatRect strokeBoundingRect = usePath->strokeBoundingRect(strok
eData); |
266 strokeBoundingRect = nonScalingTransform.inverse().mapRect(strok
eBoundingRect); | 289 strokeBoundingRect = nonScalingTransform.inverse().mapRect(strok
eBoundingRect); |
267 strokeBoundingBox.unite(strokeBoundingRect); | 290 strokeBoundingBox.unite(strokeBoundingRect); |
268 } | 291 } |
269 } else { | 292 } else { |
270 strokeBoundingBox.unite(path().strokeBoundingRect(strokeData)); | 293 strokeBoundingBox.unite(path().strokeBoundingRect(strokeData)); |
(...skipping 25 matching lines...) Expand all Loading... |
296 } | 319 } |
297 | 320 |
298 LayoutSVGShapeRareData& LayoutSVGShape::ensureRareData() const | 321 LayoutSVGShapeRareData& LayoutSVGShape::ensureRareData() const |
299 { | 322 { |
300 if (!m_rareData) | 323 if (!m_rareData) |
301 m_rareData = adoptPtr(new LayoutSVGShapeRareData()); | 324 m_rareData = adoptPtr(new LayoutSVGShapeRareData()); |
302 return *m_rareData.get(); | 325 return *m_rareData.get(); |
303 } | 326 } |
304 | 327 |
305 } // namespace blink | 328 } // namespace blink |
OLD | NEW |