| 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 #ifndef CSSMatrixComponent_h | 5 #ifndef CSSMatrixComponent_h |
| 6 #define CSSMatrixComponent_h | 6 #define CSSMatrixComponent_h |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include "core/css/cssom/CSSTransformComponent.h" | 9 #include "core/css/cssom/CSSTransformComponent.h" |
| 10 #include "core/geometry/DOMMatrix.h" |
| 10 #include "platform/transforms/TransformationMatrix.h" | 11 #include "platform/transforms/TransformationMatrix.h" |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 15 class DOMMatrixReadOnly; |
| 16 |
| 14 class CORE_EXPORT CSSMatrixComponent final : public CSSTransformComponent { | 17 class CORE_EXPORT CSSMatrixComponent final : public CSSTransformComponent { |
| 15 WTF_MAKE_NONCOPYABLE(CSSMatrixComponent); | 18 WTF_MAKE_NONCOPYABLE(CSSMatrixComponent); |
| 16 DEFINE_WRAPPERTYPEINFO(); | 19 DEFINE_WRAPPERTYPEINFO(); |
| 17 | 20 |
| 18 public: | 21 public: |
| 19 static CSSMatrixComponent* Create(double a, | 22 static CSSMatrixComponent* Create(DOMMatrixReadOnly*); |
| 20 double b, | |
| 21 double c, | |
| 22 double d, | |
| 23 double e, | |
| 24 double f) { | |
| 25 return new CSSMatrixComponent(a, b, c, d, e, f); | |
| 26 } | |
| 27 | |
| 28 static CSSMatrixComponent* Create(double m11, | |
| 29 double m12, | |
| 30 double m13, | |
| 31 double m14, | |
| 32 double m21, | |
| 33 double m22, | |
| 34 double m23, | |
| 35 double m24, | |
| 36 double m31, | |
| 37 double m32, | |
| 38 double m33, | |
| 39 double m34, | |
| 40 double m41, | |
| 41 double m42, | |
| 42 double m43, | |
| 43 double m44) { | |
| 44 return new CSSMatrixComponent(m11, m12, m13, m14, m21, m22, m23, m24, m31, | |
| 45 m32, m33, m34, m41, m42, m43, m44); | |
| 46 } | |
| 47 | 23 |
| 48 static CSSMatrixComponent* FromCSSValue(const CSSFunctionValue& value) { | 24 static CSSMatrixComponent* FromCSSValue(const CSSFunctionValue& value) { |
| 49 return nullptr; | 25 return nullptr; |
| 50 } | 26 } |
| 51 | 27 |
| 52 // 2D matrix attributes | 28 DOMMatrix* matrix() const { return matrix_; } |
| 53 double a() const { return matrix_->A(); } | |
| 54 double b() const { return matrix_->B(); } | |
| 55 double c() const { return matrix_->C(); } | |
| 56 double d() const { return matrix_->D(); } | |
| 57 double e() const { return matrix_->E(); } | |
| 58 double f() const { return matrix_->F(); } | |
| 59 | 29 |
| 60 // 3D matrix attributes | 30 void setMatrix(DOMMatrix* matrix) { matrix_ = matrix; } |
| 61 double m11() const { return matrix_->M11(); } | |
| 62 double m12() const { return matrix_->M12(); } | |
| 63 double m13() const { return matrix_->M13(); } | |
| 64 double m14() const { return matrix_->M14(); } | |
| 65 double m21() const { return matrix_->M21(); } | |
| 66 double m22() const { return matrix_->M22(); } | |
| 67 double m23() const { return matrix_->M23(); } | |
| 68 double m24() const { return matrix_->M24(); } | |
| 69 double m31() const { return matrix_->M31(); } | |
| 70 double m32() const { return matrix_->M32(); } | |
| 71 double m33() const { return matrix_->M33(); } | |
| 72 double m34() const { return matrix_->M34(); } | |
| 73 double m41() const { return matrix_->M41(); } | |
| 74 double m42() const { return matrix_->M42(); } | |
| 75 double m43() const { return matrix_->M43(); } | |
| 76 double m44() const { return matrix_->M44(); } | |
| 77 | 31 |
| 78 TransformComponentType GetType() const override { | 32 TransformComponentType GetType() const override { |
| 79 return is2d_ ? kMatrixType : kMatrix3DType; | 33 return is2d_ ? kMatrixType : kMatrix3DType; |
| 80 } | 34 } |
| 81 | 35 |
| 82 // Bindings require a non const return value. | 36 // Bindings require a non const return value. |
| 83 CSSMatrixComponent* asMatrix() const override { | 37 CSSMatrixComponent* asMatrix() const override { |
| 84 return const_cast<CSSMatrixComponent*>(this); | 38 return const_cast<CSSMatrixComponent*>(this); |
| 85 } | 39 } |
| 86 | 40 |
| 87 CSSFunctionValue* ToCSSValue() const override; | 41 CSSFunctionValue* ToCSSValue() const override; |
| 88 | 42 |
| 89 static CSSMatrixComponent* Perspective(double length); | 43 static CSSMatrixComponent* Perspective(double length); |
| 90 | 44 |
| 91 static CSSMatrixComponent* Rotate(double angle); | 45 static CSSMatrixComponent* Rotate(double angle); |
| 92 static CSSMatrixComponent* Rotate3d(double angle, | 46 static CSSMatrixComponent* Rotate3d(double angle, |
| 93 double x, | 47 double x, |
| 94 double y, | 48 double y, |
| 95 double z); | 49 double z); |
| 96 | 50 |
| 97 static CSSMatrixComponent* Scale(double x, double y); | 51 static CSSMatrixComponent* Scale(double x, double y); |
| 98 static CSSMatrixComponent* Scale3d(double x, double y, double z); | 52 static CSSMatrixComponent* Scale3d(double x, double y, double z); |
| 99 | 53 |
| 100 static CSSMatrixComponent* Skew(double x, double y); | 54 static CSSMatrixComponent* Skew(double x, double y); |
| 101 | 55 |
| 102 static CSSMatrixComponent* Translate(double x, double y); | 56 static CSSMatrixComponent* Translate(double x, double y); |
| 103 static CSSMatrixComponent* Translate3d(double x, double y, double z); | 57 static CSSMatrixComponent* Translate3d(double x, double y, double z); |
| 104 | 58 |
| 59 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 60 visitor->Trace(matrix_); |
| 61 CSSTransformComponent::Trace(visitor); |
| 62 } |
| 63 |
| 105 private: | 64 private: |
| 106 CSSMatrixComponent(double a, double b, double c, double d, double e, double f) | 65 CSSMatrixComponent(DOMMatrixReadOnly*); |
| 107 : CSSTransformComponent(), | 66 CSSMatrixComponent(DOMMatrixReadOnly*, TransformComponentType); |
| 108 matrix_(TransformationMatrix::Create(a, b, c, d, e, f)), | |
| 109 is2d_(true) {} | |
| 110 | 67 |
| 111 CSSMatrixComponent(double m11, | 68 Member<DOMMatrix> matrix_; |
| 112 double m12, | |
| 113 double m13, | |
| 114 double m14, | |
| 115 double m21, | |
| 116 double m22, | |
| 117 double m23, | |
| 118 double m24, | |
| 119 double m31, | |
| 120 double m32, | |
| 121 double m33, | |
| 122 double m34, | |
| 123 double m41, | |
| 124 double m42, | |
| 125 double m43, | |
| 126 double m44) | |
| 127 : CSSTransformComponent(), | |
| 128 matrix_(TransformationMatrix::Create(m11, | |
| 129 m12, | |
| 130 m13, | |
| 131 m14, | |
| 132 m21, | |
| 133 m22, | |
| 134 m23, | |
| 135 m24, | |
| 136 m31, | |
| 137 m32, | |
| 138 m33, | |
| 139 m34, | |
| 140 m41, | |
| 141 m42, | |
| 142 m43, | |
| 143 m44)), | |
| 144 is2d_(false) {} | |
| 145 | |
| 146 CSSMatrixComponent(std::unique_ptr<const TransformationMatrix> matrix, | |
| 147 TransformComponentType from_type) | |
| 148 : CSSTransformComponent(), | |
| 149 matrix_(std::move(matrix)), | |
| 150 is2d_(Is2DComponentType(from_type)) {} | |
| 151 | |
| 152 // TransformationMatrix needs to be 16-byte aligned. PartitionAlloc | |
| 153 // supports 16-byte alignment but Oilpan doesn't. So we use an std::unique_ptr | |
| 154 // to allocate TransformationMatrix on PartitionAlloc. | |
| 155 // TODO(oilpan): Oilpan should support 16-byte aligned allocations. | |
| 156 std::unique_ptr<const TransformationMatrix> matrix_; | |
| 157 bool is2d_; | 69 bool is2d_; |
| 158 }; | 70 }; |
| 159 | 71 |
| 160 } // namespace blink | 72 } // namespace blink |
| 161 | 73 |
| 162 #endif | 74 #endif |
| OLD | NEW |