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

Side by Side Diff: third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.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/DOMMatrixReadOnly.h" 5 #include "core/dom/DOMMatrixReadOnly.h"
6 6
7 #include "bindings/core/v8/V8ObjectBuilder.h" 7 #include "bindings/core/v8/V8ObjectBuilder.h"
8 #include "core/css/CSSIdentifierValue.h"
9 #include "core/css/CSSToLengthConversionData.h"
10 #include "core/css/CSSValueList.h"
11 #include "core/css/parser/CSSParser.h"
12 #include "core/css/resolver/TransformBuilder.h"
8 #include "core/dom/DOMMatrix.h" 13 #include "core/dom/DOMMatrix.h"
9 #include "core/dom/DOMMatrixInit.h" 14 #include "core/dom/DOMMatrixInit.h"
10 #include "core/dom/DOMPoint.h" 15 #include "core/dom/DOMPoint.h"
11 #include "core/dom/DOMPointInit.h" 16 #include "core/dom/DOMPointInit.h"
17 #include "core/layout/api/LayoutViewItem.h"
18 #include "core/style/ComputedStyle.h"
12 19
13 namespace blink { 20 namespace blink {
14 namespace { 21 namespace {
15 22
16 void setDictionaryMembers(DOMMatrixInit& other) { 23 void setDictionaryMembers(DOMMatrixInit& other) {
17 if (!other.hasM11()) 24 if (!other.hasM11())
18 other.setM11(other.hasA() ? other.a() : 1); 25 other.setM11(other.hasA() ? other.a() : 1);
19 26
20 if (!other.hasM12()) 27 if (!other.hasM12())
21 other.setM12(other.hasB() ? other.b() : 0); 28 other.setM12(other.hasB() ? other.b() : 0);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 other.m33() != 1 || other.m44() != 1); 89 other.m33() != 1 || other.m44() != 1);
83 other.setIs2D(is2D); 90 other.setIs2D(is2D);
84 } 91 }
85 return true; 92 return true;
86 } 93 }
87 94
88 DOMMatrixReadOnly* DOMMatrixReadOnly::create(ExceptionState& exceptionState) { 95 DOMMatrixReadOnly* DOMMatrixReadOnly::create(ExceptionState& exceptionState) {
89 return new DOMMatrixReadOnly(TransformationMatrix()); 96 return new DOMMatrixReadOnly(TransformationMatrix());
90 } 97 }
91 98
99 DOMMatrixReadOnly* DOMMatrixReadOnly::create(const String& transformList,
100 ExceptionState& exceptionState) {
101 DOMMatrixReadOnly* matrix = new DOMMatrixReadOnly(TransformationMatrix());
102 matrix->setMatrixValueFromString(transformList, exceptionState);
103 return matrix;
104 }
105
92 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, 106 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence,
93 ExceptionState& exceptionState) { 107 ExceptionState& exceptionState) {
94 if (sequence.size() != 6 && sequence.size() != 16) { 108 if (sequence.size() != 6 && sequence.size() != 16) {
95 exceptionState.throwTypeError( 109 exceptionState.throwTypeError(
96 "The sequence must contain 6 elements for a 2D matrix or 16 elements " 110 "The sequence must contain 6 elements for a 2D matrix or 16 elements "
97 "for a 3D matrix."); 111 "for a 3D matrix.");
98 return nullptr; 112 return nullptr;
99 } 113 }
100 return new DOMMatrixReadOnly(sequence, sequence.size()); 114 return new DOMMatrixReadOnly(sequence, sequence.size());
101 } 115 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 result.addNumber("m34", m34()); 339 result.addNumber("m34", m34());
326 result.addNumber("m41", m41()); 340 result.addNumber("m41", m41());
327 result.addNumber("m42", m42()); 341 result.addNumber("m42", m42());
328 result.addNumber("m43", m43()); 342 result.addNumber("m43", m43());
329 result.addNumber("m44", m44()); 343 result.addNumber("m44", m44());
330 result.addBoolean("is2D", is2D()); 344 result.addBoolean("is2D", is2D());
331 result.addBoolean("isIdentity", isIdentity()); 345 result.addBoolean("isIdentity", isIdentity());
332 return result.scriptValue(); 346 return result.scriptValue();
333 } 347 }
334 348
349 void DOMMatrixReadOnly::setMatrixValueFromString(
350 const String& inputString,
351 ExceptionState& exceptionState) {
352 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)"));
353 String string = inputString;
354 if (string.isEmpty())
355 string = identityMatrix2D;
356
357 const CSSValue* value =
358 CSSParser::parseSingleValue(CSSPropertyTransform, string);
359
360 if (!value || value->isCSSWideKeyword()) {
361 exceptionState.throwDOMException(SyntaxError,
362 "Failed to parse '" + inputString + "'.");
363 return;
364 }
365
366 if (value->isIdentifierValue()) {
367 DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone);
368 m_matrix->makeIdentity();
369 m_is2D = true;
370 return;
371 }
372
373 if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) {
374 exceptionState.throwDOMException(SyntaxError,
375 "Relative lengths not supported.");
dominicc (has gone to gerrit) 2016/12/05 08:03:45 Maybe something which mentions "must" and "absolut
Hwanseung Lee 2016/12/05 15:15:19 i modified strings. is it fine?
376 return;
377 }
378
379 const ComputedStyle& initialStyle = ComputedStyle::initialStyle();
380 TransformOperations operations = TransformBuilder::createTransformOperations(
381 *value, CSSToLengthConversionData(&initialStyle, &initialStyle,
382 LayoutViewItem(nullptr), 1.0f));
383
384 if (operations.dependsOnBoxSize()) {
385 exceptionState.throwDOMException(SyntaxError,
386 "The transformation depends on the box "
387 "size, which is not supported.");
388 return;
389 }
390
391 m_matrix->makeIdentity();
392 operations.apply(FloatSize(0, 0), *m_matrix);
393
394 m_is2D = !operations.has3DOperation();
395
396 return;
397 }
398
335 } // namespace blink 399 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698