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/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 Loading... |
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 Loading... |
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 "Lengths must be absolute, not relative"); |
| 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( |
| 386 SyntaxError, "Lengths must be absolute, not depend on the box size"); |
| 387 return; |
| 388 } |
| 389 |
| 390 m_matrix->makeIdentity(); |
| 391 operations.apply(FloatSize(0, 0), *m_matrix); |
| 392 |
| 393 m_is2D = !operations.has3DOperation(); |
| 394 |
| 395 return; |
| 396 } |
| 397 |
335 } // namespace blink | 398 } // namespace blink |
OLD | NEW |