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

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

Issue 2516973002: [GeometryInferface] add Constructor(DOMString transformList). (Closed)
Patch Set: [GeometryInferface] add Constructor(DOMString transformList). 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 DOMMatrix* matrix = new DOMMatrix(TransformationMatrix());
27 matrix->setMatrixValueFromString(transformList, exceptionState);
28 return matrix;
29 }
30
32 DOMMatrix* DOMMatrix::create(Vector<double> sequence, 31 DOMMatrix* DOMMatrix::create(Vector<double> sequence,
33 ExceptionState& exceptionState) { 32 ExceptionState& exceptionState) {
34 if (sequence.size() != 6 && sequence.size() != 16) { 33 if (sequence.size() != 6 && sequence.size() != 16) {
35 exceptionState.throwTypeError( 34 exceptionState.throwTypeError(
36 "The sequence must contain 6 elements for a 2D matrix or 16 elements " 35 "The sequence must contain 6 elements for a 2D matrix or 16 elements "
37 "for a 3D matrix."); 36 "for a 3D matrix.");
38 return nullptr; 37 return nullptr;
39 } 38 }
40 return new DOMMatrix(sequence, sequence.size()); 39 return new DOMMatrix(sequence, sequence.size());
41 } 40 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 m_matrix = TransformationMatrix::create(m_matrix->inverse()); 253 m_matrix = TransformationMatrix::create(m_matrix->inverse());
255 } else { 254 } else {
256 setNAN(); 255 setNAN();
257 setIs2D(false); 256 setIs2D(false);
258 } 257 }
259 return this; 258 return this;
260 } 259 }
261 260
262 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString, 261 DOMMatrix* DOMMatrix::setMatrixValue(const String& inputString,
263 ExceptionState& exceptionState) { 262 ExceptionState& exceptionState) {
264 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); 263 setMatrixValueFromString(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; 264 return this;
309 } 265 }
310 266
311 } // namespace blink 267 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/DOMMatrix.h ('k') | third_party/WebKit/Source/core/dom/DOMMatrix.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698