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 "core/css/CSSPrimitiveValue.h" | 7 #include "core/css/CSSPrimitiveValue.h" |
| 8 #include "core/css/cssom/CSSMatrixComponentOptions.h" |
| 9 #include "core/geometry/DOMMatrix.h" |
8 #include "platform/wtf/MathExtras.h" | 10 #include "platform/wtf/MathExtras.h" |
9 | 11 |
10 namespace blink { | 12 namespace blink { |
11 | 13 |
12 CSSMatrixComponent* CSSMatrixComponent::Create(DOMMatrixReadOnly* matrix) { | 14 namespace { |
13 return new CSSMatrixComponent(matrix); | 15 |
| 16 DOMMatrix* To2DMatrix(DOMMatrixReadOnly* matrix) { |
| 17 DOMMatrix* twoDimensionalMatrix = DOMMatrix::Create(); |
| 18 twoDimensionalMatrix->setA(matrix->m11()); |
| 19 twoDimensionalMatrix->setB(matrix->m12()); |
| 20 twoDimensionalMatrix->setC(matrix->m21()); |
| 21 twoDimensionalMatrix->setD(matrix->m22()); |
| 22 twoDimensionalMatrix->setE(matrix->m41()); |
| 23 twoDimensionalMatrix->setF(matrix->m42()); |
| 24 return twoDimensionalMatrix; |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 29 CSSMatrixComponent* CSSMatrixComponent::Create( |
| 30 DOMMatrixReadOnly* matrix, |
| 31 const CSSMatrixComponentOptions& options) { |
| 32 return new CSSMatrixComponent(matrix, options.is2D() || matrix->is2D()); |
| 33 } |
| 34 |
| 35 DOMMatrix* CSSMatrixComponent::AsMatrix() const { |
| 36 if (is2D() && !matrix_->is2D()) |
| 37 return To2DMatrix(matrix_); |
| 38 |
| 39 return matrix_.Get(); |
14 } | 40 } |
15 | 41 |
16 CSSFunctionValue* CSSMatrixComponent::ToCSSValue() const { | 42 CSSFunctionValue* CSSMatrixComponent::ToCSSValue() const { |
17 CSSFunctionValue* result = | 43 CSSFunctionValue* result = |
18 CSSFunctionValue::Create(is2d_ ? CSSValueMatrix : CSSValueMatrix3d); | 44 CSSFunctionValue::Create(is2D() ? CSSValueMatrix : CSSValueMatrix3d); |
19 | 45 |
20 if (is2d_) { | 46 if (is2D()) { |
21 double values[6] = {matrix()->a(), matrix()->b(), matrix()->c(), | 47 double values[6] = {matrix_->a(), matrix_->b(), matrix_->c(), |
22 matrix()->d(), matrix()->e(), matrix()->f()}; | 48 matrix_->d(), matrix_->e(), matrix_->f()}; |
23 for (double value : values) { | 49 for (double value : values) { |
24 result->Append(*CSSPrimitiveValue::Create( | 50 result->Append(*CSSPrimitiveValue::Create( |
25 value, CSSPrimitiveValue::UnitType::kNumber)); | 51 value, CSSPrimitiveValue::UnitType::kNumber)); |
26 } | 52 } |
27 } else { | 53 } else { |
28 double values[16] = { | 54 double values[16] = { |
29 matrix()->m11(), matrix()->m12(), matrix()->m13(), matrix()->m14(), | 55 matrix_->m11(), matrix_->m12(), matrix_->m13(), matrix_->m14(), |
30 matrix()->m21(), matrix()->m22(), matrix()->m23(), matrix()->m24(), | 56 matrix_->m21(), matrix_->m22(), matrix_->m23(), matrix_->m24(), |
31 matrix()->m31(), matrix()->m32(), matrix()->m33(), matrix()->m34(), | 57 matrix_->m31(), matrix_->m32(), matrix_->m33(), matrix_->m34(), |
32 matrix()->m41(), matrix()->m42(), matrix()->m43(), matrix()->m44()}; | 58 matrix_->m41(), matrix_->m42(), matrix_->m43(), matrix_->m44()}; |
33 for (double value : values) { | 59 for (double value : values) { |
34 result->Append(*CSSPrimitiveValue::Create( | 60 result->Append(*CSSPrimitiveValue::Create( |
35 value, CSSPrimitiveValue::UnitType::kNumber)); | 61 value, CSSPrimitiveValue::UnitType::kNumber)); |
36 } | 62 } |
37 } | 63 } |
38 | 64 |
39 return result; | 65 return result; |
40 } | 66 } |
41 | 67 |
42 CSSMatrixComponent::CSSMatrixComponent(DOMMatrixReadOnly* matrix) | |
43 : CSSTransformComponent() { | |
44 matrix_ = DOMMatrix::Create(matrix); | |
45 is2d_ = matrix->is2D(); | |
46 } | |
47 | |
48 } // namespace blink | 68 } // namespace blink |
OLD | NEW |