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, |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "SVGNames.h" | 25 #include "SVGNames.h" |
26 #include "core/rendering/svg/RenderSVGPath.h" | 26 #include "core/rendering/svg/RenderSVGPath.h" |
27 #include "core/rendering/svg/RenderSVGResource.h" | 27 #include "core/rendering/svg/RenderSVGResource.h" |
28 #include "core/rendering/svg/SVGPathData.h" | 28 #include "core/rendering/svg/SVGPathData.h" |
29 #include "core/svg/SVGElementInstance.h" | 29 #include "core/svg/SVGElementInstance.h" |
30 #include "platform/transforms/AffineTransform.h" | 30 #include "platform/transforms/AffineTransform.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 // Animated property definitions | 34 // Animated property definitions |
35 DEFINE_ANIMATED_TRANSFORM_LIST(SVGGraphicsElement, SVGNames::transformAttr, Tran
sform, transform) | |
36 | 35 |
37 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGraphicsElement) | 36 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGraphicsElement) |
38 REGISTER_LOCAL_ANIMATED_PROPERTY(transform) | |
39 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement) | 37 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement) |
40 END_REGISTER_ANIMATED_PROPERTIES | 38 END_REGISTER_ANIMATED_PROPERTIES |
41 | 39 |
42 SVGGraphicsElement::SVGGraphicsElement(const QualifiedName& tagName, Document& d
ocument, ConstructionType constructionType) | 40 SVGGraphicsElement::SVGGraphicsElement(const QualifiedName& tagName, Document& d
ocument, ConstructionType constructionType) |
43 : SVGElement(tagName, document, constructionType) | 41 : SVGElement(tagName, document, constructionType) |
44 , SVGTests(this) | 42 , SVGTests(this) |
| 43 , m_transform(SVGAnimatedTransformList::create(this, SVGNames::transformAttr
, SVGTransformList::create())) |
45 { | 44 { |
| 45 addToPropertyMap(m_transform); |
46 registerAnimatedPropertiesForSVGGraphicsElement(); | 46 registerAnimatedPropertiesForSVGGraphicsElement(); |
47 } | 47 } |
48 | 48 |
49 SVGGraphicsElement::~SVGGraphicsElement() | 49 SVGGraphicsElement::~SVGGraphicsElement() |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 AffineTransform SVGGraphicsElement::getTransformToElement(SVGElement* target, Ex
ceptionState& exceptionState) | 53 PassRefPtr<SVGMatrixTearOff> SVGGraphicsElement::getTransformToElement(SVGElemen
t* target, ExceptionState& exceptionState) |
54 { | 54 { |
55 AffineTransform ctm = getCTM(AllowStyleUpdate); | 55 AffineTransform ctm = getCTM(AllowStyleUpdate); |
56 | 56 |
57 if (target && target->isSVGGraphicsElement()) { | 57 if (target && target->isSVGGraphicsElement()) { |
58 AffineTransform targetCTM = toSVGGraphicsElement(target)->getCTM(AllowSt
yleUpdate); | 58 AffineTransform targetCTM = toSVGGraphicsElement(target)->getCTM(AllowSt
yleUpdate); |
59 if (!targetCTM.isInvertible()) { | 59 if (!targetCTM.isInvertible()) { |
60 exceptionState.throwDOMException(InvalidStateError, "The target tran
sformation is not invertable."); | 60 exceptionState.throwDOMException(InvalidStateError, "The target tran
sformation is not invertable."); |
61 return ctm; | 61 return 0; |
62 } | 62 } |
63 ctm = targetCTM.inverse() * ctm; | 63 ctm = targetCTM.inverse() * ctm; |
64 } | 64 } |
65 | 65 |
66 return ctm; | 66 return SVGMatrixTearOff::create(ctm); |
67 } | 67 } |
68 | 68 |
69 static AffineTransform computeCTM(SVGGraphicsElement* element, SVGElement::CTMSc
ope mode, SVGGraphicsElement::StyleUpdateStrategy styleUpdateStrategy) | 69 static AffineTransform computeCTM(SVGGraphicsElement* element, SVGElement::CTMSc
ope mode, SVGGraphicsElement::StyleUpdateStrategy styleUpdateStrategy) |
70 { | 70 { |
71 ASSERT(element); | 71 ASSERT(element); |
72 if (styleUpdateStrategy == SVGGraphicsElement::AllowStyleUpdate) | 72 if (styleUpdateStrategy == SVGGraphicsElement::AllowStyleUpdate) |
73 element->document().updateLayoutIgnorePendingStylesheets(); | 73 element->document().updateLayoutIgnorePendingStylesheets(); |
74 | 74 |
75 AffineTransform ctm; | 75 AffineTransform ctm; |
76 | 76 |
(...skipping 15 matching lines...) Expand all Loading... |
92 AffineTransform SVGGraphicsElement::getCTM(StyleUpdateStrategy styleUpdateStrate
gy) | 92 AffineTransform SVGGraphicsElement::getCTM(StyleUpdateStrategy styleUpdateStrate
gy) |
93 { | 93 { |
94 return computeCTM(this, NearestViewportScope, styleUpdateStrategy); | 94 return computeCTM(this, NearestViewportScope, styleUpdateStrategy); |
95 } | 95 } |
96 | 96 |
97 AffineTransform SVGGraphicsElement::getScreenCTM(StyleUpdateStrategy styleUpdate
Strategy) | 97 AffineTransform SVGGraphicsElement::getScreenCTM(StyleUpdateStrategy styleUpdate
Strategy) |
98 { | 98 { |
99 return computeCTM(this, ScreenScope, styleUpdateStrategy); | 99 return computeCTM(this, ScreenScope, styleUpdateStrategy); |
100 } | 100 } |
101 | 101 |
| 102 PassRefPtr<SVGMatrixTearOff> SVGGraphicsElement::getCTMFromJavascript() |
| 103 { |
| 104 return SVGMatrixTearOff::create(getCTM()); |
| 105 } |
| 106 |
| 107 PassRefPtr<SVGMatrixTearOff> SVGGraphicsElement::getScreenCTMFromJavascript() |
| 108 { |
| 109 return SVGMatrixTearOff::create(getScreenCTM()); |
| 110 } |
| 111 |
102 AffineTransform SVGGraphicsElement::animatedLocalTransform() const | 112 AffineTransform SVGGraphicsElement::animatedLocalTransform() const |
103 { | 113 { |
104 AffineTransform matrix; | 114 AffineTransform matrix; |
105 RenderStyle* style = renderer() ? renderer()->style() : 0; | 115 RenderStyle* style = renderer() ? renderer()->style() : 0; |
106 | 116 |
107 // If CSS property was set, use that, otherwise fallback to attribute (if se
t). | 117 // If CSS property was set, use that, otherwise fallback to attribute (if se
t). |
108 if (style && style->hasTransform()) { | 118 if (style && style->hasTransform()) { |
109 // Note: objectBoundingBox is an emptyRect for elements like pattern or
clipPath. | 119 // Note: objectBoundingBox is an emptyRect for elements like pattern or
clipPath. |
110 // See the "Object bounding box units" section of http://dev.w3.org/cssw
g/css3-transforms/ | 120 // See the "Object bounding box units" section of http://dev.w3.org/cssw
g/css3-transforms/ |
111 TransformationMatrix transform; | 121 TransformationMatrix transform; |
112 style->applyTransform(transform, renderer()->objectBoundingBox()); | 122 style->applyTransform(transform, renderer()->objectBoundingBox()); |
113 | 123 |
114 // Flatten any 3D transform. | 124 // Flatten any 3D transform. |
115 matrix = transform.toAffineTransform(); | 125 matrix = transform.toAffineTransform(); |
116 | 126 |
117 // CSS bakes the zoom factor into lengths, including translation compone
nts. | 127 // CSS bakes the zoom factor into lengths, including translation compone
nts. |
118 // In order to align CSS & SVG transforms, we need to invert this operat
ion. | 128 // In order to align CSS & SVG transforms, we need to invert this operat
ion. |
119 float zoom = style->effectiveZoom(); | 129 float zoom = style->effectiveZoom(); |
120 if (zoom != 1) { | 130 if (zoom != 1) { |
121 matrix.setE(matrix.e() / zoom); | 131 matrix.setE(matrix.e() / zoom); |
122 matrix.setF(matrix.f() / zoom); | 132 matrix.setF(matrix.f() / zoom); |
123 } | 133 } |
124 } else { | 134 } else { |
125 transformCurrentValue().concatenate(matrix); | 135 m_transform->currentValue()->concatenate(matrix); |
126 } | 136 } |
127 | 137 |
128 if (m_supplementalTransform) | 138 if (m_supplementalTransform) |
129 return *m_supplementalTransform * matrix; | 139 return *m_supplementalTransform * matrix; |
130 return matrix; | 140 return matrix; |
131 } | 141 } |
132 | 142 |
133 AffineTransform* SVGGraphicsElement::supplementalTransform() | 143 AffineTransform* SVGGraphicsElement::supplementalTransform() |
134 { | 144 { |
135 if (!m_supplementalTransform) | 145 if (!m_supplementalTransform) |
(...skipping 11 matching lines...) Expand all Loading... |
147 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); | 157 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); |
148 } | 158 } |
149 | 159 |
150 void SVGGraphicsElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) | 160 void SVGGraphicsElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) |
151 { | 161 { |
152 if (!isSupportedAttribute(name)) { | 162 if (!isSupportedAttribute(name)) { |
153 SVGElement::parseAttribute(name, value); | 163 SVGElement::parseAttribute(name, value); |
154 return; | 164 return; |
155 } | 165 } |
156 | 166 |
157 if (name == SVGNames::transformAttr) { | 167 SVGParsingError parseError = NoError; |
158 SVGTransformList newList; | 168 |
159 newList.parse(value); | 169 if (name == SVGNames::transformAttr) |
160 detachAnimatedTransformListWrappers(newList.size()); | 170 m_transform->setBaseValueAsString(value, parseError); |
161 setTransformBaseValue(newList); | 171 else if (SVGTests::parseAttribute(name, value)) |
162 return; | 172 return; |
163 } else if (SVGTests::parseAttribute(name, value)) { | 173 else |
164 return; | 174 ASSERT_NOT_REACHED(); |
165 } | |
166 | 175 |
167 ASSERT_NOT_REACHED(); | 176 reportAttributeParsingError(parseError, name, value); |
168 } | 177 } |
169 | 178 |
170 void SVGGraphicsElement::svgAttributeChanged(const QualifiedName& attrName) | 179 void SVGGraphicsElement::svgAttributeChanged(const QualifiedName& attrName) |
171 { | 180 { |
172 if (!isSupportedAttribute(attrName)) { | 181 if (!isSupportedAttribute(attrName)) { |
173 SVGElement::svgAttributeChanged(attrName); | 182 SVGElement::svgAttributeChanged(attrName); |
174 return; | 183 return; |
175 } | 184 } |
176 | 185 |
177 SVGElementInstance::InvalidationGuard invalidationGuard(this); | 186 SVGElementInstance::InvalidationGuard invalidationGuard(this); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 255 } |
247 | 256 |
248 void SVGGraphicsElement::toClipPath(Path& path) | 257 void SVGGraphicsElement::toClipPath(Path& path) |
249 { | 258 { |
250 updatePathFromGraphicsElement(this, path); | 259 updatePathFromGraphicsElement(this, path); |
251 // FIXME: How do we know the element has done a layout? | 260 // FIXME: How do we know the element has done a layout? |
252 path.transform(animatedLocalTransform()); | 261 path.transform(animatedLocalTransform()); |
253 } | 262 } |
254 | 263 |
255 } | 264 } |
OLD | NEW |