OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "core/dom/DOMMatrix.h" | 5 #include "core/dom/DOMMatrix.h" |
6 | 6 |
7 #include "core/css/CSSIdentifierValue.h" | |
8 #include "core/css/CSSToLengthConversionData.h" | |
9 #include "core/css/CSSValueList.h" | |
10 #include "core/css/parser/CSSParser.h" | |
11 #include "core/css/resolver/TransformBuilder.h" | |
12 #include "core/layout/api/LayoutViewItem.h" | |
13 #include "core/style/ComputedStyle.h" | |
14 | |
7 namespace blink { | 15 namespace blink { |
8 | 16 |
9 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { | 17 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { |
10 return new DOMMatrix(TransformationMatrix()); | 18 return new DOMMatrix(TransformationMatrix()); |
11 } | 19 } |
12 | 20 |
13 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, | 21 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, |
14 ExceptionState& exceptionState) { | 22 ExceptionState& exceptionState) { |
15 return new DOMMatrix(other->matrix(), other->is2D()); | 23 return new DOMMatrix(other->matrix(), other->is2D()); |
16 } | 24 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 setM34(NAN); | 212 setM34(NAN); |
205 setM41(NAN); | 213 setM41(NAN); |
206 setM42(NAN); | 214 setM42(NAN); |
207 setM43(NAN); | 215 setM43(NAN); |
208 setM44(NAN); | 216 setM44(NAN); |
209 setIs2D(false); | 217 setIs2D(false); |
210 } | 218 } |
211 return this; | 219 return this; |
212 } | 220 } |
213 | 221 |
222 static inline PassRefPtr<ComputedStyle> createInitialStyle() { | |
Timothy Loh
2016/10/19 02:59:08
Just use ComputedStyle::initialStyle() instead of
Hwanseung Lee
2016/10/22 14:44:56
Done.
Timothy Loh
2016/10/24 04:18:30
I meant that we shouldn't need a createInitialStyl
Hwanseung Lee
2016/10/24 13:23:37
Done.
| |
223 RefPtr<ComputedStyle> initialStyle = ComputedStyle::create(); | |
224 initialStyle->font().update(nullptr); | |
225 return initialStyle; | |
226 } | |
227 | |
228 DOMMatrix* DOMMatrix::setMatrixValue(const String& string, | |
229 ExceptionState& exceptionState) { | |
230 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); | |
231 String inputString = string; | |
Timothy Loh
2016/10/19 02:59:08
This naming is weird, if you have inputString and
Hwanseung Lee
2016/10/22 14:44:56
Done.
| |
232 if (string.isEmpty()) | |
233 inputString = identityMatrix2D; | |
234 | |
235 const CSSValue* value = | |
236 CSSParser::parseSingleValue(CSSPropertyTransform, inputString); | |
237 | |
238 if (!value) { // There is something there but parsing failed. | |
239 exceptionState.throwDOMException(SyntaxError, | |
240 "Failed to parse '" + string + "'."); | |
241 return nullptr; | |
242 } | |
243 | |
244 if (value->isIdentifierValue() && | |
245 (toCSSIdentifierValue(value))->getValueID() == CSSValueNone) { | |
246 exceptionState.throwDOMException(SyntaxError, | |
247 "Failed to parse '" + string + "'."); | |
248 return nullptr; | |
249 } | |
250 | |
251 DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); | |
252 | |
253 if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) { | |
254 exceptionState.throwDOMException(SyntaxError, | |
255 "Relative lengths not supported."); | |
256 return nullptr; | |
257 } | |
258 | |
259 TransformOperations operations; | |
260 TransformBuilder::createTransformOperations( | |
261 *value, CSSToLengthConversionData(initialStyle, initialStyle, | |
262 LayoutViewItem(nullptr), 1.0f), | |
263 operations); | |
264 | |
265 // Convert transform operations to a TransformationMatrix. This can fail | |
Timothy Loh
2016/10/19 02:59:08
This comment is misplaced, the conversion is 12 li
Hwanseung Lee
2016/10/22 14:44:56
Done.
| |
266 // if a param has a percentage ('%') | |
267 if (operations.dependsOnBoxSize()) { | |
268 exceptionState.throwDOMException(SyntaxError, | |
269 "The transformation depends on the box " | |
270 "size, which is not supported."); | |
271 return nullptr; | |
272 } | |
273 | |
274 if (operations.has3DOperation()) | |
275 m_is2D = false; | |
Timothy Loh
2016/10/19 02:59:08
Shouldn't this be
m_is2D = !operations.has3DOpera
Hwanseung Lee
2016/10/22 14:44:57
Done.
| |
276 | |
277 m_matrix = TransformationMatrix::create(); | |
278 operations.apply(FloatSize(0, 0), *m_matrix); | |
279 | |
280 return this; | |
281 } | |
282 | |
214 } // namespace blink | 283 } // namespace blink |
OLD | NEW |