blob: b90887a4ae149081eceb198efcceca2b4cdbb5af [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
zimmermann@webkit.org711245f2010-08-03 19:39:01 +00002 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 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 */
darinb9481ed2006-03-20 02:57:59 +000020
21#include "config.h"
weinig5fc44ff2006-10-24 21:57:42 +000022
mjsd2948ef2007-02-26 19:29:04 +000023#if ENABLE(SVG)
weinig5fc44ff2006-10-24 21:57:42 +000024#include "SVGStyledTransformableElement.h"
25
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000026#include "AffineTransform.h"
eseidel40eb1b92006-03-25 22:20:36 +000027#include "Attr.h"
andreas.kling@nokia.comecf49562010-10-07 07:33:33 +000028#include "RenderSVGPath.h"
weinig5fc44ff2006-10-24 21:57:42 +000029#include "SVGDocument.h"
darinb9481ed2006-03-20 02:57:59 +000030#include "SVGStyledElement.h"
eseidela7f76262006-09-06 03:36:10 +000031#include "SVGTransformList.h"
darinb9481ed2006-03-20 02:57:59 +000032
rwlbuisdde95e22006-12-03 12:02:26 +000033namespace WebCore {
darinb9481ed2006-03-20 02:57:59 +000034
darin@apple.comc8b8f872010-08-30 18:44:06 +000035SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName& tagName, Document* document)
36 : SVGStyledLocatableElement(tagName, document)
zimmermann@webkit.org8fc45392010-01-27 01:51:39 +000037 , m_transform(SVGTransformList::create(SVGNames::transformAttr))
darinb9481ed2006-03-20 02:57:59 +000038{
39}
40
simon.fraser@apple.com64487f92010-08-19 17:19:40 +000041AffineTransform SVGStyledTransformableElement::getCTM(StyleUpdateStrategy styleUpdateStrategy) const
darinb9481ed2006-03-20 02:57:59 +000042{
simon.fraser@apple.com64487f92010-08-19 17:19:40 +000043 return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, styleUpdateStrategy);
darinb9481ed2006-03-20 02:57:59 +000044}
45
simon.fraser@apple.com64487f92010-08-19 17:19:40 +000046AffineTransform SVGStyledTransformableElement::getScreenCTM(StyleUpdateStrategy styleUpdateStrategy) const
darinb9481ed2006-03-20 02:57:59 +000047{
simon.fraser@apple.com64487f92010-08-19 17:19:40 +000048 return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdateStrategy);
darinb9481ed2006-03-20 02:57:59 +000049}
50
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000051AffineTransform SVGStyledTransformableElement::animatedLocalTransform() const
darinb9481ed2006-03-20 02:57:59 +000052{
antti@apple.comaf579272008-04-18 07:40:17 +000053 return m_supplementalTransform ? transform()->concatenate().matrix() * *m_supplementalTransform : transform()->concatenate().matrix();
54}
55
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000056AffineTransform* SVGStyledTransformableElement::supplementalTransform()
antti@apple.comaf579272008-04-18 07:40:17 +000057{
58 if (!m_supplementalTransform)
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000059 m_supplementalTransform.set(new AffineTransform());
antti@apple.comaf579272008-04-18 07:40:17 +000060 return m_supplementalTransform.get();
darinb9481ed2006-03-20 02:57:59 +000061}
62
weinig@apple.comc3608932010-05-19 17:48:06 +000063void SVGStyledTransformableElement::parseMappedAttribute(Attribute* attr)
darinb9481ed2006-03-20 02:57:59 +000064{
zimmermann@webkit.orgbe274bd2010-01-08 00:36:10 +000065 if (SVGTransformable::isKnownAttribute(attr->name())) {
rwlbuisdde95e22006-12-03 12:02:26 +000066 SVGTransformList* localTransforms = transformBaseValue();
zimmermann@webkit.orgbe274bd2010-01-08 00:36:10 +000067 if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value())) {
68 ExceptionCode ec = 0;
rwlbuisc8a141e2006-12-08 08:02:35 +000069 localTransforms->clear(ec);
zimmermann@webkit.orgbe274bd2010-01-08 00:36:10 +000070 }
71 } else
darinb9481ed2006-03-20 02:57:59 +000072 SVGStyledLocatableElement::parseMappedAttribute(attr);
73}
74
zimmermann@webkit.org8fc45392010-01-27 01:51:39 +000075void SVGStyledTransformableElement::synchronizeProperty(const QualifiedName& attrName)
76{
77 SVGStyledLocatableElement::synchronizeProperty(attrName);
78
79 if (attrName == anyQName() || SVGTransformable::isKnownAttribute(attrName))
80 synchronizeTransform();
81}
82
zimmermann@webkit.org52b39ec2008-02-03 23:18:53 +000083bool SVGStyledTransformableElement::isKnownAttribute(const QualifiedName& attrName)
84{
85 return SVGTransformable::isKnownAttribute(attrName) ||
86 SVGStyledLocatableElement::isKnownAttribute(attrName);
87}
88
rwlbuisdde95e22006-12-03 12:02:26 +000089SVGElement* SVGStyledTransformableElement::nearestViewportElement() const
darinb9481ed2006-03-20 02:57:59 +000090{
91 return SVGTransformable::nearestViewportElement(this);
92}
93
rwlbuisdde95e22006-12-03 12:02:26 +000094SVGElement* SVGStyledTransformableElement::farthestViewportElement() const
darinb9481ed2006-03-20 02:57:59 +000095{
96 return SVGTransformable::farthestViewportElement(this);
97}
98
simon.fraser@apple.com64487f92010-08-19 17:19:40 +000099FloatRect SVGStyledTransformableElement::getBBox(StyleUpdateStrategy styleUpdateStrategy) const
darinb9481ed2006-03-20 02:57:59 +0000100{
simon.fraser@apple.com64487f92010-08-19 17:19:40 +0000101 return SVGTransformable::getBBox(this, styleUpdateStrategy);
darinb9481ed2006-03-20 02:57:59 +0000102}
103
darin@apple.comfaced262009-01-12 07:44:27 +0000104RenderObject* SVGStyledTransformableElement::createRenderer(RenderArena* arena, RenderStyle*)
oliver09e98ea2007-10-12 15:38:34 +0000105{
106 // By default, any subclass is expected to do path-based drawing
andreas.kling@nokia.comecf49562010-10-07 07:33:33 +0000107 return new (arena) RenderSVGPath(this);
oliver09e98ea2007-10-12 15:38:34 +0000108}
109
rwlbuis@webkit.org8f675dd2008-09-16 11:12:52 +0000110Path SVGStyledTransformableElement::toClipPath() const
111{
112 Path pathData = toPathData();
113 // FIXME: How do we know the element has done a layout?
114 pathData.transform(animatedLocalTransform());
115 return pathData;
116}
117
oliver666a58d2007-10-12 12:28:28 +0000118}
119
mjsd2948ef2007-02-26 19:29:04 +0000120#endif // ENABLE(SVG)