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