2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "core/svg/SVGMatrixTearOff.h"
34 #include "bindings/core/v8/ExceptionState.h"
35 #include "core/dom/ExceptionCode.h"
36 #include "core/svg/SVGElement.h"
37 #include "core/svg/SVGTransformTearOff.h"
41 SVGMatrixTearOff::SVGMatrixTearOff(const AffineTransform
& staticValue
)
42 : m_staticValue(staticValue
)
43 , m_contextTransform(nullptr)
47 SVGMatrixTearOff::SVGMatrixTearOff(SVGTransformTearOff
* transform
)
48 : m_contextTransform(transform
)
53 SVGMatrixTearOff::~SVGMatrixTearOff()
57 DEFINE_TRACE(SVGMatrixTearOff
)
59 visitor
->trace(m_contextTransform
);
62 const AffineTransform
& SVGMatrixTearOff::value() const
64 return m_contextTransform
? m_contextTransform
->target()->matrix() : m_staticValue
;
67 AffineTransform
* SVGMatrixTearOff::mutableValue()
69 return m_contextTransform
? m_contextTransform
->target()->mutableMatrix() : &m_staticValue
;
72 void SVGMatrixTearOff::commitChange()
74 if (!m_contextTransform
)
77 m_contextTransform
->target()->onMatrixChange();
78 m_contextTransform
->commitChange();
81 #define DEFINE_SETTER(ATTRIBUTE) \
82 void SVGMatrixTearOff::set##ATTRIBUTE(double f, ExceptionState& exceptionState) \
84 if (m_contextTransform && m_contextTransform->isImmutable()) { \
85 exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); \
88 mutableValue()->set##ATTRIBUTE(f); \
101 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::translate(double tx
, double ty
)
103 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
104 matrix
->mutableValue()->translate(tx
, ty
);
105 return matrix
.release();
108 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::scale(double s
)
110 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
111 matrix
->mutableValue()->scale(s
, s
);
112 return matrix
.release();
115 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::scaleNonUniform(double sx
, double sy
)
117 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
118 matrix
->mutableValue()->scale(sx
, sy
);
119 return matrix
.release();
122 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::rotate(double d
)
124 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
125 matrix
->mutableValue()->rotate(d
);
126 return matrix
.release();
129 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::flipX()
131 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
132 matrix
->mutableValue()->flipX();
133 return matrix
.release();
136 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::flipY()
138 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
139 matrix
->mutableValue()->flipY();
140 return matrix
.release();
143 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::skewX(double angle
)
145 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
146 matrix
->mutableValue()->skewX(angle
);
147 return matrix
.release();
150 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::skewY(double angle
)
152 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
153 matrix
->mutableValue()->skewY(angle
);
154 return matrix
.release();
157 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::multiply(PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> other
)
159 RefPtrWillBeRawPtr
<SVGMatrixTearOff
> matrix
= create(value());
160 *matrix
->mutableValue() *= other
->value();
161 return matrix
.release();
164 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::inverse(ExceptionState
& exceptionState
)
166 AffineTransform transform
= value().inverse();
167 if (!value().isInvertible())
168 exceptionState
.throwDOMException(InvalidStateError
, "The matrix is not invertible.");
170 return create(transform
);
173 PassRefPtrWillBeRawPtr
<SVGMatrixTearOff
> SVGMatrixTearOff::rotateFromVector(double x
, double y
, ExceptionState
& exceptionState
)
176 exceptionState
.throwDOMException(InvalidAccessError
, "Arguments cannot be zero.");
178 AffineTransform copy
= value();
179 copy
.rotateFromVector(x
, y
);