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/DOMPointReadOnly.h" | 5 #include "core/dom/DOMPointReadOnly.h" |
6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" |
7 #include "bindings/core/v8/ScriptValue.h" | 8 #include "bindings/core/v8/ScriptValue.h" |
8 #include "bindings/core/v8/V8ObjectBuilder.h" | 9 #include "bindings/core/v8/V8ObjectBuilder.h" |
| 10 #include "core/dom/DOMMatrixInit.h" |
| 11 #include "core/dom/DOMMatrixReadOnly.h" |
| 12 #include "core/dom/DOMPoint.h" |
9 #include "core/dom/DOMPointInit.h" | 13 #include "core/dom/DOMPointInit.h" |
10 | 14 |
11 namespace blink { | 15 namespace blink { |
12 | 16 |
13 DOMPointReadOnly* DOMPointReadOnly::create(double x, | 17 DOMPointReadOnly* DOMPointReadOnly::create(double x, |
14 double y, | 18 double y, |
15 double z, | 19 double z, |
16 double w) { | 20 double w) { |
17 return new DOMPointReadOnly(x, y, z, w); | 21 return new DOMPointReadOnly(x, y, z, w); |
18 } | 22 } |
19 | 23 |
20 ScriptValue DOMPointReadOnly::toJSONForBinding( | 24 ScriptValue DOMPointReadOnly::toJSONForBinding( |
21 ScriptState* scriptState) const { | 25 ScriptState* scriptState) const { |
22 V8ObjectBuilder result(scriptState); | 26 V8ObjectBuilder result(scriptState); |
23 result.addNumber("x", x()); | 27 result.addNumber("x", x()); |
24 result.addNumber("y", y()); | 28 result.addNumber("y", y()); |
25 result.addNumber("z", z()); | 29 result.addNumber("z", z()); |
26 result.addNumber("w", w()); | 30 result.addNumber("w", w()); |
27 return result.scriptValue(); | 31 return result.scriptValue(); |
28 } | 32 } |
29 | 33 |
30 DOMPointReadOnly* DOMPointReadOnly::fromPoint(const DOMPointInit& other) { | 34 DOMPointReadOnly* DOMPointReadOnly::fromPoint(const DOMPointInit& other) { |
31 return new DOMPointReadOnly(other.x(), other.y(), other.z(), other.w()); | 35 return new DOMPointReadOnly(other.x(), other.y(), other.z(), other.w()); |
32 } | 36 } |
33 | 37 |
| 38 DOMPoint* DOMPointReadOnly::matrixTransform(DOMMatrixInit& other, |
| 39 ExceptionState& exceptionState) { |
| 40 DOMMatrixReadOnly* matrix = |
| 41 DOMMatrixReadOnly::fromMatrix(other, exceptionState); |
| 42 |
| 43 if (matrix->is2D() && z() == 0 && w() == 1) { |
| 44 double transformedX = |
| 45 x() * matrix->m11() + y() * matrix->m12() + matrix->m41(); |
| 46 double transformedY = |
| 47 x() * matrix->m12() + y() * matrix->m22() + matrix->m42(); |
| 48 return DOMPoint::create(transformedX, transformedY, 0, 1); |
| 49 } |
| 50 |
| 51 double transformedX = x() * matrix->m11() + y() * matrix->m21() + |
| 52 z() * matrix->m31() + w() * matrix->m41(); |
| 53 double transformedY = x() * matrix->m12() + y() * matrix->m22() + |
| 54 z() * matrix->m32() + w() * matrix->m42(); |
| 55 double transformedZ = x() * matrix->m13() + y() * matrix->m23() + |
| 56 z() * matrix->m33() + w() * matrix->m43(); |
| 57 double transformedW = x() * matrix->m14() + y() * matrix->m24() + |
| 58 z() * matrix->m34() + w() * matrix->m44(); |
| 59 return DOMPoint::create(transformedX, transformedY, transformedZ, |
| 60 transformedW); |
| 61 } |
| 62 |
34 DOMPointReadOnly::DOMPointReadOnly(double x, double y, double z, double w) | 63 DOMPointReadOnly::DOMPointReadOnly(double x, double y, double z, double w) |
35 : m_x(x), m_y(y), m_z(z), m_w(w) {} | 64 : m_x(x), m_y(y), m_z(z), m_w(w) {} |
36 | 65 |
37 } // namespace blink | 66 } // namespace blink |
OLD | NEW |