Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: third_party/WebKit/Source/core/dom/DOMMatrix.cpp

Issue 2516973002: [GeometryInferface] add Constructor(DOMString transformList). (Closed)
Patch Set: update test message. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (!validateAndFixup(other, exceptionState)) { 75 if (!validateAndFixup(other, exceptionState)) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 m_matrix = TransformationMatrix::create(m_matrix->inverse()); 255 m_matrix = TransformationMatrix::create(m_matrix->inverse());
255 } else { 256 } else {
256 setNAN(); 257 setNAN();
257 setIs2D(false); 258 setIs2D(false);
258 } 259 }
259 return this; 260 return this;
260 } 261 }
261 262
262 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString, 263 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString,
263 ExceptionState& exceptionState) { 264 ExceptionState& exceptionState) {
264 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); 265 DOMMatrixReadOnly::setMatrixValueInternal(inputString, exceptionState);
265 String string = inputString;
266 if (string.isEmpty())
267 string = identityMatrix2D;
268
269 const CSSValue* value =
270 CSSParser::parseSingleValue(CSSPropertyTransform, string);
271
272 if (!value || value->isCSSWideKeyword()) {
273 exceptionState.throwDOMException(SyntaxError,
274 "Failed to parse '" + inputString + "'.");
275 return nullptr;
276 }
277
278 if (value->isIdentifierValue()) {
279 DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone);
280 m_matrix->makeIdentity();
281 m_is2D = true;
282 return this;
283 }
284
285 if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) {
286 exceptionState.throwDOMException(SyntaxError,
287 "Relative lengths not supported.");
288 return nullptr;
289 }
290
291 const ComputedStyle& initialStyle = ComputedStyle::initialStyle();
292 TransformOperations operations = TransformBuilder::createTransformOperations(
293 *value, CSSToLengthConversionData(&initialStyle, &initialStyle,
294 LayoutViewItem(nullptr), 1.0f));
295
296 if (operations.dependsOnBoxSize()) {
297 exceptionState.throwDOMException(SyntaxError,
298 "The transformation depends on the box "
299 "size, which is not supported.");
300 return nullptr;
301 }
302
303 m_matrix->makeIdentity();
304 operations.apply(FloatSize(0, 0), *m_matrix);
305
306 m_is2D = !operations.has3DOperation();
307
308 return this; 266 return this;
309 } 267 }
310 268
311 } // namespace blink 269 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698