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/DOMQuadInit.h" |
10 #include "core/dom/DOMRect.h" | |
10 #include "core/dom/DOMRectInit.h" | 11 #include "core/dom/DOMRectInit.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 DOMQuad* DOMQuad::create(const DOMPointInit& p1, | 15 DOMQuad* DOMQuad::create(const DOMPointInit& p1, |
15 const DOMPointInit& p2, | 16 const DOMPointInit& p2, |
16 const DOMPointInit& p3, | 17 const DOMPointInit& p3, |
17 const DOMPointInit& p4) { | 18 const DOMPointInit& p4) { |
18 return new DOMQuad(p1, p2, p3, p4); | 19 return new DOMQuad(p1, p2, p3, p4); |
19 } | 20 } |
20 | 21 |
21 DOMQuad* DOMQuad::fromRect(const DOMRectInit& other) { | 22 DOMQuad* DOMQuad::fromRect(const DOMRectInit& other) { |
22 return new DOMQuad(other.x(), other.y(), other.width(), other.height()); | 23 return new DOMQuad(other.x(), other.y(), other.width(), other.height()); |
23 } | 24 } |
24 | 25 |
25 DOMQuad* DOMQuad::fromQuad(const DOMQuadInit& other) { | 26 DOMQuad* DOMQuad::fromQuad(const DOMQuadInit& other) { |
26 return new DOMQuad(other.hasP1() ? other.p1() : DOMPointInit(), | 27 return new DOMQuad(other.hasP1() ? other.p1() : DOMPointInit(), |
27 other.hasP2() ? other.p2() : DOMPointInit(), | 28 other.hasP2() ? other.p2() : DOMPointInit(), |
28 other.hasP3() ? other.p3() : DOMPointInit(), | 29 other.hasP3() ? other.p3() : DOMPointInit(), |
29 other.hasP3() ? other.p4() : DOMPointInit()); | 30 other.hasP3() ? other.p4() : DOMPointInit()); |
30 } | 31 } |
31 | 32 |
33 DOMRect* DOMQuad::getBounds() { | |
34 double left = std::min(p1()->x(), p2()->x()); | |
zino
2017/02/13 15:23:18
This might be inefficiency. We should cache the bo
| |
35 left = std::min(left, p3()->x()); | |
36 left = std::min(left, p4()->x()); | |
37 double top = std::min(p1()->y(), p2()->y()); | |
38 top = std::min(top, p3()->y()); | |
39 top = std::min(top, p4()->y()); | |
40 double right = std::max(p1()->x(), p2()->x()); | |
41 right = std::max(right, p3()->x()); | |
42 right = std::max(right, p4()->x()); | |
43 double bottom = std::max(p1()->y(), p2()->y()); | |
44 bottom = std::max(bottom, p3()->y()); | |
45 bottom = std::max(bottom, p4()->y()); | |
46 return DOMRect::create(left, top, right - left, bottom - top); | |
47 } | |
48 | |
32 DOMQuad::DOMQuad(const DOMPointInit& p1, | 49 DOMQuad::DOMQuad(const DOMPointInit& p1, |
33 const DOMPointInit& p2, | 50 const DOMPointInit& p2, |
34 const DOMPointInit& p3, | 51 const DOMPointInit& p3, |
35 const DOMPointInit& p4) | 52 const DOMPointInit& p4) |
36 : m_p1(DOMPoint::fromPoint(p1)), | 53 : m_p1(DOMPoint::fromPoint(p1)), |
37 m_p2(DOMPoint::fromPoint(p2)), | 54 m_p2(DOMPoint::fromPoint(p2)), |
38 m_p3(DOMPoint::fromPoint(p3)), | 55 m_p3(DOMPoint::fromPoint(p3)), |
39 m_p4(DOMPoint::fromPoint(p4)) {} | 56 m_p4(DOMPoint::fromPoint(p4)) {} |
40 | 57 |
41 DOMQuad::DOMQuad(double x, double y, double width, double height) | 58 DOMQuad::DOMQuad(double x, double y, double width, double height) |
42 : m_p1(DOMPoint::create(x, y, 0, 1)), | 59 : m_p1(DOMPoint::create(x, y, 0, 1)), |
43 m_p2(DOMPoint::create(x + width, y, 0, 1)), | 60 m_p2(DOMPoint::create(x + width, y, 0, 1)), |
44 m_p3(DOMPoint::create(x + width, y + height, 0, 1)), | 61 m_p3(DOMPoint::create(x + width, y + height, 0, 1)), |
45 m_p4(DOMPoint::create(x, y + height, 0, 1)) {} | 62 m_p4(DOMPoint::create(x, y + height, 0, 1)) {} |
46 | 63 |
47 ScriptValue DOMQuad::toJSONForBinding(ScriptState* scriptState) const { | 64 ScriptValue DOMQuad::toJSONForBinding(ScriptState* scriptState) const { |
48 V8ObjectBuilder result(scriptState); | 65 V8ObjectBuilder result(scriptState); |
49 result.add("p1", p1()); | 66 result.add("p1", p1()); |
50 result.add("p2", p2()); | 67 result.add("p2", p2()); |
51 result.add("p3", p3()); | 68 result.add("p3", p3()); |
52 result.add("p4", p4()); | 69 result.add("p4", p4()); |
53 return result.scriptValue(); | 70 return result.scriptValue(); |
54 } | 71 } |
55 | 72 |
56 } // namespace blink | 73 } // namespace blink |
OLD | NEW |