|
1 /* |
|
2 Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
|
3 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 #if ENABLE(SVG) |
|
24 #include "SVGStyledTransformableElement.h" |
|
25 |
|
26 #include "AffineTransform.h" |
|
27 #include "Attr.h" |
|
28 #include "RenderPath.h" |
|
29 #include "SVGDocument.h" |
|
30 #include "SVGStyledElement.h" |
|
31 #include "SVGTransformList.h" |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName& tagName, Document* doc) |
|
36 : SVGStyledLocatableElement(tagName, doc) |
|
37 , SVGTransformable() |
|
38 , m_transform(SVGTransformList::create(SVGNames::transformAttr)) |
|
39 { |
|
40 } |
|
41 |
|
42 SVGStyledTransformableElement::~SVGStyledTransformableElement() |
|
43 { |
|
44 } |
|
45 |
|
46 AffineTransform SVGStyledTransformableElement::getCTM() const |
|
47 { |
|
48 return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope); |
|
49 } |
|
50 |
|
51 AffineTransform SVGStyledTransformableElement::getScreenCTM() const |
|
52 { |
|
53 return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope); |
|
54 } |
|
55 |
|
56 AffineTransform SVGStyledTransformableElement::animatedLocalTransform() const |
|
57 { |
|
58 return m_supplementalTransform ? transform()->concatenate().matrix() * *m_supplementalTransform : transform()->concatenate().matrix(); |
|
59 } |
|
60 |
|
61 AffineTransform* SVGStyledTransformableElement::supplementalTransform() |
|
62 { |
|
63 if (!m_supplementalTransform) |
|
64 m_supplementalTransform.set(new AffineTransform()); |
|
65 return m_supplementalTransform.get(); |
|
66 } |
|
67 |
|
68 void SVGStyledTransformableElement::parseMappedAttribute(Attribute* attr) |
|
69 { |
|
70 if (SVGTransformable::isKnownAttribute(attr->name())) { |
|
71 SVGTransformList* localTransforms = transformBaseValue(); |
|
72 if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value())) { |
|
73 ExceptionCode ec = 0; |
|
74 localTransforms->clear(ec); |
|
75 } |
|
76 } else |
|
77 SVGStyledLocatableElement::parseMappedAttribute(attr); |
|
78 } |
|
79 |
|
80 void SVGStyledTransformableElement::synchronizeProperty(const QualifiedName& attrName) |
|
81 { |
|
82 SVGStyledLocatableElement::synchronizeProperty(attrName); |
|
83 |
|
84 if (attrName == anyQName() || SVGTransformable::isKnownAttribute(attrName)) |
|
85 synchronizeTransform(); |
|
86 } |
|
87 |
|
88 bool SVGStyledTransformableElement::isKnownAttribute(const QualifiedName& attrName) |
|
89 { |
|
90 return SVGTransformable::isKnownAttribute(attrName) || |
|
91 SVGStyledLocatableElement::isKnownAttribute(attrName); |
|
92 } |
|
93 |
|
94 SVGElement* SVGStyledTransformableElement::nearestViewportElement() const |
|
95 { |
|
96 return SVGTransformable::nearestViewportElement(this); |
|
97 } |
|
98 |
|
99 SVGElement* SVGStyledTransformableElement::farthestViewportElement() const |
|
100 { |
|
101 return SVGTransformable::farthestViewportElement(this); |
|
102 } |
|
103 |
|
104 FloatRect SVGStyledTransformableElement::getBBox() const |
|
105 { |
|
106 return SVGTransformable::getBBox(this); |
|
107 } |
|
108 |
|
109 RenderObject* SVGStyledTransformableElement::createRenderer(RenderArena* arena, RenderStyle*) |
|
110 { |
|
111 // By default, any subclass is expected to do path-based drawing |
|
112 return new (arena) RenderPath(this); |
|
113 } |
|
114 |
|
115 Path SVGStyledTransformableElement::toClipPath() const |
|
116 { |
|
117 Path pathData = toPathData(); |
|
118 // FIXME: How do we know the element has done a layout? |
|
119 pathData.transform(animatedLocalTransform()); |
|
120 return pathData; |
|
121 } |
|
122 |
|
123 } |
|
124 |
|
125 #endif // ENABLE(SVG) |