OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 | 22 |
23 #include "core/svg/SVGStyledTransformableElement.h" | 23 #include "core/svg/SVGGraphicsElement.h" |
24 | 24 |
25 #include "SVGNames.h" | 25 #include "SVGNames.h" |
26 #include "core/platform/graphics/transforms/AffineTransform.h" | 26 #include "core/platform/graphics/transforms/AffineTransform.h" |
27 #include "core/rendering/svg/RenderSVGPath.h" | 27 #include "core/rendering/svg/RenderSVGPath.h" |
28 #include "core/rendering/svg/RenderSVGResource.h" | 28 #include "core/rendering/svg/RenderSVGResource.h" |
29 #include "core/rendering/svg/SVGPathData.h" | 29 #include "core/rendering/svg/SVGPathData.h" |
30 #include "core/svg/SVGElementInstance.h" | 30 #include "core/svg/SVGElementInstance.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 // Animated property definitions | 34 // Animated property definitions |
35 DEFINE_ANIMATED_TRANSFORM_LIST(SVGStyledTransformableElement, SVGNames::transfor
mAttr, Transform, transform) | 35 DEFINE_ANIMATED_TRANSFORM_LIST(SVGGraphicsElement, SVGNames::transformAttr, Tran
sform, transform) |
36 | 36 |
37 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGStyledTransformableElement) | 37 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGraphicsElement) |
38 REGISTER_LOCAL_ANIMATED_PROPERTY(transform) | 38 REGISTER_LOCAL_ANIMATED_PROPERTY(transform) |
39 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledLocatableElement) | 39 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledElement) |
| 40 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests) |
40 END_REGISTER_ANIMATED_PROPERTIES | 41 END_REGISTER_ANIMATED_PROPERTIES |
41 | 42 |
42 SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName
& tagName, Document* document, ConstructionType constructionType) | 43 SVGGraphicsElement::SVGGraphicsElement(const QualifiedName& tagName, Document* d
ocument, ConstructionType constructionType) |
43 : SVGStyledLocatableElement(tagName, document, constructionType) | 44 : SVGStyledLocatableElement(tagName, document, constructionType) |
44 { | 45 { |
45 registerAnimatedPropertiesForSVGStyledTransformableElement(); | 46 registerAnimatedPropertiesForSVGGraphicsElement(); |
46 } | 47 } |
47 | 48 |
48 SVGStyledTransformableElement::~SVGStyledTransformableElement() | 49 SVGGraphicsElement::~SVGGraphicsElement() |
49 { | 50 { |
50 } | 51 } |
51 | 52 |
52 AffineTransform SVGStyledTransformableElement::getCTM(StyleUpdateStrategy styleU
pdateStrategy) | 53 AffineTransform SVGGraphicsElement::getCTM(StyleUpdateStrategy styleUpdateStrate
gy) |
53 { | 54 { |
54 return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, st
yleUpdateStrategy); | 55 return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, st
yleUpdateStrategy); |
55 } | 56 } |
56 | 57 |
57 AffineTransform SVGStyledTransformableElement::getScreenCTM(StyleUpdateStrategy
styleUpdateStrategy) | 58 AffineTransform SVGGraphicsElement::getScreenCTM(StyleUpdateStrategy styleUpdate
Strategy) |
58 { | 59 { |
59 return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdate
Strategy); | 60 return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdate
Strategy); |
60 } | 61 } |
61 | 62 |
62 AffineTransform SVGStyledTransformableElement::animatedLocalTransform() const | 63 AffineTransform SVGGraphicsElement::animatedLocalTransform() const |
63 { | 64 { |
64 AffineTransform matrix; | 65 AffineTransform matrix; |
65 RenderStyle* style = renderer() ? renderer()->style() : 0; | 66 RenderStyle* style = renderer() ? renderer()->style() : 0; |
66 | 67 |
67 // If CSS property was set, use that, otherwise fallback to attribute (if se
t). | 68 // If CSS property was set, use that, otherwise fallback to attribute (if se
t). |
68 if (style && style->hasTransform()) { | 69 if (style && style->hasTransform()) { |
69 // Note: objectBoundingBox is an emptyRect for elements like pattern or
clipPath. | 70 // Note: objectBoundingBox is an emptyRect for elements like pattern or
clipPath. |
70 // See the "Object bounding box units" section of http://dev.w3.org/cssw
g/css3-transforms/ | 71 // See the "Object bounding box units" section of http://dev.w3.org/cssw
g/css3-transforms/ |
71 TransformationMatrix transform; | 72 TransformationMatrix transform; |
72 style->applyTransform(transform, renderer()->objectBoundingBox()); | 73 style->applyTransform(transform, renderer()->objectBoundingBox()); |
73 | 74 |
74 // Flatten any 3D transform. | 75 // Flatten any 3D transform. |
75 matrix = transform.toAffineTransform(); | 76 matrix = transform.toAffineTransform(); |
76 } else | 77 } else { |
77 transform().concatenate(matrix); | 78 transform().concatenate(matrix); |
| 79 } |
78 | 80 |
79 if (m_supplementalTransform) | 81 if (m_supplementalTransform) |
80 return *m_supplementalTransform * matrix; | 82 return *m_supplementalTransform * matrix; |
81 return matrix; | 83 return matrix; |
82 } | 84 } |
83 | 85 |
84 AffineTransform* SVGStyledTransformableElement::supplementalTransform() | 86 AffineTransform* SVGGraphicsElement::supplementalTransform() |
85 { | 87 { |
86 if (!m_supplementalTransform) | 88 if (!m_supplementalTransform) |
87 m_supplementalTransform = adoptPtr(new AffineTransform); | 89 m_supplementalTransform = adoptPtr(new AffineTransform); |
88 return m_supplementalTransform.get(); | 90 return m_supplementalTransform.get(); |
89 } | 91 } |
90 | 92 |
91 bool SVGStyledTransformableElement::isSupportedAttribute(const QualifiedName& at
trName) | 93 bool SVGGraphicsElement::isSupportedAttribute(const QualifiedName& attrName) |
92 { | 94 { |
93 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); | 95 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); |
94 if (supportedAttributes.isEmpty()) | 96 if (supportedAttributes.isEmpty()) |
95 supportedAttributes.add(SVGNames::transformAttr); | 97 supportedAttributes.add(SVGNames::transformAttr); |
96 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); | 98 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); |
97 } | 99 } |
98 | 100 |
99 void SVGStyledTransformableElement::parseAttribute(const QualifiedName& name, co
nst AtomicString& value) | 101 void SVGGraphicsElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) |
100 { | 102 { |
101 if (!isSupportedAttribute(name)) { | 103 if (!isSupportedAttribute(name)) { |
102 SVGStyledLocatableElement::parseAttribute(name, value); | 104 SVGStyledLocatableElement::parseAttribute(name, value); |
103 return; | 105 return; |
104 } | 106 } |
105 | 107 |
106 if (name == SVGNames::transformAttr) { | 108 if (name == SVGNames::transformAttr) { |
107 SVGTransformList newList; | 109 SVGTransformList newList; |
108 newList.parse(value); | 110 newList.parse(value); |
109 detachAnimatedTransformListWrappers(newList.size()); | 111 detachAnimatedTransformListWrappers(newList.size()); |
110 setTransformBaseValue(newList); | 112 setTransformBaseValue(newList); |
111 return; | 113 return; |
112 } | 114 } |
113 | 115 |
114 ASSERT_NOT_REACHED(); | 116 ASSERT_NOT_REACHED(); |
115 } | 117 } |
116 | 118 |
117 void SVGStyledTransformableElement::svgAttributeChanged(const QualifiedName& att
rName) | 119 void SVGGraphicsElement::svgAttributeChanged(const QualifiedName& attrName) |
118 { | 120 { |
119 if (!isSupportedAttribute(attrName)) { | 121 if (!isSupportedAttribute(attrName)) { |
120 SVGStyledLocatableElement::svgAttributeChanged(attrName); | 122 SVGStyledLocatableElement::svgAttributeChanged(attrName); |
121 return; | 123 return; |
122 } | 124 } |
123 | 125 |
124 SVGElementInstance::InvalidationGuard invalidationGuard(this); | 126 SVGElementInstance::InvalidationGuard invalidationGuard(this); |
125 | 127 |
126 RenderObject* object = renderer(); | 128 RenderObject* object = renderer(); |
127 if (!object) | 129 if (!object) |
128 return; | 130 return; |
129 | 131 |
130 if (attrName == SVGNames::transformAttr) { | 132 if (attrName == SVGNames::transformAttr) { |
131 object->setNeedsTransformUpdate(); | 133 object->setNeedsTransformUpdate(); |
132 RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); | 134 RenderSVGResource::markForLayoutAndParentResourceInvalidation(object); |
133 return; | 135 return; |
134 } | 136 } |
135 | 137 |
136 ASSERT_NOT_REACHED(); | 138 ASSERT_NOT_REACHED(); |
137 } | 139 } |
138 | 140 |
139 SVGElement* SVGStyledTransformableElement::nearestViewportElement() const | 141 SVGElement* SVGGraphicsElement::nearestViewportElement() const |
140 { | 142 { |
141 return SVGTransformable::nearestViewportElement(this); | 143 return SVGTransformable::nearestViewportElement(this); |
142 } | 144 } |
143 | 145 |
144 SVGElement* SVGStyledTransformableElement::farthestViewportElement() const | 146 SVGElement* SVGGraphicsElement::farthestViewportElement() const |
145 { | 147 { |
146 return SVGTransformable::farthestViewportElement(this); | 148 return SVGTransformable::farthestViewportElement(this); |
147 } | 149 } |
148 | 150 |
149 FloatRect SVGStyledTransformableElement::getBBox(StyleUpdateStrategy styleUpdate
Strategy) | 151 FloatRect SVGGraphicsElement::getBBox(StyleUpdateStrategy styleUpdateStrategy) |
150 { | 152 { |
151 return SVGTransformable::getBBox(this, styleUpdateStrategy); | 153 return SVGTransformable::getBBox(this, styleUpdateStrategy); |
152 } | 154 } |
153 | 155 |
154 RenderObject* SVGStyledTransformableElement::createRenderer(RenderStyle*) | 156 RenderObject* SVGGraphicsElement::createRenderer(RenderStyle*) |
155 { | 157 { |
156 // By default, any subclass is expected to do path-based drawing | 158 // By default, any subclass is expected to do path-based drawing |
157 return new (document()->renderArena()) RenderSVGPath(this); | 159 return new (document()->renderArena()) RenderSVGPath(this); |
158 } | 160 } |
159 | 161 |
160 void SVGStyledTransformableElement::toClipPath(Path& path) | 162 void SVGGraphicsElement::toClipPath(Path& path) |
161 { | 163 { |
162 updatePathFromGraphicsElement(this, path); | 164 updatePathFromGraphicsElement(this, path); |
163 // FIXME: How do we know the element has done a layout? | 165 // FIXME: How do we know the element has done a layout? |
164 path.transform(animatedLocalTransform()); | 166 path.transform(animatedLocalTransform()); |
165 } | 167 } |
166 | 168 |
167 } | 169 } |
OLD | NEW |