1 | /* |
2 | * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "ExceptionOr.h" |
29 | #include "ScriptWrappable.h" |
30 | #include "TransformationMatrix.h" |
31 | |
32 | namespace WebCore { |
33 | |
34 | // FIXME: Remove this class once WebKitCSSMatrix becomes an alias to DOMMatrix. |
35 | class WebKitCSSMatrix final : public ScriptWrappable, public RefCounted<WebKitCSSMatrix> { |
36 | WTF_MAKE_ISO_ALLOCATED(WebKitCSSMatrix); |
37 | public: |
38 | static Ref<WebKitCSSMatrix> create(const TransformationMatrix&); |
39 | static ExceptionOr<Ref<WebKitCSSMatrix>> create(const String&); |
40 | |
41 | ~WebKitCSSMatrix(); |
42 | |
43 | double a() const { return m_matrix.a(); } |
44 | double b() const { return m_matrix.b(); } |
45 | double c() const { return m_matrix.c(); } |
46 | double d() const { return m_matrix.d(); } |
47 | double e() const { return m_matrix.e(); } |
48 | double f() const { return m_matrix.f(); } |
49 | |
50 | void setA(double f) { m_matrix.setA(f); } |
51 | void setB(double f) { m_matrix.setB(f); } |
52 | void setC(double f) { m_matrix.setC(f); } |
53 | void setD(double f) { m_matrix.setD(f); } |
54 | void setE(double f) { m_matrix.setE(f); } |
55 | void setF(double f) { m_matrix.setF(f); } |
56 | |
57 | double m11() const { return m_matrix.m11(); } |
58 | double m12() const { return m_matrix.m12(); } |
59 | double m13() const { return m_matrix.m13(); } |
60 | double m14() const { return m_matrix.m14(); } |
61 | double m21() const { return m_matrix.m21(); } |
62 | double m22() const { return m_matrix.m22(); } |
63 | double m23() const { return m_matrix.m23(); } |
64 | double m24() const { return m_matrix.m24(); } |
65 | double m31() const { return m_matrix.m31(); } |
66 | double m32() const { return m_matrix.m32(); } |
67 | double m33() const { return m_matrix.m33(); } |
68 | double m34() const { return m_matrix.m34(); } |
69 | double m41() const { return m_matrix.m41(); } |
70 | double m42() const { return m_matrix.m42(); } |
71 | double m43() const { return m_matrix.m43(); } |
72 | double m44() const { return m_matrix.m44(); } |
73 | |
74 | void setM11(double f) { m_matrix.setM11(f); } |
75 | void setM12(double f) { m_matrix.setM12(f); } |
76 | void setM13(double f) { m_matrix.setM13(f); } |
77 | void setM14(double f) { m_matrix.setM14(f); } |
78 | void setM21(double f) { m_matrix.setM21(f); } |
79 | void setM22(double f) { m_matrix.setM22(f); } |
80 | void setM23(double f) { m_matrix.setM23(f); } |
81 | void setM24(double f) { m_matrix.setM24(f); } |
82 | void setM31(double f) { m_matrix.setM31(f); } |
83 | void setM32(double f) { m_matrix.setM32(f); } |
84 | void setM33(double f) { m_matrix.setM33(f); } |
85 | void setM34(double f) { m_matrix.setM34(f); } |
86 | void setM41(double f) { m_matrix.setM41(f); } |
87 | void setM42(double f) { m_matrix.setM42(f); } |
88 | void setM43(double f) { m_matrix.setM43(f); } |
89 | void setM44(double f) { m_matrix.setM44(f); } |
90 | |
91 | ExceptionOr<void> setMatrixValue(const String&); |
92 | |
93 | // The following math function return a new matrix with the |
94 | // specified operation applied. The this value is not modified. |
95 | |
96 | // Multiply this matrix by secondMatrix, on the right (result = this * secondMatrix) |
97 | RefPtr<WebKitCSSMatrix> multiply(WebKitCSSMatrix* secondMatrix) const; |
98 | |
99 | // Return the inverse of this matrix. Throw an exception if the matrix is not invertible |
100 | ExceptionOr<Ref<WebKitCSSMatrix>> inverse() const; |
101 | |
102 | // Return this matrix translated by the passed values. |
103 | // Passing a NaN will use a value of 0. This allows the 3D form to used for 2D operations |
104 | // Operation is performed as though the this matrix is multiplied by a matrix with |
105 | // the translation values on the left (result = translation(x,y,z) * this) |
106 | Ref<WebKitCSSMatrix> translate(double x, double y, double z) const; |
107 | |
108 | // Returns this matrix scaled by the passed values. |
109 | // Passing scaleX or scaleZ as NaN uses a value of 1, but passing scaleY of NaN |
110 | // makes it the same as scaleX. This allows the 3D form to used for 2D operations |
111 | // Operation is performed as though the this matrix is multiplied by a matrix with |
112 | // the scale values on the left (result = scale(x,y,z) * this) |
113 | Ref<WebKitCSSMatrix> scale(double scaleX, double scaleY, double scaleZ) const; |
114 | |
115 | // Returns this matrix rotated by the passed values. |
116 | // If rotY and rotZ are NaN, rotate about Z (rotX=0, rotateY=0, rotateZ=rotX). |
117 | // Otherwise use a rotation value of 0 for any passed NaN. |
118 | // Operation is performed as though the this matrix is multiplied by a matrix with |
119 | // the rotation values on the left (result = rotation(x,y,z) * this) |
120 | Ref<WebKitCSSMatrix> rotate(double rotX, double rotY, double rotZ) const; |
121 | |
122 | // Returns this matrix rotated about the passed axis by the passed angle. |
123 | // Passing a NaN will use a value of 0. If the axis is (0,0,0) use a value |
124 | // Operation is performed as though the this matrix is multiplied by a matrix with |
125 | // the rotation values on the left (result = rotation(x,y,z,angle) * this) |
126 | Ref<WebKitCSSMatrix> rotateAxisAngle(double x, double y, double z, double angle) const; |
127 | |
128 | // Return this matrix skewed along the X axis by the passed values. |
129 | // Passing a NaN will use a value of 0. |
130 | // Operation is performed as though the this matrix is multiplied by a matrix with |
131 | // the skew values on the left (result = skewX(angle) * this) |
132 | Ref<WebKitCSSMatrix> skewX(double angle) const; |
133 | |
134 | // Return this matrix skewed along the Y axis by the passed values. |
135 | // Passing a NaN will use a value of 0. |
136 | // Operation is performed as though the this matrix is multiplied by a matrix with |
137 | // the skew values on the left (result = skewY(angle) * this) |
138 | Ref<WebKitCSSMatrix> skewY(double angle) const; |
139 | |
140 | const TransformationMatrix& transform() const { return m_matrix; } |
141 | |
142 | ExceptionOr<String> toString() const; |
143 | |
144 | private: |
145 | WebKitCSSMatrix() = default; |
146 | WebKitCSSMatrix(const TransformationMatrix&); |
147 | |
148 | TransformationMatrix m_matrix; |
149 | }; |
150 | |
151 | } // namespace WebCore |
152 | |