2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / svg / SVGStyledTransformableElement.cpp
bloba7b5c41640d09342a12be40181022877ea499f62
1 /*
2 Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
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.
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.
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.
23 #include "config.h"
25 #if ENABLE(SVG)
26 #include "SVGStyledTransformableElement.h"
28 #include "Attr.h"
29 #include "RegularExpression.h"
30 #include "RenderPath.h"
31 #include "SVGDocument.h"
32 #include "AffineTransform.h"
33 #include "SVGStyledElement.h"
34 #include "SVGTransformList.h"
36 namespace WebCore {
38 char SVGStyledTransformableElementIdentifier[] = "SVGStyledTransformableElement";
40 SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName& tagName, Document* doc)
41 : SVGStyledLocatableElement(tagName, doc)
42 , SVGTransformable()
43 , m_transform(this, SVGNames::transformAttr, SVGTransformList::create(SVGNames::transformAttr))
47 SVGStyledTransformableElement::~SVGStyledTransformableElement()
51 AffineTransform SVGStyledTransformableElement::getCTM() const
53 return SVGTransformable::getCTM(this);
56 AffineTransform SVGStyledTransformableElement::getScreenCTM() const
58 return SVGTransformable::getScreenCTM(this);
61 AffineTransform SVGStyledTransformableElement::animatedLocalTransform() const
63 return m_supplementalTransform ? transform()->concatenate().matrix() * *m_supplementalTransform : transform()->concatenate().matrix();
66 AffineTransform* SVGStyledTransformableElement::supplementalTransform()
68 if (!m_supplementalTransform)
69 m_supplementalTransform.set(new AffineTransform());
70 return m_supplementalTransform.get();
73 void SVGStyledTransformableElement::parseMappedAttribute(MappedAttribute* attr)
75 if (attr->name() == SVGNames::transformAttr) {
76 SVGTransformList* localTransforms = transformBaseValue();
78 ExceptionCode ec = 0;
79 localTransforms->clear(ec);
81 if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value()))
82 localTransforms->clear(ec);
83 else
84 setTransformBaseValue(localTransforms);
85 } else
86 SVGStyledLocatableElement::parseMappedAttribute(attr);
89 bool SVGStyledTransformableElement::isKnownAttribute(const QualifiedName& attrName)
91 return SVGTransformable::isKnownAttribute(attrName) ||
92 SVGStyledLocatableElement::isKnownAttribute(attrName);
95 SVGElement* SVGStyledTransformableElement::nearestViewportElement() const
97 return SVGTransformable::nearestViewportElement(this);
100 SVGElement* SVGStyledTransformableElement::farthestViewportElement() const
102 return SVGTransformable::farthestViewportElement(this);
105 FloatRect SVGStyledTransformableElement::getBBox() const
107 return SVGTransformable::getBBox(this);
110 RenderObject* SVGStyledTransformableElement::createRenderer(RenderArena* arena, RenderStyle* style)
112 // By default, any subclass is expected to do path-based drawing
113 return new (arena) RenderPath(style, this);
116 Path SVGStyledTransformableElement::toClipPath() const
118 Path pathData = toPathData();
119 // FIXME: How do we know the element has done a layout?
120 pathData.transform(animatedLocalTransform());
121 return pathData;
126 #endif // ENABLE(SVG)