1 | /*
|
---|
2 | * Copyright (C) 2017 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. AND ITS CONTRIBUTORS ``AS IS''
|
---|
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
---|
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
---|
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
---|
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
---|
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
---|
23 | * THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #pragma once
|
---|
27 |
|
---|
28 | #include "DOMMatrixReadOnly.h"
|
---|
29 |
|
---|
30 | namespace WebCore {
|
---|
31 |
|
---|
32 | class ScriptExecutionContext;
|
---|
33 |
|
---|
34 | class DOMMatrix : public DOMMatrixReadOnly {
|
---|
35 | public:
|
---|
36 | static ExceptionOr<Ref<DOMMatrix>> create(ScriptExecutionContext&, std::optional<std::variant<String, Vector<double>>>&&);
|
---|
37 |
|
---|
38 | static Ref<DOMMatrix> create(const TransformationMatrix& matrix, Is2D is2D)
|
---|
39 | {
|
---|
40 | return adoptRef(*new DOMMatrix(matrix, is2D));
|
---|
41 | }
|
---|
42 |
|
---|
43 | static Ref<DOMMatrix> create(TransformationMatrix&& matrix, Is2D is2D)
|
---|
44 | {
|
---|
45 | return adoptRef(*new DOMMatrix(WTFMove(matrix), is2D));
|
---|
46 | }
|
---|
47 |
|
---|
48 | static ExceptionOr<Ref<DOMMatrix>> fromMatrix(DOMMatrixInit&&);
|
---|
49 |
|
---|
50 | static ExceptionOr<Ref<DOMMatrix>> fromFloat32Array(Ref<Float32Array>&&);
|
---|
51 | static ExceptionOr<Ref<DOMMatrix>> fromFloat64Array(Ref<Float64Array>&&);
|
---|
52 |
|
---|
53 | ExceptionOr<Ref<DOMMatrix>> multiplySelf(DOMMatrixInit&& other);
|
---|
54 | ExceptionOr<Ref<DOMMatrix>> preMultiplySelf(DOMMatrixInit&& other);
|
---|
55 | Ref<DOMMatrix> translateSelf(double tx = 0, double ty = 0, double tz = 0);
|
---|
56 | Ref<DOMMatrix> scaleSelf(double scaleX = 1, std::optional<double> scaleY = std::nullopt, double scaleZ = 1, double originX = 0, double originY = 0, double originZ = 0);
|
---|
57 | Ref<DOMMatrix> scale3dSelf(double scale = 1, double originX = 0, double originY = 0, double originZ = 0);
|
---|
58 | Ref<DOMMatrix> rotateSelf(double rotX = 0, std::optional<double> rotY = std::nullopt, std::optional<double> rotZ = std::nullopt); // Angles are in degrees.
|
---|
59 | Ref<DOMMatrix> rotateFromVectorSelf(double x = 0, double y = 0);
|
---|
60 | Ref<DOMMatrix> rotateAxisAngleSelf(double x = 0, double y = 0, double z = 0, double angle = 0); // Angle is in degrees.
|
---|
61 | Ref<DOMMatrix> skewXSelf(double sx = 0); // Angle is in degrees.
|
---|
62 | Ref<DOMMatrix> skewYSelf(double sy = 0); // Angle is in degrees.
|
---|
63 | Ref<DOMMatrix> invertSelf();
|
---|
64 |
|
---|
65 | ExceptionOr<Ref<DOMMatrix>> setMatrixValueForBindings(const String&);
|
---|
66 |
|
---|
67 | void setA(double f) { m_matrix.setA(f); }
|
---|
68 | void setB(double f) { m_matrix.setB(f); }
|
---|
69 | void setC(double f) { m_matrix.setC(f); }
|
---|
70 | void setD(double f) { m_matrix.setD(f); }
|
---|
71 | void setE(double f) { m_matrix.setE(f); }
|
---|
72 | void setF(double f) { m_matrix.setF(f); }
|
---|
73 |
|
---|
74 | void setM11(double f) { m_matrix.setM11(f); }
|
---|
75 | void setM12(double f) { m_matrix.setM12(f); }
|
---|
76 | void setM13(double f);
|
---|
77 | void setM14(double f);
|
---|
78 | void setM21(double f) { m_matrix.setM21(f); }
|
---|
79 | void setM22(double f) { m_matrix.setM22(f); }
|
---|
80 | void setM23(double f);
|
---|
81 | void setM24(double f);
|
---|
82 | void setM31(double f);
|
---|
83 | void setM32(double f);
|
---|
84 | void setM33(double f);
|
---|
85 | void setM34(double f);
|
---|
86 | void setM41(double f) { m_matrix.setM41(f); }
|
---|
87 | void setM42(double f) { m_matrix.setM42(f); }
|
---|
88 | void setM43(double f);
|
---|
89 | void setM44(double f);
|
---|
90 |
|
---|
91 | private:
|
---|
92 | DOMMatrix() = default;
|
---|
93 | DOMMatrix(const TransformationMatrix&, Is2D);
|
---|
94 | DOMMatrix(TransformationMatrix&&, Is2D);
|
---|
95 | };
|
---|
96 | static_assert(sizeof(DOMMatrix) == sizeof(DOMMatrixReadOnly));
|
---|
97 |
|
---|
98 | inline void DOMMatrix::setM13(double f)
|
---|
99 | {
|
---|
100 | m_matrix.setM13(f);
|
---|
101 | if (f)
|
---|
102 | m_is2D = false;
|
---|
103 | }
|
---|
104 |
|
---|
105 | inline void DOMMatrix::setM14(double f)
|
---|
106 | {
|
---|
107 | m_matrix.setM14(f);
|
---|
108 | if (f)
|
---|
109 | m_is2D = false;
|
---|
110 | }
|
---|
111 |
|
---|
112 | inline void DOMMatrix::setM23(double f)
|
---|
113 | {
|
---|
114 | m_matrix.setM23(f);
|
---|
115 | if (f)
|
---|
116 | m_is2D = false;
|
---|
117 | }
|
---|
118 |
|
---|
119 | inline void DOMMatrix::setM24(double f)
|
---|
120 | {
|
---|
121 | m_matrix.setM24(f);
|
---|
122 | if (f)
|
---|
123 | m_is2D = false;
|
---|
124 | }
|
---|
125 |
|
---|
126 | inline void DOMMatrix::setM31(double f)
|
---|
127 | {
|
---|
128 | m_matrix.setM31(f);
|
---|
129 | if (f)
|
---|
130 | m_is2D = false;
|
---|
131 | }
|
---|
132 |
|
---|
133 | inline void DOMMatrix::setM32(double f)
|
---|
134 | {
|
---|
135 | m_matrix.setM32(f);
|
---|
136 | if (f)
|
---|
137 | m_is2D = false;
|
---|
138 | }
|
---|
139 |
|
---|
140 | inline void DOMMatrix::setM33(double f)
|
---|
141 | {
|
---|
142 | m_matrix.setM33(f);
|
---|
143 | if (f != 1)
|
---|
144 | m_is2D = false;
|
---|
145 | }
|
---|
146 |
|
---|
147 | inline void DOMMatrix::setM34(double f)
|
---|
148 | {
|
---|
149 | m_matrix.setM34(f);
|
---|
150 | if (f)
|
---|
151 | m_is2D = false;
|
---|
152 | }
|
---|
153 |
|
---|
154 | inline void DOMMatrix::setM43(double f)
|
---|
155 | {
|
---|
156 | m_matrix.setM43(f);
|
---|
157 | if (f)
|
---|
158 | m_is2D = false;
|
---|
159 | }
|
---|
160 |
|
---|
161 | inline void DOMMatrix::setM44(double f)
|
---|
162 | {
|
---|
163 | m_matrix.setM44(f);
|
---|
164 | if (f != 1)
|
---|
165 | m_is2D = false;
|
---|
166 | }
|
---|
167 |
|
---|
168 | } // namespace WebCore
|
---|