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 #include "third_party/blink/renderer/core/svg/svg_transform_tear_off.h"
32
33 #include "third_party/blink/renderer/core/svg/svg_matrix_tear_off.h"
34 #include "third_party/blink/renderer/platform/heap/heap.h"
35
36 namespace blink {
37
SVGTransformTearOff(SVGMatrixTearOff * matrix)38 SVGTransformTearOff::SVGTransformTearOff(SVGMatrixTearOff* matrix)
39 : SVGTransformTearOff(MakeGarbageCollected<SVGTransform>(matrix->Value()),
40 nullptr,
41 kPropertyIsNotAnimVal) {}
42
SVGTransformTearOff(SVGTransform * target,SVGAnimatedPropertyBase * binding,PropertyIsAnimValType property_is_anim_val)43 SVGTransformTearOff::SVGTransformTearOff(
44 SVGTransform* target,
45 SVGAnimatedPropertyBase* binding,
46 PropertyIsAnimValType property_is_anim_val)
47 : SVGPropertyTearOff<SVGTransform>(target, binding, property_is_anim_val) {}
48
49 SVGTransformTearOff::~SVGTransformTearOff() = default;
50
Trace(Visitor * visitor) const51 void SVGTransformTearOff::Trace(Visitor* visitor) const {
52 visitor->Trace(matrix_tearoff_);
53 SVGPropertyTearOff<SVGTransform>::Trace(visitor);
54 }
55
CreateDetached()56 SVGTransformTearOff* SVGTransformTearOff::CreateDetached() {
57 return MakeGarbageCollected<SVGTransformTearOff>(
58 MakeGarbageCollected<SVGTransform>(blink::SVGTransformType::kMatrix),
59 nullptr, kPropertyIsNotAnimVal);
60 }
61
matrix()62 SVGMatrixTearOff* SVGTransformTearOff::matrix() {
63 if (!matrix_tearoff_)
64 matrix_tearoff_ = MakeGarbageCollected<SVGMatrixTearOff>(this);
65 return matrix_tearoff_.Get();
66 }
67
setMatrix(SVGMatrixTearOff * matrix,ExceptionState & exception_state)68 void SVGTransformTearOff::setMatrix(SVGMatrixTearOff* matrix,
69 ExceptionState& exception_state) {
70 if (IsImmutable()) {
71 ThrowReadOnly(exception_state);
72 return;
73 }
74 Target()->SetMatrix(matrix->Value());
75 CommitChange();
76 }
77
setTranslate(float tx,float ty,ExceptionState & exception_state)78 void SVGTransformTearOff::setTranslate(float tx,
79 float ty,
80 ExceptionState& exception_state) {
81 if (IsImmutable()) {
82 ThrowReadOnly(exception_state);
83 return;
84 }
85 Target()->SetTranslate(tx, ty);
86 CommitChange();
87 }
88
setScale(float sx,float sy,ExceptionState & exception_state)89 void SVGTransformTearOff::setScale(float sx,
90 float sy,
91 ExceptionState& exception_state) {
92 if (IsImmutable()) {
93 ThrowReadOnly(exception_state);
94 return;
95 }
96 Target()->SetScale(sx, sy);
97 CommitChange();
98 }
99
setRotate(float angle,float cx,float cy,ExceptionState & exception_state)100 void SVGTransformTearOff::setRotate(float angle,
101 float cx,
102 float cy,
103 ExceptionState& exception_state) {
104 if (IsImmutable()) {
105 ThrowReadOnly(exception_state);
106 return;
107 }
108 Target()->SetRotate(angle, cx, cy);
109 CommitChange();
110 }
111
setSkewX(float x,ExceptionState & exception_state)112 void SVGTransformTearOff::setSkewX(float x, ExceptionState& exception_state) {
113 if (IsImmutable()) {
114 ThrowReadOnly(exception_state);
115 return;
116 }
117 Target()->SetSkewX(x);
118 CommitChange();
119 }
120
setSkewY(float y,ExceptionState & exception_state)121 void SVGTransformTearOff::setSkewY(float y, ExceptionState& exception_state) {
122 if (IsImmutable()) {
123 ThrowReadOnly(exception_state);
124 return;
125 }
126 Target()->SetSkewY(y);
127 CommitChange();
128 }
129
130 } // namespace blink
131