1/*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef SVGMatrixTearOff_h
32#define SVGMatrixTearOff_h
33
34#include "bindings/core/v8/ExceptionState.h"
35#include "bindings/core/v8/ScriptWrappable.h"
36#include "platform/transforms/AffineTransform.h"
37#include "wtf/RefCounted.h"
38
39namespace blink {
40
41class SVGTransformTearOff;
42
43// SVGMatrixTearOff wraps a AffineTransform for Javascript.
44// Its instance can either hold a static value, or this can be teared off from |SVGTransform.matrix|.
45// This does not derive from SVGPropertyTearOff, as its instances are never tied to an animated property nor an XML attribute.
46class SVGMatrixTearOff FINAL : public RefCounted<SVGMatrixTearOff>, public ScriptWrappable {
47    DEFINE_WRAPPERTYPEINFO();
48public:
49    static PassRefPtr<SVGMatrixTearOff> create(const AffineTransform& value)
50    {
51        return adoptRef(new SVGMatrixTearOff(value));
52    }
53
54    static PassRefPtr<SVGMatrixTearOff> create(SVGTransformTearOff* target)
55    {
56        return adoptRef(new SVGMatrixTearOff(target));
57    }
58
59    ~SVGMatrixTearOff();
60
61    double a() { return value().a(); }
62    double b() { return value().b(); }
63    double c() { return value().c(); }
64    double d() { return value().d(); }
65    double e() { return value().e(); }
66    double f() { return value().f(); }
67
68    void setA(double, ExceptionState&);
69    void setB(double, ExceptionState&);
70    void setC(double, ExceptionState&);
71    void setD(double, ExceptionState&);
72    void setE(double, ExceptionState&);
73    void setF(double, ExceptionState&);
74
75    PassRefPtr<SVGMatrixTearOff> translate(double tx, double ty);
76    PassRefPtr<SVGMatrixTearOff> scale(double);
77    PassRefPtr<SVGMatrixTearOff> scaleNonUniform(double sx, double sy);
78    PassRefPtr<SVGMatrixTearOff> rotate(double);
79    PassRefPtr<SVGMatrixTearOff> flipX();
80    PassRefPtr<SVGMatrixTearOff> flipY();
81    PassRefPtr<SVGMatrixTearOff> skewX(double);
82    PassRefPtr<SVGMatrixTearOff> skewY(double);
83    PassRefPtr<SVGMatrixTearOff> multiply(PassRefPtr<SVGMatrixTearOff>);
84    PassRefPtr<SVGMatrixTearOff> inverse(ExceptionState&);
85    PassRefPtr<SVGMatrixTearOff> rotateFromVector(double x, double y, ExceptionState&);
86
87    SVGTransformTearOff* contextTransform() { return m_contextTransform; }
88
89    const AffineTransform& value() const;
90
91private:
92    SVGMatrixTearOff(const AffineTransform&);
93    SVGMatrixTearOff(SVGTransformTearOff*);
94
95    AffineTransform* mutableValue();
96    void commitChange();
97
98    AffineTransform m_staticValue;
99
100    // FIXME: oilpan: This is raw-ptr to avoid reference cycles. Should be Member in oilpan.
101    SVGTransformTearOff* m_contextTransform;
102};
103
104} // namespace blink
105
106#endif // SVGMatrixTearOff_h
107