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

Unified Diff: third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp

Issue 2283363003: GeometryInterface: Add DOMMatrixInit and fromMatrix(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp
diff --git a/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp b/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp
index b91ed3d470c01dd6ab0b8b3bcf9c5da1174ff204..1f24620588e993efb7c0251c15cbd5b5ffd49637 100644
--- a/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp
+++ b/third_party/WebKit/Source/core/dom/DOMMatrixReadOnly.cpp
@@ -3,8 +3,82 @@
// found in the LICENSE file.
#include "core/dom/DOMMatrix.h"
+#include "core/dom/DOMMatrixInit.h"
namespace blink {
+namespace {
+
+void setDictionaryMembers(DOMMatrixInit& other)
+{
+ if (!other.hasM11()) {
+ if (other.hasA())
+ other.setM11(other.a());
+ else
+ other.setM11(1);
+ }
+ if (!other.hasM12()) {
+ if (other.hasB())
+ other.setM12(other.b());
+ else
+ other.setM12(0);
+ }
+ if (!other.hasM21()) {
+ if (other.hasC())
+ other.setM21(other.c());
+ else
+ other.setM21(0);
+ }
+ if (!other.hasM22()) {
+ if (other.hasD())
+ other.setM22(other.d());
+ else
+ other.setM22(1);
+ }
+ if (!other.hasM41()) {
+ if (other.hasE())
+ other.setM41(other.e());
+ else
+ other.setM41(0);
+ }
+ if (!other.hasM42()) {
+ if (other.hasF())
+ other.setM42(other.f());
+ else
+ other.setM42(0);
+ }
+}
+
+} // namespace
+
+void DOMMatrixReadOnly::validateAndFixup(DOMMatrixInit& other, ExceptionState& exceptionState)
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.
+{
+ if ((other.hasA() && other.hasM11() && other.a() != other.m11())
+ || (other.hasB() && other.hasM12() && other.b() != other.m12())
+ || (other.hasC() && other.hasM21() && other.c() != other.m21())
+ || (other.hasD() && other.hasM22() && other.d() != other.m22())
+ || (other.hasE() && other.hasM41() && other.e() != other.m41())
+ || (other.hasF() && other.hasM42() && other.f() != other.m42())) {
+ 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.
+ return;
+ }
+
+ if (other.hasIs2D() && other.is2D() && (other.m31() || other.m32()
+ || other.m13() || other.m23() || other.m43() || other.m14()
+ || other.m24() || other.m34() || other.m33() != 1 || other.m44() != 1)) {
+ exceptionState.throwTypeError("The is2D member is set to true but the input matrix is 3d matrix.");
+ return;
+ }
+
+ setDictionaryMembers(other);
+ if (!other.hasIs2D()) {
+ if (other.m31() || other.m32() || other.m13() || other.m23()
+ || other.m43() || other.m14() || other.m24() || other.m34()
+ || other.m33() != 1 || other.m44() != 1)
+ 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.
+ else
+ other.setIs2D(true);
+ }
+}
DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, ExceptionState& exceptionState)
{
@@ -15,6 +89,24 @@ DOMMatrixReadOnly* DOMMatrixReadOnly::create(Vector<double> sequence, ExceptionS
return new DOMMatrixReadOnly(sequence);
}
+DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix(DOMMatrixInit& other, ExceptionState& exceptionState)
+{
+ 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.
+ if (exceptionState.hadException())
+ return nullptr;
+
+ if (other.is2D()) {
+ return new DOMMatrixReadOnly({
+ other.m11(), other.m12(), other.m21(),
+ other.m22(), other.m41(), other.m42()});
+ }
+ return new DOMMatrixReadOnly({
+ other.m11(), other.m12(), other.m13(), other.m14(),
+ other.m21(), other.m22(), other.m23(), other.m24(),
+ other.m31(), other.m32(), other.m33(), other.m34(),
+ other.m41(), other.m42(), other.m43(), other.m44()});
+}
+
DOMMatrixReadOnly::DOMMatrixReadOnly(Vector<double> sequence)
{
if (sequence.size() == 6) {
@@ -48,9 +140,9 @@ bool DOMMatrixReadOnly::isIdentity() const
return m_matrix->isIdentity();
}
-DOMMatrix* DOMMatrixReadOnly::multiply(DOMMatrix* other)
+DOMMatrix* DOMMatrixReadOnly::multiply(DOMMatrixInit& other, ExceptionState& exceptionState)
{
- return DOMMatrix::create(this)->multiplySelf(other);
+ return DOMMatrix::create(this)->multiplySelf(other, exceptionState);
}
DOMMatrix* DOMMatrixReadOnly::translate(double tx, double ty, double tz)

Powered by Google App Engine
This is Rietveld 408576698