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/CSSMatrixTransformComponent.h" | 5 #include "core/css/cssom/CSSMatrixComponent.h" |
6 | 6 |
| 7 #include <cmath> |
| 8 #include <memory> |
7 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
8 #include "wtf/MathExtras.h" | 10 #include "wtf/MathExtras.h" |
9 #include <cmath> | |
10 #include <memory> | |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 CSSFunctionValue* CSSMatrixTransformComponent::toCSSValue() const { | 14 CSSFunctionValue* CSSMatrixComponent::toCSSValue() const { |
15 CSSFunctionValue* result = | 15 CSSFunctionValue* result = |
16 CSSFunctionValue::create(m_is2D ? CSSValueMatrix : CSSValueMatrix3d); | 16 CSSFunctionValue::create(m_is2D ? CSSValueMatrix : CSSValueMatrix3d); |
17 | 17 |
18 if (m_is2D) { | 18 if (m_is2D) { |
19 double values[6] = {a(), b(), c(), d(), e(), f()}; | 19 double values[6] = {a(), b(), c(), d(), e(), f()}; |
20 for (double value : values) { | 20 for (double value : values) { |
21 result->append(*CSSPrimitiveValue::create( | 21 result->append(*CSSPrimitiveValue::create( |
22 value, CSSPrimitiveValue::UnitType::Number)); | 22 value, CSSPrimitiveValue::UnitType::Number)); |
23 } | 23 } |
24 } else { | 24 } else { |
25 double values[16] = {m11(), m12(), m13(), m14(), m21(), m22(), | 25 double values[16] = {m11(), m12(), m13(), m14(), m21(), m22(), |
26 m23(), m24(), m31(), m32(), m33(), m34(), | 26 m23(), m24(), m31(), m32(), m33(), m34(), |
27 m41(), m42(), m43(), m44()}; | 27 m41(), m42(), m43(), m44()}; |
28 for (double value : values) { | 28 for (double value : values) { |
29 result->append(*CSSPrimitiveValue::create( | 29 result->append(*CSSPrimitiveValue::create( |
30 value, CSSPrimitiveValue::UnitType::Number)); | 30 value, CSSPrimitiveValue::UnitType::Number)); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 return result; | 34 return result; |
35 } | 35 } |
36 | 36 |
37 CSSMatrixTransformComponent* CSSMatrixTransformComponent::perspective( | 37 CSSMatrixComponent* CSSMatrixComponent::perspective(double length) { |
38 double length) { | |
39 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 38 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
40 if (length != 0) | 39 if (length != 0) |
41 matrix->setM34(-1 / length); | 40 matrix->setM34(-1 / length); |
42 return new CSSMatrixTransformComponent(std::move(matrix), PerspectiveType); | 41 return new CSSMatrixComponent(std::move(matrix), PerspectiveType); |
43 } | 42 } |
44 | 43 |
45 CSSMatrixTransformComponent* CSSMatrixTransformComponent::rotate(double angle) { | 44 CSSMatrixComponent* CSSMatrixComponent::rotate(double angle) { |
46 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 45 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
47 matrix->rotate(angle); | 46 matrix->rotate(angle); |
48 return new CSSMatrixTransformComponent(std::move(matrix), RotationType); | 47 return new CSSMatrixComponent(std::move(matrix), RotationType); |
49 } | 48 } |
50 | 49 |
51 CSSMatrixTransformComponent* CSSMatrixTransformComponent::rotate3d(double angle, | 50 CSSMatrixComponent* CSSMatrixComponent::rotate3d(double angle, |
52 double x, | 51 double x, |
53 double y, | 52 double y, |
54 double z) { | 53 double z) { |
55 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 54 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
56 matrix->rotate3d(x, y, z, angle); | 55 matrix->rotate3d(x, y, z, angle); |
57 return new CSSMatrixTransformComponent(std::move(matrix), Rotation3DType); | 56 return new CSSMatrixComponent(std::move(matrix), Rotation3DType); |
58 } | 57 } |
59 | 58 |
60 CSSMatrixTransformComponent* CSSMatrixTransformComponent::scale(double x, | 59 CSSMatrixComponent* CSSMatrixComponent::scale(double x, double y) { |
61 double y) { | |
62 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 60 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
63 matrix->setM11(x); | 61 matrix->setM11(x); |
64 matrix->setM22(y); | 62 matrix->setM22(y); |
65 return new CSSMatrixTransformComponent(std::move(matrix), ScaleType); | 63 return new CSSMatrixComponent(std::move(matrix), ScaleType); |
66 } | 64 } |
67 | 65 |
68 CSSMatrixTransformComponent* CSSMatrixTransformComponent::scale3d(double x, | 66 CSSMatrixComponent* CSSMatrixComponent::scale3d(double x, double y, double z) { |
69 double y, | |
70 double z) { | |
71 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 67 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
72 matrix->setM11(x); | 68 matrix->setM11(x); |
73 matrix->setM22(y); | 69 matrix->setM22(y); |
74 matrix->setM33(z); | 70 matrix->setM33(z); |
75 return new CSSMatrixTransformComponent(std::move(matrix), Scale3DType); | 71 return new CSSMatrixComponent(std::move(matrix), Scale3DType); |
76 } | 72 } |
77 | 73 |
78 CSSMatrixTransformComponent* CSSMatrixTransformComponent::skew(double ax, | 74 CSSMatrixComponent* CSSMatrixComponent::skew(double ax, double ay) { |
79 double ay) { | |
80 double tanAx = std::tan(deg2rad(ax)); | 75 double tanAx = std::tan(deg2rad(ax)); |
81 double tanAy = std::tan(deg2rad(ay)); | 76 double tanAy = std::tan(deg2rad(ay)); |
82 | 77 |
83 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 78 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
84 matrix->setM12(tanAy); | 79 matrix->setM12(tanAy); |
85 matrix->setM21(tanAx); | 80 matrix->setM21(tanAx); |
86 return new CSSMatrixTransformComponent(std::move(matrix), SkewType); | 81 return new CSSMatrixComponent(std::move(matrix), SkewType); |
87 } | 82 } |
88 | 83 |
89 CSSMatrixTransformComponent* CSSMatrixTransformComponent::translate(double x, | 84 CSSMatrixComponent* CSSMatrixComponent::translate(double x, double y) { |
90 double y) { | |
91 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 85 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
92 matrix->setM41(x); | 86 matrix->setM41(x); |
93 matrix->setM42(y); | 87 matrix->setM42(y); |
94 return new CSSMatrixTransformComponent(std::move(matrix), TranslationType); | 88 return new CSSMatrixComponent(std::move(matrix), TranslationType); |
95 } | 89 } |
96 | 90 |
97 CSSMatrixTransformComponent* | 91 CSSMatrixComponent* CSSMatrixComponent::translate3d(double x, |
98 CSSMatrixTransformComponent::translate3d(double x, double y, double z) { | 92 double y, |
| 93 double z) { |
99 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); | 94 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::create(); |
100 matrix->setM41(x); | 95 matrix->setM41(x); |
101 matrix->setM42(y); | 96 matrix->setM42(y); |
102 matrix->setM43(z); | 97 matrix->setM43(z); |
103 return new CSSMatrixTransformComponent(std::move(matrix), Translation3DType); | 98 return new CSSMatrixComponent(std::move(matrix), Translation3DType); |
104 } | 99 } |
105 | 100 |
106 } // namespace blink | 101 } // namespace blink |
OLD | NEW |