Chromium Code Reviews| 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 return new DOMMatrixReadOnly(transformList, exceptionState); | |
|
zino
2016/11/30 13:39:31
DOMMatrixReadOnly*
matrix = new DOMMatrixReadOnly(
Hwanseung Lee
2016/11/30 14:00:31
Done.
| |
| 102 } | |
| 103 | |
| 92 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, | 104 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, |
| 93 ExceptionState& exceptionState) { | 105 ExceptionState& exceptionState) { |
| 94 if (sequence.size() != 6 && sequence.size() != 16) { | 106 if (sequence.size() != 6 && sequence.size() != 16) { |
| 95 exceptionState.throwTypeError( | 107 exceptionState.throwTypeError( |
| 96 "The sequence must contain 6 elements for a 2D matrix or 16 elements " | 108 "The sequence must contain 6 elements for a 2D matrix or 16 elements " |
| 97 "for a 3D matrix."); | 109 "for a 3D matrix."); |
| 98 return nullptr; | 110 return nullptr; |
| 99 } | 111 } |
| 100 return new DOMMatrixReadOnly(sequence, sequence.size()); | 112 return new DOMMatrixReadOnly(sequence, sequence.size()); |
| 101 } | 113 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 point.w() * m41(); | 260 point.w() * m41(); |
| 249 double y = point.x() * m12() + point.y() * m22() + point.z() * m32() + | 261 double y = point.x() * m12() + point.y() * m22() + point.z() * m32() + |
| 250 point.w() * m42(); | 262 point.w() * m42(); |
| 251 double z = point.x() * m13() + point.y() * m23() + point.z() * m33() + | 263 double z = point.x() * m13() + point.y() * m23() + point.z() * m33() + |
| 252 point.w() * m43(); | 264 point.w() * m43(); |
| 253 double w = point.x() * m14() + point.y() * m24() + point.z() * m34() + | 265 double w = point.x() * m14() + point.y() * m24() + point.z() * m34() + |
| 254 point.w() * m44(); | 266 point.w() * m44(); |
| 255 return DOMPoint::create(x, y, z, w); | 267 return DOMPoint::create(x, y, z, w); |
| 256 } | 268 } |
| 257 | 269 |
| 270 DOMMatrixReadOnly::DOMMatrixReadOnly(const String& inputString, | |
|
zino
2016/11/30 13:39:31
This constructor is unncessary I think :)
Please
Hwanseung Lee
2016/11/30 14:00:31
Done.
| |
| 271 ExceptionState& exceptionState) { | |
| 272 m_matrix = TransformationMatrix::create(); | |
| 273 setMatrixValueInternal(inputString, exceptionState); | |
| 274 } | |
| 275 | |
| 258 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix, | 276 DOMMatrixReadOnly::DOMMatrixReadOnly(const TransformationMatrix& matrix, |
| 259 bool is2D) { | 277 bool is2D) { |
| 260 m_matrix = TransformationMatrix::create(matrix); | 278 m_matrix = TransformationMatrix::create(matrix); |
| 261 m_is2D = is2D; | 279 m_is2D = is2D; |
| 262 } | 280 } |
| 263 | 281 |
| 264 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const { | 282 DOMFloat32Array* DOMMatrixReadOnly::toFloat32Array() const { |
| 265 float array[] = { | 283 float array[] = { |
| 266 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()), | 284 static_cast<float>(m_matrix->m11()), static_cast<float>(m_matrix->m12()), |
| 267 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()), | 285 static_cast<float>(m_matrix->m13()), static_cast<float>(m_matrix->m14()), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 result.addNumber("m34", m34()); | 343 result.addNumber("m34", m34()); |
| 326 result.addNumber("m41", m41()); | 344 result.addNumber("m41", m41()); |
| 327 result.addNumber("m42", m42()); | 345 result.addNumber("m42", m42()); |
| 328 result.addNumber("m43", m43()); | 346 result.addNumber("m43", m43()); |
| 329 result.addNumber("m44", m44()); | 347 result.addNumber("m44", m44()); |
| 330 result.addBoolean("is2D", is2D()); | 348 result.addBoolean("is2D", is2D()); |
| 331 result.addBoolean("isIdentity", isIdentity()); | 349 result.addBoolean("isIdentity", isIdentity()); |
| 332 return result.scriptValue(); | 350 return result.scriptValue(); |
| 333 } | 351 } |
| 334 | 352 |
| 353 void DOMMatrixReadOnly::setMatrixValueInternal(const String& inputString, | |
|
zino
2016/11/30 13:39:31
Could you please rename this to better name? (e.g.
Hwanseung Lee
2016/11/30 14:00:31
Done.
| |
| 354 ExceptionState& exceptionState) { | |
| 355 DEFINE_STATIC_LOCAL(String, identityMatrix2D, ("matrix(1, 0, 0, 1, 0, 0)")); | |
| 356 String string = inputString; | |
| 357 if (string.isEmpty()) | |
| 358 string = identityMatrix2D; | |
| 359 | |
| 360 const CSSValue* value = | |
| 361 CSSParser::parseSingleValue(CSSPropertyTransform, string); | |
| 362 | |
| 363 if (!value || value->isCSSWideKeyword()) { | |
| 364 exceptionState.throwDOMException(SyntaxError, | |
| 365 "Failed to parse '" + inputString + "'."); | |
| 366 return; | |
| 367 } | |
| 368 | |
| 369 if (value->isIdentifierValue()) { | |
| 370 DCHECK(toCSSIdentifierValue(value)->getValueID() == CSSValueNone); | |
| 371 m_matrix->makeIdentity(); | |
| 372 m_is2D = true; | |
| 373 return; | |
| 374 } | |
| 375 | |
| 376 if (TransformBuilder::hasRelativeLengths(toCSSValueList(*value))) { | |
| 377 exceptionState.throwDOMException(SyntaxError, | |
| 378 "Relative lengths not supported."); | |
| 379 return; | |
| 380 } | |
| 381 | |
| 382 const ComputedStyle& initialStyle = ComputedStyle::initialStyle(); | |
| 383 TransformOperations operations = TransformBuilder::createTransformOperations( | |
| 384 *value, CSSToLengthConversionData(&initialStyle, &initialStyle, | |
| 385 LayoutViewItem(nullptr), 1.0f)); | |
| 386 | |
| 387 if (operations.dependsOnBoxSize()) { | |
| 388 exceptionState.throwDOMException(SyntaxError, | |
| 389 "The transformation depends on the box " | |
| 390 "size, which is not supported."); | |
| 391 return; | |
| 392 } | |
| 393 | |
| 394 m_matrix->makeIdentity(); | |
| 395 operations.apply(FloatSize(0, 0), *m_matrix); | |
| 396 | |
| 397 m_is2D = !operations.has3DOperation(); | |
| 398 | |
| 399 return; | |
| 400 } | |
| 401 | |
| 335 } // namespace blink | 402 } // namespace blink |
| OLD | NEW |