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 | 29 |
30 #include "core/rendering/svg/RenderSVGPath.h" | 30 #include "core/layout/svg/LayoutSVGPath.h" |
31 | 31 |
32 #include "core/layout/svg/LayoutSVGResourceMarker.h" | 32 #include "core/layout/svg/LayoutSVGResourceMarker.h" |
33 #include "core/layout/svg/SVGResources.h" | 33 #include "core/layout/svg/SVGResources.h" |
34 #include "core/layout/svg/SVGResourcesCache.h" | 34 #include "core/layout/svg/SVGResourcesCache.h" |
35 #include "core/layout/svg/SVGSubpathData.h" | 35 #include "core/layout/svg/SVGSubpathData.h" |
36 #include "core/svg/SVGGraphicsElement.h" | 36 #include "core/svg/SVGGraphicsElement.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 RenderSVGPath::RenderSVGPath(SVGGraphicsElement* node) | 40 LayoutSVGPath::LayoutSVGPath(SVGGraphicsElement* node) |
41 : RenderSVGShape(node) | 41 : LayoutSVGShape(node) |
42 { | 42 { |
43 } | 43 } |
44 | 44 |
45 RenderSVGPath::~RenderSVGPath() | 45 LayoutSVGPath::~LayoutSVGPath() |
46 { | 46 { |
47 } | 47 } |
48 | 48 |
49 void RenderSVGPath::updateShapeFromElement() | 49 void LayoutSVGPath::updateShapeFromElement() |
50 { | 50 { |
51 RenderSVGShape::updateShapeFromElement(); | 51 LayoutSVGShape::updateShapeFromElement(); |
52 updateZeroLengthSubpaths(); | 52 updateZeroLengthSubpaths(); |
53 | 53 |
54 m_strokeBoundingBox = calculateUpdatedStrokeBoundingBox(); | 54 m_strokeBoundingBox = calculateUpdatedStrokeBoundingBox(); |
55 } | 55 } |
56 | 56 |
57 FloatRect RenderSVGPath::calculateUpdatedStrokeBoundingBox() const | 57 FloatRect LayoutSVGPath::calculateUpdatedStrokeBoundingBox() const |
58 { | 58 { |
59 FloatRect strokeBoundingBox = m_strokeBoundingBox; | 59 FloatRect strokeBoundingBox = m_strokeBoundingBox; |
60 | 60 |
61 if (!m_markerPositions.isEmpty()) | 61 if (!m_markerPositions.isEmpty()) |
62 strokeBoundingBox.unite(markerRect(strokeWidth())); | 62 strokeBoundingBox.unite(markerRect(strokeWidth())); |
63 | 63 |
64 if (style()->svgStyle().hasStroke()) { | 64 if (style()->svgStyle().hasStroke()) { |
65 // FIXME: zero-length subpaths do not respect vector-effect = non-scalin
g-stroke. | 65 // FIXME: zero-length subpaths do not respect vector-effect = non-scalin
g-stroke. |
66 float strokeWidth = this->strokeWidth(); | 66 float strokeWidth = this->strokeWidth(); |
67 for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) | 67 for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) |
68 strokeBoundingBox.unite(zeroLengthSubpathRect(m_zeroLengthLinecapLoc
ations[i], strokeWidth)); | 68 strokeBoundingBox.unite(zeroLengthSubpathRect(m_zeroLengthLinecapLoc
ations[i], strokeWidth)); |
69 } | 69 } |
70 | 70 |
71 return strokeBoundingBox; | 71 return strokeBoundingBox; |
72 } | 72 } |
73 | 73 |
74 bool RenderSVGPath::shapeDependentStrokeContains(const FloatPoint& point) | 74 bool LayoutSVGPath::shapeDependentStrokeContains(const FloatPoint& point) |
75 { | 75 { |
76 if (RenderSVGShape::shapeDependentStrokeContains(point)) | 76 if (LayoutSVGShape::shapeDependentStrokeContains(point)) |
77 return true; | 77 return true; |
78 | 78 |
79 const SVGLayoutStyle& svgStyle = style()->svgStyle(); | 79 const SVGLayoutStyle& svgStyle = style()->svgStyle(); |
80 for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) { | 80 for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) { |
81 ASSERT(svgStyle.hasStroke()); | 81 ASSERT(svgStyle.hasStroke()); |
82 float strokeWidth = this->strokeWidth(); | 82 float strokeWidth = this->strokeWidth(); |
83 if (svgStyle.capStyle() == SquareCap) { | 83 if (svgStyle.capStyle() == SquareCap) { |
84 if (zeroLengthSubpathRect(m_zeroLengthLinecapLocations[i], strokeWid
th).contains(point)) | 84 if (zeroLengthSubpathRect(m_zeroLengthLinecapLocations[i], strokeWid
th).contains(point)) |
85 return true; | 85 return true; |
86 } else { | 86 } else { |
87 ASSERT(svgStyle.capStyle() == RoundCap); | 87 ASSERT(svgStyle.capStyle() == RoundCap); |
88 FloatPoint radiusVector(point.x() - m_zeroLengthLinecapLocations[i].
x(), point.y() - m_zeroLengthLinecapLocations[i].y()); | 88 FloatPoint radiusVector(point.x() - m_zeroLengthLinecapLocations[i].
x(), point.y() - m_zeroLengthLinecapLocations[i].y()); |
89 if (radiusVector.lengthSquared() < strokeWidth * strokeWidth * .25f) | 89 if (radiusVector.lengthSquared() < strokeWidth * strokeWidth * .25f) |
90 return true; | 90 return true; |
91 } | 91 } |
92 } | 92 } |
93 return false; | 93 return false; |
94 } | 94 } |
95 | 95 |
96 bool RenderSVGPath::shouldStrokeZeroLengthSubpath() const | 96 bool LayoutSVGPath::shouldStrokeZeroLengthSubpath() const |
97 { | 97 { |
98 // Spec(11.4): Any zero length subpath shall not be stroked if the "stroke-l
inecap" property has a value of butt | 98 // Spec(11.4): Any zero length subpath shall not be stroked if the "stroke-l
inecap" property has a value of butt |
99 // but shall be stroked if the "stroke-linecap" property has a value of roun
d or square | 99 // but shall be stroked if the "stroke-linecap" property has a value of roun
d or square |
100 return style()->svgStyle().hasStroke() && style()->svgStyle().capStyle() !=
ButtCap; | 100 return style()->svgStyle().hasStroke() && style()->svgStyle().capStyle() !=
ButtCap; |
101 } | 101 } |
102 | 102 |
103 FloatRect RenderSVGPath::zeroLengthSubpathRect(const FloatPoint& linecapPosition
, float strokeWidth) | 103 FloatRect LayoutSVGPath::zeroLengthSubpathRect(const FloatPoint& linecapPosition
, float strokeWidth) |
104 { | 104 { |
105 return FloatRect(linecapPosition.x() - strokeWidth / 2, linecapPosition.y()
- strokeWidth / 2, strokeWidth, strokeWidth); | 105 return FloatRect(linecapPosition.x() - strokeWidth / 2, linecapPosition.y()
- strokeWidth / 2, strokeWidth, strokeWidth); |
106 } | 106 } |
107 | 107 |
108 void RenderSVGPath::updateZeroLengthSubpaths() | 108 void LayoutSVGPath::updateZeroLengthSubpaths() |
109 { | 109 { |
110 m_zeroLengthLinecapLocations.clear(); | 110 m_zeroLengthLinecapLocations.clear(); |
111 | 111 |
112 if (!strokeWidth() || !shouldStrokeZeroLengthSubpath()) | 112 if (!strokeWidth() || !shouldStrokeZeroLengthSubpath()) |
113 return; | 113 return; |
114 | 114 |
115 SVGSubpathData subpathData(m_zeroLengthLinecapLocations); | 115 SVGSubpathData subpathData(m_zeroLengthLinecapLocations); |
116 path().apply(&subpathData, SVGSubpathData::updateFromPathElement); | 116 path().apply(&subpathData, SVGSubpathData::updateFromPathElement); |
117 subpathData.pathIsDone(); | 117 subpathData.pathIsDone(); |
118 } | 118 } |
119 | 119 |
120 FloatRect RenderSVGPath::markerRect(float strokeWidth) const | 120 FloatRect LayoutSVGPath::markerRect(float strokeWidth) const |
121 { | 121 { |
122 ASSERT(!m_markerPositions.isEmpty()); | 122 ASSERT(!m_markerPositions.isEmpty()); |
123 | 123 |
124 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
this); | 124 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
this); |
125 ASSERT(resources); | 125 ASSERT(resources); |
126 | 126 |
127 LayoutSVGResourceMarker* markerStart = resources->markerStart(); | 127 LayoutSVGResourceMarker* markerStart = resources->markerStart(); |
128 LayoutSVGResourceMarker* markerMid = resources->markerMid(); | 128 LayoutSVGResourceMarker* markerMid = resources->markerMid(); |
129 LayoutSVGResourceMarker* markerEnd = resources->markerEnd(); | 129 LayoutSVGResourceMarker* markerEnd = resources->markerEnd(); |
130 ASSERT(markerStart || markerMid || markerEnd); | 130 ASSERT(markerStart || markerMid || markerEnd); |
131 | 131 |
132 FloatRect boundaries; | 132 FloatRect boundaries; |
133 unsigned size = m_markerPositions.size(); | 133 unsigned size = m_markerPositions.size(); |
134 for (unsigned i = 0; i < size; ++i) { | 134 for (unsigned i = 0; i < size; ++i) { |
135 if (LayoutSVGResourceMarker* marker = SVGMarkerData::markerForType(m_mar
kerPositions[i].type, markerStart, markerMid, markerEnd)) | 135 if (LayoutSVGResourceMarker* marker = SVGMarkerData::markerForType(m_mar
kerPositions[i].type, markerStart, markerMid, markerEnd)) |
136 boundaries.unite(marker->markerBoundaries(marker->markerTransformati
on(m_markerPositions[i].origin, m_markerPositions[i].angle, strokeWidth))); | 136 boundaries.unite(marker->markerBoundaries(marker->markerTransformati
on(m_markerPositions[i].origin, m_markerPositions[i].angle, strokeWidth))); |
137 } | 137 } |
138 return boundaries; | 138 return boundaries; |
139 } | 139 } |
140 | 140 |
141 bool RenderSVGPath::shouldGenerateMarkerPositions() const | 141 bool LayoutSVGPath::shouldGenerateMarkerPositions() const |
142 { | 142 { |
143 if (!style()->svgStyle().hasMarkers()) | 143 if (!style()->svgStyle().hasMarkers()) |
144 return false; | 144 return false; |
145 | 145 |
146 if (!SVGResources::supportsMarkers(*toSVGGraphicsElement(element()))) | 146 if (!SVGResources::supportsMarkers(*toSVGGraphicsElement(element()))) |
147 return false; | 147 return false; |
148 | 148 |
149 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
this); | 149 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
this); |
150 if (!resources) | 150 if (!resources) |
151 return false; | 151 return false; |
152 | 152 |
153 return resources->markerStart() || resources->markerMid() || resources->mark
erEnd(); | 153 return resources->markerStart() || resources->markerMid() || resources->mark
erEnd(); |
154 } | 154 } |
155 | 155 |
156 void RenderSVGPath::processMarkerPositions() | 156 void LayoutSVGPath::processMarkerPositions() |
157 { | 157 { |
158 m_markerPositions.clear(); | 158 m_markerPositions.clear(); |
159 | 159 |
160 if (!shouldGenerateMarkerPositions()) | 160 if (!shouldGenerateMarkerPositions()) |
161 return; | 161 return; |
162 | 162 |
163 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
this); | 163 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
this); |
164 ASSERT(resources); | 164 ASSERT(resources); |
165 | 165 |
166 LayoutSVGResourceMarker* markerStart = resources->markerStart(); | 166 LayoutSVGResourceMarker* markerStart = resources->markerStart(); |
167 | 167 |
168 SVGMarkerData markerData(m_markerPositions, markerStart ? markerStart->orien
tType() == SVGMarkerOrientAutoStartReverse : false); | 168 SVGMarkerData markerData(m_markerPositions, markerStart ? markerStart->orien
tType() == SVGMarkerOrientAutoStartReverse : false); |
169 path().apply(&markerData, SVGMarkerData::updateFromPathElement); | 169 path().apply(&markerData, SVGMarkerData::updateFromPathElement); |
170 markerData.pathIsDone(); | 170 markerData.pathIsDone(); |
171 } | 171 } |
172 | 172 |
173 } | 173 } |
OLD | NEW |