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