OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "core/css/parser/CSSParser.h" | 33 #include "core/css/parser/CSSParser.h" |
34 #include "core/css/resolver/TransformBuilder.h" | 34 #include "core/css/resolver/TransformBuilder.h" |
35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
36 #include "core/frame/UseCounter.h" | 36 #include "core/frame/UseCounter.h" |
37 #include "core/style/ComputedStyle.h" | 37 #include "core/style/ComputedStyle.h" |
38 #include "core/style/StyleInheritedData.h" | 38 #include "core/style/StyleInheritedData.h" |
39 #include "wtf/MathExtras.h" | 39 #include "wtf/MathExtras.h" |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 RawPtr<CSSMatrix> CSSMatrix::create(ExecutionContext* executionContext, const St
ring& s, ExceptionState& exceptionState) | 43 CSSMatrix* CSSMatrix::create(ExecutionContext* executionContext, const String& s
, ExceptionState& exceptionState) |
44 { | 44 { |
45 UseCounter::count(executionContext, UseCounter::WebKitCSSMatrix); | 45 UseCounter::count(executionContext, UseCounter::WebKitCSSMatrix); |
46 return new CSSMatrix(s, exceptionState); | 46 return new CSSMatrix(s, exceptionState); |
47 } | 47 } |
48 | 48 |
49 CSSMatrix::CSSMatrix(const TransformationMatrix& m) | 49 CSSMatrix::CSSMatrix(const TransformationMatrix& m) |
50 : m_matrix(TransformationMatrix::create(m)) | 50 : m_matrix(TransformationMatrix::create(m)) |
51 { | 51 { |
52 } | 52 } |
53 | 53 |
54 CSSMatrix::CSSMatrix(const String& s, ExceptionState& exceptionState) | 54 CSSMatrix::CSSMatrix(const String& s, ExceptionState& exceptionState) |
55 : m_matrix(TransformationMatrix::create()) | 55 : m_matrix(TransformationMatrix::create()) |
56 { | 56 { |
57 setMatrixValue(s, exceptionState); | 57 setMatrixValue(s, exceptionState); |
58 } | 58 } |
59 | 59 |
60 static inline PassRefPtr<ComputedStyle> createInitialStyle() | 60 static inline PassRefPtr<ComputedStyle> createInitialStyle() |
61 { | 61 { |
62 RefPtr<ComputedStyle> initialStyle = ComputedStyle::create(); | 62 RefPtr<ComputedStyle> initialStyle = ComputedStyle::create(); |
63 initialStyle->font().update(nullptr); | 63 initialStyle->font().update(nullptr); |
64 return initialStyle; | 64 return initialStyle; |
65 } | 65 } |
66 | 66 |
67 void CSSMatrix::setMatrixValue(const String& string, ExceptionState& exceptionSt
ate) | 67 void CSSMatrix::setMatrixValue(const String& string, ExceptionState& exceptionSt
ate) |
68 { | 68 { |
69 if (string.isEmpty()) | 69 if (string.isEmpty()) |
70 return; | 70 return; |
71 | 71 |
72 if (RawPtr<CSSValue> value = CSSParser::parseSingleValue(CSSPropertyTransfor
m, string)) { | 72 if (CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransform, stri
ng)) { |
73 // Check for a "none" transform. In these cases we can use the default i
dentity matrix. | 73 // Check for a "none" transform. In these cases we can use the default i
dentity matrix. |
74 if (value->isPrimitiveValue() && (toCSSPrimitiveValue(value.get()))->get
ValueID() == CSSValueNone) | 74 if (value->isPrimitiveValue() && (toCSSPrimitiveValue(value))->getValueI
D() == CSSValueNone) |
75 return; | 75 return; |
76 | 76 |
77 DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); | 77 DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); |
78 TransformOperations operations; | 78 TransformOperations operations; |
79 TransformBuilder::createTransformOperations(*value, CSSToLengthConversio
nData(initialStyle, initialStyle, nullptr, 1.0f), operations); | 79 TransformBuilder::createTransformOperations(*value, CSSToLengthConversio
nData(initialStyle, initialStyle, nullptr, 1.0f), operations); |
80 | 80 |
81 // Convert transform operations to a TransformationMatrix. This can fail | 81 // Convert transform operations to a TransformationMatrix. This can fail |
82 // if a param has a percentage ('%') | 82 // if a param has a percentage ('%') |
83 if (operations.dependsOnBoxSize()) | 83 if (operations.dependsOnBoxSize()) |
84 exceptionState.throwDOMException(SyntaxError, "The transformation de
pends on the box size, which is not supported."); | 84 exceptionState.throwDOMException(SyntaxError, "The transformation de
pends on the box size, which is not supported."); |
85 m_matrix = TransformationMatrix::create(); | 85 m_matrix = TransformationMatrix::create(); |
86 operations.apply(FloatSize(0, 0), *m_matrix); | 86 operations.apply(FloatSize(0, 0), *m_matrix); |
87 } else { // There is something there but parsing failed. | 87 } else { // There is something there but parsing failed. |
88 exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + stri
ng + "'."); | 88 exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + stri
ng + "'."); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 // Perform a concatenation of the matrices (this * secondMatrix) | 92 // Perform a concatenation of the matrices (this * secondMatrix) |
93 RawPtr<CSSMatrix> CSSMatrix::multiply(CSSMatrix* secondMatrix) const | 93 CSSMatrix* CSSMatrix::multiply(CSSMatrix* secondMatrix) const |
94 { | 94 { |
95 if (!secondMatrix) | 95 if (!secondMatrix) |
96 return nullptr; | 96 return nullptr; |
97 | 97 |
98 return CSSMatrix::create(TransformationMatrix(*m_matrix).multiply(*secondMat
rix->m_matrix)); | 98 return CSSMatrix::create(TransformationMatrix(*m_matrix).multiply(*secondMat
rix->m_matrix)); |
99 } | 99 } |
100 | 100 |
101 RawPtr<CSSMatrix> CSSMatrix::inverse(ExceptionState& exceptionState) const | 101 CSSMatrix* CSSMatrix::inverse(ExceptionState& exceptionState) const |
102 { | 102 { |
103 if (!m_matrix->isInvertible()) { | 103 if (!m_matrix->isInvertible()) { |
104 exceptionState.throwDOMException(NotSupportedError, "The matrix is not i
nvertable."); | 104 exceptionState.throwDOMException(NotSupportedError, "The matrix is not i
nvertable."); |
105 return nullptr; | 105 return nullptr; |
106 } | 106 } |
107 | 107 |
108 return CSSMatrix::create(m_matrix->inverse()); | 108 return CSSMatrix::create(m_matrix->inverse()); |
109 } | 109 } |
110 | 110 |
111 RawPtr<CSSMatrix> CSSMatrix::translate(double x, double y, double z) const | 111 CSSMatrix* CSSMatrix::translate(double x, double y, double z) const |
112 { | 112 { |
113 if (std::isnan(x)) | 113 if (std::isnan(x)) |
114 x = 0; | 114 x = 0; |
115 if (std::isnan(y)) | 115 if (std::isnan(y)) |
116 y = 0; | 116 y = 0; |
117 if (std::isnan(z)) | 117 if (std::isnan(z)) |
118 z = 0; | 118 z = 0; |
119 return CSSMatrix::create(TransformationMatrix(*m_matrix).translate3d(x, y, z
)); | 119 return CSSMatrix::create(TransformationMatrix(*m_matrix).translate3d(x, y, z
)); |
120 } | 120 } |
121 | 121 |
122 RawPtr<CSSMatrix> CSSMatrix::scale(double scaleX, double scaleY, double scaleZ)
const | 122 CSSMatrix* CSSMatrix::scale(double scaleX, double scaleY, double scaleZ) const |
123 { | 123 { |
124 if (std::isnan(scaleX)) | 124 if (std::isnan(scaleX)) |
125 scaleX = 1; | 125 scaleX = 1; |
126 if (std::isnan(scaleY)) | 126 if (std::isnan(scaleY)) |
127 scaleY = scaleX; | 127 scaleY = scaleX; |
128 if (std::isnan(scaleZ)) | 128 if (std::isnan(scaleZ)) |
129 scaleZ = 1; | 129 scaleZ = 1; |
130 return CSSMatrix::create(TransformationMatrix(*m_matrix).scale3d(scaleX, sca
leY, scaleZ)); | 130 return CSSMatrix::create(TransformationMatrix(*m_matrix).scale3d(scaleX, sca
leY, scaleZ)); |
131 } | 131 } |
132 | 132 |
133 RawPtr<CSSMatrix> CSSMatrix::rotate(double rotX, double rotY, double rotZ) const | 133 CSSMatrix* CSSMatrix::rotate(double rotX, double rotY, double rotZ) const |
134 { | 134 { |
135 if (std::isnan(rotX)) | 135 if (std::isnan(rotX)) |
136 rotX = 0; | 136 rotX = 0; |
137 | 137 |
138 if (std::isnan(rotY) && std::isnan(rotZ)) { | 138 if (std::isnan(rotY) && std::isnan(rotZ)) { |
139 rotZ = rotX; | 139 rotZ = rotX; |
140 rotX = 0; | 140 rotX = 0; |
141 rotY = 0; | 141 rotY = 0; |
142 } | 142 } |
143 | 143 |
144 if (std::isnan(rotY)) | 144 if (std::isnan(rotY)) |
145 rotY = 0; | 145 rotY = 0; |
146 if (std::isnan(rotZ)) | 146 if (std::isnan(rotZ)) |
147 rotZ = 0; | 147 rotZ = 0; |
148 return CSSMatrix::create(TransformationMatrix(*m_matrix).rotate3d(rotX, rotY
, rotZ)); | 148 return CSSMatrix::create(TransformationMatrix(*m_matrix).rotate3d(rotX, rotY
, rotZ)); |
149 } | 149 } |
150 | 150 |
151 RawPtr<CSSMatrix> CSSMatrix::rotateAxisAngle(double x, double y, double z, doubl
e angle) const | 151 CSSMatrix* CSSMatrix::rotateAxisAngle(double x, double y, double z, double angle
) const |
152 { | 152 { |
153 if (std::isnan(x)) | 153 if (std::isnan(x)) |
154 x = 0; | 154 x = 0; |
155 if (std::isnan(y)) | 155 if (std::isnan(y)) |
156 y = 0; | 156 y = 0; |
157 if (std::isnan(z)) | 157 if (std::isnan(z)) |
158 z = 0; | 158 z = 0; |
159 if (std::isnan(angle)) | 159 if (std::isnan(angle)) |
160 angle = 0; | 160 angle = 0; |
161 if (!x && !y && !z) | 161 if (!x && !y && !z) |
162 z = 1; | 162 z = 1; |
163 return CSSMatrix::create(TransformationMatrix(*m_matrix).rotate3d(x, y, z, a
ngle)); | 163 return CSSMatrix::create(TransformationMatrix(*m_matrix).rotate3d(x, y, z, a
ngle)); |
164 } | 164 } |
165 | 165 |
166 RawPtr<CSSMatrix> CSSMatrix::skewX(double angle) const | 166 CSSMatrix* CSSMatrix::skewX(double angle) const |
167 { | 167 { |
168 if (std::isnan(angle)) | 168 if (std::isnan(angle)) |
169 angle = 0; | 169 angle = 0; |
170 return CSSMatrix::create(TransformationMatrix(*m_matrix).skewX(angle)); | 170 return CSSMatrix::create(TransformationMatrix(*m_matrix).skewX(angle)); |
171 } | 171 } |
172 | 172 |
173 RawPtr<CSSMatrix> CSSMatrix::skewY(double angle) const | 173 CSSMatrix* CSSMatrix::skewY(double angle) const |
174 { | 174 { |
175 if (std::isnan(angle)) | 175 if (std::isnan(angle)) |
176 angle = 0; | 176 angle = 0; |
177 return CSSMatrix::create(TransformationMatrix(*m_matrix).skewY(angle)); | 177 return CSSMatrix::create(TransformationMatrix(*m_matrix).skewY(angle)); |
178 } | 178 } |
179 | 179 |
180 String CSSMatrix::toString() const | 180 String CSSMatrix::toString() const |
181 { | 181 { |
182 // FIXME - Need to ensure valid CSS floating point values (https://bugs.webk
it.org/show_bug.cgi?id=20674) | 182 // FIXME - Need to ensure valid CSS floating point values (https://bugs.webk
it.org/show_bug.cgi?id=20674) |
183 if (m_matrix->isAffine()) | 183 if (m_matrix->isAffine()) |
184 return String::format("matrix(%f, %f, %f, %f, %f, %f)", m_matrix->a(), m
_matrix->b(), m_matrix->c(), m_matrix->d(), m_matrix->e(), m_matrix->f()); | 184 return String::format("matrix(%f, %f, %f, %f, %f, %f)", m_matrix->a(), m
_matrix->b(), m_matrix->c(), m_matrix->d(), m_matrix->e(), m_matrix->f()); |
185 return String::format("matrix3d(%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f,
%f, %f, %f, %f, %f)", | 185 return String::format("matrix3d(%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f,
%f, %f, %f, %f, %f)", |
186 m_matrix->m11(), m_matrix->m12(), m_matrix->m13(), m_matrix->m14(), | 186 m_matrix->m11(), m_matrix->m12(), m_matrix->m13(), m_matrix->m14(), |
187 m_matrix->m21(), m_matrix->m22(), m_matrix->m23(), m_matrix->m24(), | 187 m_matrix->m21(), m_matrix->m22(), m_matrix->m23(), m_matrix->m24(), |
188 m_matrix->m31(), m_matrix->m32(), m_matrix->m33(), m_matrix->m34(), | 188 m_matrix->m31(), m_matrix->m32(), m_matrix->m33(), m_matrix->m34(), |
189 m_matrix->m41(), m_matrix->m42(), m_matrix->m43(), m_matrix->m44()); | 189 m_matrix->m41(), m_matrix->m42(), m_matrix->m43(), m_matrix->m44()); |
190 } | 190 } |
191 | 191 |
192 } // namespace blink | 192 } // namespace blink |
OLD | NEW |