1/*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 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#ifndef SVGTransform_h
22#define SVGTransform_h
23
24#include "core/svg/properties/SVGProperty.h"
25#include "platform/geometry/FloatPoint.h"
26#include "platform/transforms/AffineTransform.h"
27#include "wtf/text/WTFString.h"
28
29namespace blink {
30
31class FloatSize;
32class SVGTransformTearOff;
33
34enum SVGTransformType {
35    SVG_TRANSFORM_UNKNOWN = 0,
36    SVG_TRANSFORM_MATRIX = 1,
37    SVG_TRANSFORM_TRANSLATE = 2,
38    SVG_TRANSFORM_SCALE = 3,
39    SVG_TRANSFORM_ROTATE = 4,
40    SVG_TRANSFORM_SKEWX = 5,
41    SVG_TRANSFORM_SKEWY = 6
42};
43
44class SVGTransform : public SVGPropertyBase {
45public:
46    typedef SVGTransformTearOff TearOffType;
47
48    enum ConstructionMode {
49        ConstructIdentityTransform,
50        ConstructZeroTransform
51    };
52
53    static PassRefPtr<SVGTransform> create()
54    {
55        return adoptRef(new SVGTransform());
56    }
57
58    static PassRefPtr<SVGTransform> create(SVGTransformType type, ConstructionMode mode = ConstructIdentityTransform)
59    {
60        return adoptRef(new SVGTransform(type, mode));
61    }
62
63    static PassRefPtr<SVGTransform> create(const AffineTransform& affineTransform)
64    {
65        return adoptRef(new SVGTransform(affineTransform));
66    }
67
68    virtual ~SVGTransform();
69
70    PassRefPtr<SVGTransform> clone() const;
71    virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const OVERRIDE;
72
73    SVGTransformType transformType() const { return m_transformType; }
74
75    const AffineTransform& matrix() const { return m_matrix; }
76
77    // |onMatrixChange| must be called after modifications via |mutableMatrix|.
78    AffineTransform* mutableMatrix() { return &m_matrix; }
79    void onMatrixChange();
80
81    float angle() const { return m_angle; }
82    FloatPoint rotationCenter() const { return m_center; }
83
84    void setMatrix(const AffineTransform&);
85    void setTranslate(float tx, float ty);
86    void setScale(float sx, float sy);
87    void setRotate(float angle, float cx, float cy);
88    void setSkewX(float angle);
89    void setSkewY(float angle);
90
91    // Internal use only (animation system)
92    FloatPoint translate() const;
93    FloatSize scale() const;
94
95    virtual String valueAsString() const OVERRIDE;
96
97    virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERRIDE;
98    virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) OVERRIDE;
99    virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement* contextElement) OVERRIDE;
100
101    static AnimatedPropertyType classType() { return AnimatedTransform; }
102
103private:
104    SVGTransform();
105    SVGTransform(SVGTransformType, ConstructionMode);
106    explicit SVGTransform(const AffineTransform&);
107    SVGTransform(SVGTransformType, float, const FloatPoint&, const AffineTransform&);
108
109    SVGTransformType m_transformType;
110    float m_angle;
111    FloatPoint m_center;
112    AffineTransform m_matrix;
113};
114
115} // namespace blink
116
117#endif
118