• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
4 
5     This file is part of the KDE project
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16 
17     You should have received a copy of the GNU Library General Public License
18     along with this library; see the file COPYING.LIB.  If not, write to
19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20     Boston, MA 02110-1301, USA.
21 */
22 
23 #include "config.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGStyledTransformableElement.h"
27 
28 #include "Attr.h"
29 #include "MappedAttribute.h"
30 #include "RenderPath.h"
31 #include "SVGDocument.h"
32 #include "SVGStyledElement.h"
33 #include "SVGTransformList.h"
34 #include "TransformationMatrix.h"
35 
36 namespace WebCore {
37 
38 char SVGStyledTransformableElementIdentifier[] = "SVGStyledTransformableElement";
39 
SVGStyledTransformableElement(const QualifiedName & tagName,Document * doc)40 SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName& tagName, Document* doc)
41     : SVGStyledLocatableElement(tagName, doc)
42     , SVGTransformable()
43     , m_transform(this, SVGNames::transformAttr, SVGTransformList::create(SVGNames::transformAttr))
44 {
45 }
46 
~SVGStyledTransformableElement()47 SVGStyledTransformableElement::~SVGStyledTransformableElement()
48 {
49 }
50 
getCTM() const51 TransformationMatrix SVGStyledTransformableElement::getCTM() const
52 {
53     return SVGTransformable::getCTM(this);
54 }
55 
getScreenCTM() const56 TransformationMatrix SVGStyledTransformableElement::getScreenCTM() const
57 {
58     return SVGTransformable::getScreenCTM(this);
59 }
60 
animatedLocalTransform() const61 TransformationMatrix SVGStyledTransformableElement::animatedLocalTransform() const
62 {
63     return m_supplementalTransform ? transform()->concatenate().matrix() * *m_supplementalTransform : transform()->concatenate().matrix();
64 }
65 
supplementalTransform()66 TransformationMatrix* SVGStyledTransformableElement::supplementalTransform()
67 {
68     if (!m_supplementalTransform)
69         m_supplementalTransform.set(new TransformationMatrix());
70     return m_supplementalTransform.get();
71 }
72 
parseMappedAttribute(MappedAttribute * attr)73 void SVGStyledTransformableElement::parseMappedAttribute(MappedAttribute* attr)
74 {
75     if (attr->name() == SVGNames::transformAttr) {
76         SVGTransformList* localTransforms = transformBaseValue();
77 
78         ExceptionCode ec = 0;
79         localTransforms->clear(ec);
80 
81         if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value()))
82             localTransforms->clear(ec);
83         else
84             setTransformBaseValue(localTransforms);
85     } else
86         SVGStyledLocatableElement::parseMappedAttribute(attr);
87 }
88 
isKnownAttribute(const QualifiedName & attrName)89 bool SVGStyledTransformableElement::isKnownAttribute(const QualifiedName& attrName)
90 {
91     return SVGTransformable::isKnownAttribute(attrName) ||
92            SVGStyledLocatableElement::isKnownAttribute(attrName);
93 }
94 
nearestViewportElement() const95 SVGElement* SVGStyledTransformableElement::nearestViewportElement() const
96 {
97     return SVGTransformable::nearestViewportElement(this);
98 }
99 
farthestViewportElement() const100 SVGElement* SVGStyledTransformableElement::farthestViewportElement() const
101 {
102     return SVGTransformable::farthestViewportElement(this);
103 }
104 
getBBox() const105 FloatRect SVGStyledTransformableElement::getBBox() const
106 {
107     return SVGTransformable::getBBox(this);
108 }
109 
createRenderer(RenderArena * arena,RenderStyle *)110 RenderObject* SVGStyledTransformableElement::createRenderer(RenderArena* arena, RenderStyle*)
111 {
112     // By default, any subclass is expected to do path-based drawing
113     return new (arena) RenderPath(this);
114 }
115 
toClipPath() const116 Path SVGStyledTransformableElement::toClipPath() const
117 {
118     Path pathData = toPathData();
119     // FIXME: How do we know the element has done a layout?
120     pathData.transform(animatedLocalTransform());
121     return pathData;
122 }
123 
124 }
125 
126 #endif // ENABLE(SVG)
127