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 | |
15 namespace blink { | 7 namespace blink { |
16 | 8 |
17 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { | 9 DOMMatrix* DOMMatrix::create(ExceptionState& exceptionState) { |
18 return new DOMMatrix(TransformationMatrix()); | 10 return new DOMMatrix(TransformationMatrix()); |
19 } | 11 } |
20 | 12 |
21 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, | 13 DOMMatrix* DOMMatrix::create(DOMMatrixReadOnly* other, |
22 ExceptionState& exceptionState) { | 14 ExceptionState& exceptionState) { |
23 return new DOMMatrix(other->matrix(), other->is2D()); | 15 return new DOMMatrix(other->matrix(), other->is2D()); |
24 } | 16 } |
25 | 17 |
26 DOMMatrix* DOMMatrix::create(const SkMatrix44& matrix, | 18 DOMMatrix* DOMMatrix::create(const SkMatrix44& matrix, |
27 ExceptionState& exceptionState) { | 19 ExceptionState& exceptionState) { |
28 TransformationMatrix transformationMatrix(matrix); | 20 TransformationMatrix transformationMatrix(matrix); |
29 return new DOMMatrix(transformationMatrix, transformationMatrix.isAffine()); | 21 return new DOMMatrix(transformationMatrix, transformationMatrix.isAffine()); |
30 } | 22 } |
31 | 23 |
24 DOMMatrix* DOMMatrix::create(const String& transformList, | |
25 ExceptionState& exceptionState) { | |
26 return new DOMMatrix(transformList, exceptionState); | |
27 } | |
28 | |
32 DOMMatrix* DOMMatrix::create(Vector<double> sequence, | 29 DOMMatrix* DOMMatrix::create(Vector<double> sequence, |
33 ExceptionState& exceptionState) { | 30 ExceptionState& exceptionState) { |
34 if (sequence.size() != 6 && sequence.size() != 16) { | 31 if (sequence.size() != 6 && sequence.size() != 16) { |
35 exceptionState.throwTypeError( | 32 exceptionState.throwTypeError( |
36 "The sequence must contain 6 elements for a 2D matrix or 16 elements " | 33 "The sequence must contain 6 elements for a 2D matrix or 16 elements " |
37 "for a 3D matrix."); | 34 "for a 3D matrix."); |
38 return nullptr; | 35 return nullptr; |
39 } | 36 } |
40 return new DOMMatrix(sequence, sequence.size()); | 37 return new DOMMatrix(sequence, sequence.size()); |
41 } | 38 } |
(...skipping 13 matching lines...) Expand all Loading... | |
55 ExceptionState& exceptionState) { | 52 ExceptionState& exceptionState) { |
56 if (float64Array->length() != 6 && float64Array->length() != 16) { | 53 if (float64Array->length() != 6 && float64Array->length() != 16) { |
57 exceptionState.throwTypeError( | 54 exceptionState.throwTypeError( |
58 "The sequence must contain 6 elements for a 2D matrix or 16 elements " | 55 "The sequence must contain 6 elements for a 2D matrix or 16 elements " |
59 "for a 3D matrix."); | 56 "for a 3D matrix."); |
60 return nullptr; | 57 return nullptr; |
61 } | 58 } |
62 return new DOMMatrix(float64Array->data(), float64Array->length()); | 59 return new DOMMatrix(float64Array->data(), float64Array->length()); |
63 } | 60 } |
64 | 61 |
62 DOMMatrix::DOMMatrix(const String& transformList, | |
63 ExceptionState& exceptionState) | |
64 : DOMMatrixReadOnly(transformList, exceptionState) {} | |
65 | |
65 template <typename T> | 66 template <typename T> |
66 DOMMatrix::DOMMatrix(T sequence, int size) | 67 DOMMatrix::DOMMatrix(T sequence, int size) |
67 : DOMMatrixReadOnly(sequence, size) {} | 68 : DOMMatrixReadOnly(sequence, size) {} |
68 | 69 |
69 DOMMatrix::DOMMatrix(const TransformationMatrix& matrix, bool is2D) | 70 DOMMatrix::DOMMatrix(const TransformationMatrix& matrix, bool is2D) |
70 : DOMMatrixReadOnly(matrix, is2D) {} | 71 : DOMMatrixReadOnly(matrix, is2D) {} |
71 | 72 |
72 DOMMatrix* DOMMatrix::fromMatrix(DOMMatrixInit& other, | 73 DOMMatrix* DOMMatrix::fromMatrix(DOMMatrixInit& other, |
73 ExceptionState& exceptionState) { | 74 ExceptionState& exceptionState) { |
74 validateAndFixup(other, exceptionState); | 75 validateAndFixup(other, exceptionState); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 m_matrix = TransformationMatrix::create(m_matrix->inverse()); | 247 m_matrix = TransformationMatrix::create(m_matrix->inverse()); |
247 } else { | 248 } else { |
248 setNAN(); | 249 setNAN(); |
249 setIs2D(false); | 250 setIs2D(false); |
250 } | 251 } |
251 return this; | 252 return this; |
252 } | 253 } |
253 | 254 |
254 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString, | 255 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString, |
255 ExceptionState& exceptionState) { | 256 ExceptionState& exceptionState) { |
256 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); | 257 return static_cast<DOMMatrix*>( |
zino
2016/11/29 01:09:24
This casting isn't a right way.
I think we can mak
Hwanseung Lee
2016/11/29 14:31:25
Done.
| |
257 String string = inputString; | 258 DOMMatrixReadOnly::setMatrixValue(inputString, exceptionState)); |
258 if (string.isEmpty()) | |
259 string = identityMatrix2D; | |
260 | |
261 const CSSValue* value = | |
262 CSSParser::parseSingleValue(CSSPropertyTransform, string); | |
263 | |
264 if (!value || value->isCSSWideKeyword()) { | |
265 exceptionState.throwDOMException(SyntaxError, | |
266 "Failed to parse '" + inputString + "'."); | |
267 return nullptr; | |
268 } | |
269 | |
270 if (value->isIdentifierValue()) { | |
271 DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone); | |
272 m_matrix->makeIdentity(); | |
273 m_is2D = true; | |
274 return this; | |
275 } | |
276 | |
277 if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) { | |
278 exceptionState.throwDOMException(SyntaxError, | |
279 "Relative lengths not supported."); | |
280 return nullptr; | |
281 } | |
282 | |
283 const ComputedStyle& initialStyle = ComputedStyle::initialStyle(); | |
284 TransformOperations operations = TransformBuilder::createTransformOperations( | |
285 *value, CSSToLengthConversionData(&initialStyle, &initialStyle, | |
286 LayoutViewItem(nullptr), 1.0f)); | |
287 | |
288 if (operations.dependsOnBoxSize()) { | |
289 exceptionState.throwDOMException(SyntaxError, | |
290 "The transformation depends on the box " | |
291 "size, which is not supported."); | |
292 return nullptr; | |
293 } | |
294 | |
295 m_matrix->makeIdentity(); | |
296 operations.apply(FloatSize(0, 0), *m_matrix); | |
297 | |
298 m_is2D = !operations.has3DOperation(); | |
299 | |
300 return this; | |
301 } | 259 } |
302 | 260 |
303 } // namespace blink | 261 } // namespace blink |
OLD | NEW |