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/DOMMatrix.h" | 5 #include "core/dom/DOMMatrix.h" |
| 6 #include "core/dom/DOMMatrixInit.h" | |
| 6 | 7 |
| 7 namespace blink { | 8 namespace blink { |
| 9 namespace { | |
| 10 | |
| 11 void setDictionaryMembers(DOMMatrixInit& other) | |
| 12 { | |
| 13 if (!other.hasM11()) { | |
| 14 if (other.hasA()) | |
| 15 other.setM11(other.a()); | |
| 16 else | |
| 17 other.setM11(1); | |
| 18 } | |
| 19 if (!other.hasM12()) { | |
| 20 if (other.hasB()) | |
| 21 other.setM12(other.b()); | |
| 22 else | |
| 23 other.setM12(0); | |
| 24 } | |
| 25 if (!other.hasM21()) { | |
| 26 if (other.hasC()) | |
| 27 other.setM21(other.c()); | |
| 28 else | |
| 29 other.setM21(0); | |
| 30 } | |
| 31 if (!other.hasM22()) { | |
| 32 if (other.hasD()) | |
| 33 other.setM22(other.d()); | |
| 34 else | |
| 35 other.setM22(1); | |
| 36 } | |
| 37 if (!other.hasM41()) { | |
| 38 if (other.hasE()) | |
| 39 other.setM41(other.e()); | |
| 40 else | |
| 41 other.setM41(0); | |
| 42 } | |
| 43 if (!other.hasM42()) { | |
| 44 if (other.hasF()) | |
| 45 other.setM42(other.f()); | |
| 46 else | |
| 47 other.setM42(0); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 53 void DOMMatrixReadOnly::validateAndFixup(DOMMatrixInit& other, ExceptionState& e xceptionState) | |
|
dominicc (has gone to gerrit)
2016/08/30 02:13:43
Please add tests for NaN. The note about NaN bit p
zino
2016/09/10 10:18:15
Done.
| |
| 54 { | |
| 55 if ((other.hasA() && other.hasM11() && other.a() != other.m11()) | |
| 56 || (other.hasB() && other.hasM12() && other.b() != other.m12()) | |
| 57 || (other.hasC() && other.hasM21() && other.c() != other.m21()) | |
| 58 || (other.hasD() && other.hasM22() && other.d() != other.m22()) | |
| 59 || (other.hasE() && other.hasM41() && other.e() != other.m41()) | |
| 60 || (other.hasF() && other.hasM42() && other.f() != other.m42())) { | |
| 61 exceptionState.throwTypeError("[a, b, c, d, e, f] members should equals [m11, m12, m21, m22, m41, m42]."); | |
|
dominicc (has gone to gerrit)
2016/08/30 02:13:43
Grammar: should equals -> should equal
It's a bit
zino
2016/09/10 10:18:15
Done.
| |
| 62 return; | |
| 63 } | |
| 64 | |
| 65 if (other.hasIs2D() && other.is2D() && (other.m31() || other.m32() | |
| 66 || other.m13() || other.m23() || other.m43() || other.m14() | |
| 67 || other.m24() || other.m34() || other.m33() != 1 || other.m44() != 1)) { | |
| 68 exceptionState.throwTypeError("The is2D member is set to true but the in put matrix is 3d matrix."); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 setDictionaryMembers(other); | |
| 73 if (!other.hasIs2D()) { | |
| 74 if (other.m31() || other.m32() || other.m13() || other.m23() | |
| 75 || other.m43() || other.m14() || other.m24() || other.m34() | |
| 76 || other.m33() != 1 || other.m44() != 1) | |
| 77 other.setIs2D(false); | |
|
dominicc (has gone to gerrit)
2016/08/30 02:13:43
Why not save that expression in a variable with a
zino
2016/09/10 10:18:15
Done.
| |
| 78 else | |
| 79 other.setIs2D(true); | |
| 80 } | |
| 81 } | |
| 8 | 82 |
| 9 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, ExceptionS tate& exceptionState) | 83 DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, ExceptionS tate& exceptionState) |
| 10 { | 84 { |
| 11 if (sequence.size() != 6 && sequence.size() != 16) { | 85 if (sequence.size() != 6 && sequence.size() != 16) { |
| 12 exceptionState.throwTypeError("An invalid number sequence is specified. The sequence must contain 6 elements for 2D matrix and 16 elements for 3D matrix ."); | 86 exceptionState.throwTypeError("An invalid number sequence is specified. The sequence must contain 6 elements for 2D matrix and 16 elements for 3D matrix ."); |
| 13 return nullptr; | 87 return nullptr; |
| 14 } | 88 } |
| 15 return new DOMMatrixReadOnly(sequence); | 89 return new DOMMatrixReadOnly(sequence); |
| 16 } | 90 } |
| 17 | 91 |
| 92 DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix(DOMMatrixInit& other, Exception State& exceptionState) | |
| 93 { | |
| 94 validateAndFixup(other, exceptionState); | |
|
dominicc (has gone to gerrit)
2016/08/30 02:13:43
The common pattern seems to be
validateAndFixUp
c
zino
2016/09/10 10:18:15
Done.
| |
| 95 if (exceptionState.hadException()) | |
| 96 return nullptr; | |
| 97 | |
| 98 if (other.is2D()) { | |
| 99 return new DOMMatrixReadOnly({ | |
| 100 other.m11(), other.m12(), other.m21(), | |
| 101 other.m22(), other.m41(), other.m42()}); | |
| 102 } | |
| 103 return new DOMMatrixReadOnly({ | |
| 104 other.m11(), other.m12(), other.m13(), other.m14(), | |
| 105 other.m21(), other.m22(), other.m23(), other.m24(), | |
| 106 other.m31(), other.m32(), other.m33(), other.m34(), | |
| 107 other.m41(), other.m42(), other.m43(), other.m44()}); | |
| 108 } | |
| 109 | |
| 18 DOMMatrixReadOnly::DOMMatrixReadOnly(Vector<double> sequence) | 110 DOMMatrixReadOnly::DOMMatrixReadOnly(Vector<double> sequence) |
| 19 { | 111 { |
| 20 if (sequence.size() == 6) { | 112 if (sequence.size() == 6) { |
| 21 m_matrix = TransformationMatrix::create( | 113 m_matrix = TransformationMatrix::create( |
| 22 sequence[0], sequence[1], sequence[2], sequence[3], | 114 sequence[0], sequence[1], sequence[2], sequence[3], |
| 23 sequence[4], sequence[5]); | 115 sequence[4], sequence[5]); |
| 24 m_is2D = true; | 116 m_is2D = true; |
| 25 } else if (sequence.size() == 16) { | 117 } else if (sequence.size() == 16) { |
| 26 m_matrix = TransformationMatrix::create( | 118 m_matrix = TransformationMatrix::create( |
| 27 sequence[0], sequence[1], sequence[2], sequence[3], | 119 sequence[0], sequence[1], sequence[2], sequence[3], |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 41 bool DOMMatrixReadOnly::is2D() const | 133 bool DOMMatrixReadOnly::is2D() const |
| 42 { | 134 { |
| 43 return m_is2D; | 135 return m_is2D; |
| 44 } | 136 } |
| 45 | 137 |
| 46 bool DOMMatrixReadOnly::isIdentity() const | 138 bool DOMMatrixReadOnly::isIdentity() const |
| 47 { | 139 { |
| 48 return m_matrix->isIdentity(); | 140 return m_matrix->isIdentity(); |
| 49 } | 141 } |
| 50 | 142 |
| 51 DOMMatrix* DOMMatrixReadOnly::multiply(DOMMatrix* other) | 143 DOMMatrix* DOMMatrixReadOnly::multiply(DOMMatrixInit& other, ExceptionState& exc eptionState) |
| 52 { | 144 { |
| 53 return DOMMatrix::create(this)->multiplySelf(other); | 145 return DOMMatrix::create(this)->multiplySelf(other, exceptionState); |
| 54 } | 146 } |
| 55 | 147 |
| 56 DOMMatrix* DOMMatrixReadOnly::translate(double tx, double ty, double tz) | 148 DOMMatrix* DOMMatrixReadOnly::translate(double tx, double ty, double tz) |
| 57 { | 149 { |
| 58 return DOMMatrix::create(this)->translateSelf(tx, ty, tz); | 150 return DOMMatrix::create(this)->translateSelf(tx, ty, tz); |
| 59 } | 151 } |
| 60 | 152 |
| 61 DOMMatrix* DOMMatrixReadOnly::scale(double scale, double ox, double oy) | 153 DOMMatrix* DOMMatrixReadOnly::scale(double scale, double ox, double oy) |
| 62 { | 154 { |
| 63 return DOMMatrix::create(this)->scaleSelf(scale, ox, oy); | 155 return DOMMatrix::create(this)->scaleSelf(scale, ox, oy); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 << m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", " | 233 << m21() << ", " << m22() << ", " << m23() << ", " << m24() << ", " |
| 142 << m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", " | 234 << m31() << ", " << m32() << ", " << m33() << ", " << m34() << ", " |
| 143 << m41() << ", " << m42() << ", " << m43() << ", " << m44(); | 235 << m41() << ", " << m42() << ", " << m43() << ", " << m44(); |
| 144 } | 236 } |
| 145 stream << ")"; | 237 stream << ")"; |
| 146 | 238 |
| 147 return String(stream.str().c_str()); | 239 return String(stream.str().c_str()); |
| 148 } | 240 } |
| 149 | 241 |
| 150 } // namespace blink | 242 } // namespace blink |
| OLD | NEW |