Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/CSSMatrixComponent.cpp

Issue 2888403004: [css-typed-om] replace all attribute with DOMMatrix in cssMatrixComponent (Closed)
Patch Set: fix the typo Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 CSSMatrixComponent* CSSMatrixComponent::Create(DOMMatrixReadOnly* matrix) {
15 return new CSSMatrixComponent(matrix);
16 }
17
14 CSSFunctionValue* CSSMatrixComponent::ToCSSValue() const { 18 CSSFunctionValue* CSSMatrixComponent::ToCSSValue() const {
15 CSSFunctionValue* result = 19 CSSFunctionValue* result =
16 CSSFunctionValue::Create(is2d_ ? CSSValueMatrix : CSSValueMatrix3d); 20 CSSFunctionValue::Create(is2d_ ? CSSValueMatrix : CSSValueMatrix3d);
17 21
18 if (is2d_) { 22 if (is2d_) {
19 double values[6] = {a(), b(), c(), d(), e(), f()}; 23 double values[6] = {matrix()->a(), matrix()->b(), matrix()->c(),
24 matrix()->d(), matrix()->e(), matrix()->f()};
20 for (double value : values) { 25 for (double value : values) {
21 result->Append(*CSSPrimitiveValue::Create( 26 result->Append(*CSSPrimitiveValue::Create(
22 value, CSSPrimitiveValue::UnitType::kNumber)); 27 value, CSSPrimitiveValue::UnitType::kNumber));
23 } 28 }
24 } else { 29 } else {
25 double values[16] = {m11(), m12(), m13(), m14(), m21(), m22(), 30 double values[16] = {
26 m23(), m24(), m31(), m32(), m33(), m34(), 31 matrix()->m11(), matrix()->m12(), matrix()->m13(), matrix()->m14(),
27 m41(), m42(), m43(), m44()}; 32 matrix()->m21(), matrix()->m22(), matrix()->m23(), matrix()->m24(),
33 matrix()->m31(), matrix()->m32(), matrix()->m33(), matrix()->m34(),
34 matrix()->m41(), matrix()->m42(), matrix()->m43(), matrix()->m44()};
28 for (double value : values) { 35 for (double value : values) {
29 result->Append(*CSSPrimitiveValue::Create( 36 result->Append(*CSSPrimitiveValue::Create(
30 value, CSSPrimitiveValue::UnitType::kNumber)); 37 value, CSSPrimitiveValue::UnitType::kNumber));
31 } 38 }
32 } 39 }
33 40
34 return result; 41 return result;
35 } 42 }
36 43
37 CSSMatrixComponent* CSSMatrixComponent::Perspective(double length) { 44 CSSMatrixComponent* CSSMatrixComponent::Perspective(double length) {
38 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 45 DOMMatrixInit init;
46 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
47
39 if (length != 0) 48 if (length != 0)
40 matrix->SetM34(-1 / length); 49 matrix->setM34(-1 / length);
41 return new CSSMatrixComponent(std::move(matrix), kPerspectiveType); 50 return new CSSMatrixComponent(matrix, kPerspectiveType);
42 } 51 }
43 52
44 CSSMatrixComponent* CSSMatrixComponent::Rotate(double angle) { 53 CSSMatrixComponent* CSSMatrixComponent::Rotate(double angle) {
45 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 54 DOMMatrixInit init;
46 matrix->Rotate(angle); 55 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
47 return new CSSMatrixComponent(std::move(matrix), kRotationType); 56
57 matrix->rotateSelf(angle);
58 return new CSSMatrixComponent(matrix, kRotationType);
48 } 59 }
49 60
50 CSSMatrixComponent* CSSMatrixComponent::Rotate3d(double angle, 61 CSSMatrixComponent* CSSMatrixComponent::Rotate3d(double angle,
51 double x, 62 double x,
52 double y, 63 double y,
53 double z) { 64 double z) {
54 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 65 DOMMatrixInit init;
55 matrix->Rotate3d(x, y, z, angle); 66 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
56 return new CSSMatrixComponent(std::move(matrix), kRotation3DType); 67
68 matrix->rotateAxisAngleSelf(x, y, z, angle);
69 return new CSSMatrixComponent(matrix, kRotation3DType);
57 } 70 }
58 71
59 CSSMatrixComponent* CSSMatrixComponent::Scale(double x, double y) { 72 CSSMatrixComponent* CSSMatrixComponent::Scale(double x, double y) {
60 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 73 DOMMatrixInit init;
61 matrix->SetM11(x); 74 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
62 matrix->SetM22(y); 75
63 return new CSSMatrixComponent(std::move(matrix), kScaleType); 76 matrix->setM11(x);
77 matrix->setM22(y);
78 return new CSSMatrixComponent(matrix, kScaleType);
64 } 79 }
65 80
66 CSSMatrixComponent* CSSMatrixComponent::Scale3d(double x, double y, double z) { 81 CSSMatrixComponent* CSSMatrixComponent::Scale3d(double x, double y, double z) {
67 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 82 DOMMatrixInit init;
68 matrix->SetM11(x); 83 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
69 matrix->SetM22(y); 84
70 matrix->SetM33(z); 85 matrix->setM11(x);
71 return new CSSMatrixComponent(std::move(matrix), kScale3DType); 86 matrix->setM22(y);
87 matrix->setM33(z);
88 return new CSSMatrixComponent(matrix, kScale3DType);
72 } 89 }
73 90
74 CSSMatrixComponent* CSSMatrixComponent::Skew(double ax, double ay) { 91 CSSMatrixComponent* CSSMatrixComponent::Skew(double ax, double ay) {
75 double tan_ax = std::tan(deg2rad(ax)); 92 double tan_ax = std::tan(deg2rad(ax));
76 double tan_ay = std::tan(deg2rad(ay)); 93 double tan_ay = std::tan(deg2rad(ay));
77 94
78 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 95 DOMMatrixInit init;
79 matrix->SetM12(tan_ay); 96 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
80 matrix->SetM21(tan_ax); 97
81 return new CSSMatrixComponent(std::move(matrix), kSkewType); 98 matrix->setM12(tan_ay);
99 matrix->setM21(tan_ax);
100 return new CSSMatrixComponent(matrix, kSkewType);
82 } 101 }
83 102
84 CSSMatrixComponent* CSSMatrixComponent::Translate(double x, double y) { 103 CSSMatrixComponent* CSSMatrixComponent::Translate(double x, double y) {
85 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 104 DOMMatrixInit init;
86 matrix->SetM41(x); 105 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
87 matrix->SetM42(y); 106
88 return new CSSMatrixComponent(std::move(matrix), kTranslationType); 107 matrix->setM41(x);
108 matrix->setM42(y);
109 return new CSSMatrixComponent(matrix, kTranslationType);
89 } 110 }
90 111
91 CSSMatrixComponent* CSSMatrixComponent::Translate3d(double x, 112 CSSMatrixComponent* CSSMatrixComponent::Translate3d(double x,
92 double y, 113 double y,
93 double z) { 114 double z) {
94 std::unique_ptr<TransformationMatrix> matrix = TransformationMatrix::Create(); 115 DOMMatrixInit init;
95 matrix->SetM41(x); 116 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION);
96 matrix->SetM42(y); 117
97 matrix->SetM43(z); 118 matrix->setM41(x);
98 return new CSSMatrixComponent(std::move(matrix), kTranslation3DType); 119 matrix->setM42(y);
120 matrix->setM43(z);
121 return new CSSMatrixComponent(matrix, kTranslation3DType);
122 }
123
124 CSSMatrixComponent::CSSMatrixComponent(DOMMatrixReadOnly* matrix)
125 : CSSTransformComponent() {
126 matrix_ = DOMMatrix::Create(matrix);
127 is2d_ = matrix->is2D();
128 }
129
130 CSSMatrixComponent::CSSMatrixComponent(DOMMatrixReadOnly* matrix,
131 TransformComponentType from_type)
132 : CSSTransformComponent() {
133 matrix_ = DOMMatrix::Create(matrix);
134 is2d_ = Is2DComponentType(from_type);
99 } 135 }
100 136
101 } // namespace blink 137 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698