OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/DOMQuad.h" | 5 #include "core/dom/DOMQuad.h" |
6 | 6 |
7 #include "bindings/core/v8/V8ObjectBuilder.h" | 7 #include "bindings/core/v8/V8ObjectBuilder.h" |
8 #include "core/dom/DOMPoint.h" | 8 #include "core/dom/DOMPoint.h" |
| 9 #include "core/dom/DOMQuadInit.h" |
9 #include "core/dom/DOMRectInit.h" | 10 #include "core/dom/DOMRectInit.h" |
10 | 11 |
11 namespace blink { | 12 namespace blink { |
12 | 13 |
13 DOMQuad* DOMQuad::create(const DOMPointInit& p1, | 14 DOMQuad* DOMQuad::create(const DOMPointInit& p1, |
14 const DOMPointInit& p2, | 15 const DOMPointInit& p2, |
15 const DOMPointInit& p3, | 16 const DOMPointInit& p3, |
16 const DOMPointInit& p4) { | 17 const DOMPointInit& p4) { |
17 return new DOMQuad(p1, p2, p3, p4); | 18 return new DOMQuad(p1, p2, p3, p4); |
18 } | 19 } |
19 | 20 |
20 DOMQuad* DOMQuad::fromRect(const DOMRectInit& other) { | 21 DOMQuad* DOMQuad::fromRect(const DOMRectInit& other) { |
21 return new DOMQuad(other.x(), other.y(), other.width(), other.height()); | 22 return new DOMQuad(other.x(), other.y(), other.width(), other.height()); |
22 } | 23 } |
23 | 24 |
| 25 DOMQuad* DOMQuad::fromQuad(const DOMQuadInit& other) { |
| 26 return new DOMQuad(other.hasP1() ? other.p1() : DOMPointInit(), |
| 27 other.hasP2() ? other.p2() : DOMPointInit(), |
| 28 other.hasP3() ? other.p3() : DOMPointInit(), |
| 29 other.hasP3() ? other.p4() : DOMPointInit()); |
| 30 } |
| 31 |
24 DOMQuad::DOMQuad(const DOMPointInit& p1, | 32 DOMQuad::DOMQuad(const DOMPointInit& p1, |
25 const DOMPointInit& p2, | 33 const DOMPointInit& p2, |
26 const DOMPointInit& p3, | 34 const DOMPointInit& p3, |
27 const DOMPointInit& p4) | 35 const DOMPointInit& p4) |
28 : m_p1(DOMPoint::fromPoint(p1)), | 36 : m_p1(DOMPoint::fromPoint(p1)), |
29 m_p2(DOMPoint::fromPoint(p2)), | 37 m_p2(DOMPoint::fromPoint(p2)), |
30 m_p3(DOMPoint::fromPoint(p3)), | 38 m_p3(DOMPoint::fromPoint(p3)), |
31 m_p4(DOMPoint::fromPoint(p4)) {} | 39 m_p4(DOMPoint::fromPoint(p4)) {} |
32 | 40 |
33 DOMQuad::DOMQuad(double x, double y, double width, double height) | 41 DOMQuad::DOMQuad(double x, double y, double width, double height) |
34 : m_p1(DOMPoint::create(x, y, 0, 1)), | 42 : m_p1(DOMPoint::create(x, y, 0, 1)), |
35 m_p2(DOMPoint::create(x + width, y, 0, 1)), | 43 m_p2(DOMPoint::create(x + width, y, 0, 1)), |
36 m_p3(DOMPoint::create(x + width, y + height, 0, 1)), | 44 m_p3(DOMPoint::create(x + width, y + height, 0, 1)), |
37 m_p4(DOMPoint::create(x, y + height, 0, 1)) {} | 45 m_p4(DOMPoint::create(x, y + height, 0, 1)) {} |
38 | 46 |
39 ScriptValue DOMQuad::toJSONForBinding(ScriptState* scriptState) const { | 47 ScriptValue DOMQuad::toJSONForBinding(ScriptState* scriptState) const { |
40 V8ObjectBuilder result(scriptState); | 48 V8ObjectBuilder result(scriptState); |
41 result.add("p1", p1()); | 49 result.add("p1", p1()); |
42 result.add("p2", p2()); | 50 result.add("p2", p2()); |
43 result.add("p3", p3()); | 51 result.add("p3", p3()); |
44 result.add("p4", p4()); | 52 result.add("p4", p4()); |
45 return result.scriptValue(); | 53 return result.scriptValue(); |
46 } | 54 } |
47 | 55 |
48 } // namespace blink | 56 } // namespace blink |
OLD | NEW |