Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / svg / SVGStyledTransformableElement.cpp
blob4e97c833b77787a6b7c03d4a943c88bd76d13b4d
1 /*
2 Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
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.
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.
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.
21 #include "config.h"
23 #if ENABLE(SVG)
24 #include "SVGStyledTransformableElement.h"
26 #include "Attr.h"
27 #include "MappedAttribute.h"
28 #include "RenderPath.h"
29 #include "SVGDocument.h"
30 #include "SVGStyledElement.h"
31 #include "SVGTransformList.h"
32 #include "TransformationMatrix.h"
34 namespace WebCore {
36 char SVGStyledTransformableElementIdentifier[] = "SVGStyledTransformableElement";
38 SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName& tagName, Document* doc)
39 : SVGStyledLocatableElement(tagName, doc)
40 , SVGTransformable()
41 , m_transform(this, SVGNames::transformAttr, SVGTransformList::create(SVGNames::transformAttr))
45 SVGStyledTransformableElement::~SVGStyledTransformableElement()
49 TransformationMatrix SVGStyledTransformableElement::getCTM() const
51 return SVGTransformable::getCTM(this);
54 TransformationMatrix SVGStyledTransformableElement::getScreenCTM() const
56 return SVGTransformable::getScreenCTM(this);
59 TransformationMatrix SVGStyledTransformableElement::animatedLocalTransform() const
61 return m_supplementalTransform ? transform()->concatenate().matrix() * *m_supplementalTransform : transform()->concatenate().matrix();
64 TransformationMatrix* SVGStyledTransformableElement::supplementalTransform()
66 if (!m_supplementalTransform)
67 m_supplementalTransform.set(new TransformationMatrix());
68 return m_supplementalTransform.get();
71 void SVGStyledTransformableElement::parseMappedAttribute(MappedAttribute* attr)
73 if (attr->name() == SVGNames::transformAttr) {
74 SVGTransformList* localTransforms = transformBaseValue();
76 ExceptionCode ec = 0;
77 localTransforms->clear(ec);
79 if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value()))
80 localTransforms->clear(ec);
81 else
82 setTransformBaseValue(localTransforms);
83 } else
84 SVGStyledLocatableElement::parseMappedAttribute(attr);
87 bool SVGStyledTransformableElement::isKnownAttribute(const QualifiedName& attrName)
89 return SVGTransformable::isKnownAttribute(attrName) ||
90 SVGStyledLocatableElement::isKnownAttribute(attrName);
93 SVGElement* SVGStyledTransformableElement::nearestViewportElement() const
95 return SVGTransformable::nearestViewportElement(this);
98 SVGElement* SVGStyledTransformableElement::farthestViewportElement() const
100 return SVGTransformable::farthestViewportElement(this);
103 FloatRect SVGStyledTransformableElement::getBBox() const
105 return SVGTransformable::getBBox(this);
108 RenderObject* SVGStyledTransformableElement::createRenderer(RenderArena* arena, RenderStyle*)
110 // By default, any subclass is expected to do path-based drawing
111 return new (arena) RenderPath(this);
114 Path SVGStyledTransformableElement::toClipPath() const
116 Path pathData = toPathData();
117 // FIXME: How do we know the element has done a layout?
118 pathData.transform(animatedLocalTransform());
119 return pathData;
124 #endif // ENABLE(SVG)