OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/cssom/CSSMatrixComponent.h" | 5 #include "core/css/cssom/CSSMatrixComponent.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <memory> | 8 #include <memory> |
9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
10 #include "platform/wtf/MathExtras.h" | 10 #include "platform/wtf/MathExtras.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 for (double value : values) { | 35 for (double value : values) { |
36 result->Append(*CSSPrimitiveValue::Create( | 36 result->Append(*CSSPrimitiveValue::Create( |
37 value, CSSPrimitiveValue::UnitType::kNumber)); | 37 value, CSSPrimitiveValue::UnitType::kNumber)); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 return result; | 41 return result; |
42 } | 42 } |
43 | 43 |
44 CSSMatrixComponent* CSSMatrixComponent::Perspective(double length) { | 44 CSSMatrixComponent* CSSMatrixComponent::Perspective(double length) { |
45 DOMMatrixInit init; | 45 DOMMatrix* matrix = DOMMatrix::Create(); |
46 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
47 | 46 |
48 if (length != 0) | 47 if (length != 0) |
49 matrix->setM34(-1 / length); | 48 matrix->setM34(-1 / length); |
50 return new CSSMatrixComponent(matrix, kPerspectiveType); | 49 return new CSSMatrixComponent(matrix, kPerspectiveType); |
51 } | 50 } |
52 | 51 |
53 CSSMatrixComponent* CSSMatrixComponent::Rotate(double angle) { | 52 CSSMatrixComponent* CSSMatrixComponent::Rotate(double angle) { |
54 DOMMatrixInit init; | 53 DOMMatrix* matrix = DOMMatrix::Create(); |
55 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
56 | 54 |
57 matrix->rotateSelf(angle); | 55 matrix->rotateSelf(angle); |
58 return new CSSMatrixComponent(matrix, kRotationType); | 56 return new CSSMatrixComponent(matrix, kRotationType); |
59 } | 57 } |
60 | 58 |
61 CSSMatrixComponent* CSSMatrixComponent::Rotate3d(double angle, | 59 CSSMatrixComponent* CSSMatrixComponent::Rotate3d(double angle, |
62 double x, | 60 double x, |
63 double y, | 61 double y, |
64 double z) { | 62 double z) { |
65 DOMMatrixInit init; | 63 DOMMatrix* matrix = DOMMatrix::Create(); |
66 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
67 | 64 |
68 matrix->rotateAxisAngleSelf(x, y, z, angle); | 65 matrix->rotateAxisAngleSelf(x, y, z, angle); |
69 return new CSSMatrixComponent(matrix, kRotation3DType); | 66 return new CSSMatrixComponent(matrix, kRotation3DType); |
70 } | 67 } |
71 | 68 |
72 CSSMatrixComponent* CSSMatrixComponent::Scale(double x, double y) { | 69 CSSMatrixComponent* CSSMatrixComponent::Scale(double x, double y) { |
73 DOMMatrixInit init; | 70 DOMMatrix* matrix = DOMMatrix::Create(); |
74 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
75 | 71 |
76 matrix->setM11(x); | 72 matrix->setM11(x); |
77 matrix->setM22(y); | 73 matrix->setM22(y); |
78 return new CSSMatrixComponent(matrix, kScaleType); | 74 return new CSSMatrixComponent(matrix, kScaleType); |
79 } | 75 } |
80 | 76 |
81 CSSMatrixComponent* CSSMatrixComponent::Scale3d(double x, double y, double z) { | 77 CSSMatrixComponent* CSSMatrixComponent::Scale3d(double x, double y, double z) { |
82 DOMMatrixInit init; | 78 DOMMatrix* matrix = DOMMatrix::Create(); |
83 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
84 | 79 |
85 matrix->setM11(x); | 80 matrix->setM11(x); |
86 matrix->setM22(y); | 81 matrix->setM22(y); |
87 matrix->setM33(z); | 82 matrix->setM33(z); |
88 return new CSSMatrixComponent(matrix, kScale3DType); | 83 return new CSSMatrixComponent(matrix, kScale3DType); |
89 } | 84 } |
90 | 85 |
91 CSSMatrixComponent* CSSMatrixComponent::Skew(double ax, double ay) { | 86 CSSMatrixComponent* CSSMatrixComponent::Skew(double ax, double ay) { |
92 double tan_ax = std::tan(deg2rad(ax)); | 87 double tan_ax = std::tan(deg2rad(ax)); |
93 double tan_ay = std::tan(deg2rad(ay)); | 88 double tan_ay = std::tan(deg2rad(ay)); |
94 | 89 |
95 DOMMatrixInit init; | 90 DOMMatrix* matrix = DOMMatrix::Create(); |
96 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
97 | 91 |
98 matrix->setM12(tan_ay); | 92 matrix->setM12(tan_ay); |
99 matrix->setM21(tan_ax); | 93 matrix->setM21(tan_ax); |
100 return new CSSMatrixComponent(matrix, kSkewType); | 94 return new CSSMatrixComponent(matrix, kSkewType); |
101 } | 95 } |
102 | 96 |
103 CSSMatrixComponent* CSSMatrixComponent::Translate(double x, double y) { | 97 CSSMatrixComponent* CSSMatrixComponent::Translate(double x, double y) { |
104 DOMMatrixInit init; | 98 DOMMatrix* matrix = DOMMatrix::Create(); |
105 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
106 | 99 |
107 matrix->setM41(x); | 100 matrix->setM41(x); |
108 matrix->setM42(y); | 101 matrix->setM42(y); |
109 return new CSSMatrixComponent(matrix, kTranslationType); | 102 return new CSSMatrixComponent(matrix, kTranslationType); |
110 } | 103 } |
111 | 104 |
112 CSSMatrixComponent* CSSMatrixComponent::Translate3d(double x, | 105 CSSMatrixComponent* CSSMatrixComponent::Translate3d(double x, |
113 double y, | 106 double y, |
114 double z) { | 107 double z) { |
115 DOMMatrixInit init; | 108 DOMMatrix* matrix = DOMMatrix::Create(); |
116 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
117 | 109 |
118 matrix->setM41(x); | 110 matrix->setM41(x); |
119 matrix->setM42(y); | 111 matrix->setM42(y); |
120 matrix->setM43(z); | 112 matrix->setM43(z); |
121 return new CSSMatrixComponent(matrix, kTranslation3DType); | 113 return new CSSMatrixComponent(matrix, kTranslation3DType); |
122 } | 114 } |
123 | 115 |
124 CSSMatrixComponent::CSSMatrixComponent(DOMMatrixReadOnly* matrix) | 116 CSSMatrixComponent::CSSMatrixComponent(DOMMatrixReadOnly* matrix) |
125 : CSSTransformComponent() { | 117 : CSSTransformComponent() { |
126 matrix_ = DOMMatrix::Create(matrix); | 118 matrix_ = DOMMatrix::Create(matrix); |
127 is2d_ = matrix->is2D(); | 119 is2d_ = matrix->is2D(); |
128 } | 120 } |
129 | 121 |
130 CSSMatrixComponent::CSSMatrixComponent(DOMMatrixReadOnly* matrix, | 122 CSSMatrixComponent::CSSMatrixComponent(DOMMatrixReadOnly* matrix, |
131 TransformComponentType from_type) | 123 TransformComponentType from_type) |
132 : CSSTransformComponent() { | 124 : CSSTransformComponent() { |
133 matrix_ = DOMMatrix::Create(matrix); | 125 matrix_ = DOMMatrix::Create(matrix); |
134 is2d_ = Is2DComponentType(from_type); | 126 is2d_ = Is2DComponentType(from_type); |
135 } | 127 } |
136 | 128 |
137 } // namespace blink | 129 } // namespace blink |
OLD | NEW |