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

Side by Side Diff: third_party/WebKit/Source/core/geometry/DOMQuad.cpp

Issue 2771683005: Revert of Move geometry interface files to geometry directory. (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/geometry/DOMQuad.h"
6
7 #include "bindings/core/v8/V8ObjectBuilder.h"
8 #include "core/geometry/DOMPoint.h"
9 #include "core/geometry/DOMQuadInit.h"
10 #include "core/geometry/DOMRect.h"
11 #include "core/geometry/DOMRectInit.h"
12
13 namespace blink {
14
15 DOMQuad* DOMQuad::create(const DOMPointInit& p1,
16 const DOMPointInit& p2,
17 const DOMPointInit& p3,
18 const DOMPointInit& p4) {
19 return new DOMQuad(p1, p2, p3, p4);
20 }
21
22 DOMQuad* DOMQuad::fromRect(const DOMRectInit& other) {
23 return new DOMQuad(other.x(), other.y(), other.width(), other.height());
24 }
25
26 DOMQuad* DOMQuad::fromQuad(const DOMQuadInit& other) {
27 return new DOMQuad(other.hasP1() ? other.p1() : DOMPointInit(),
28 other.hasP2() ? other.p2() : DOMPointInit(),
29 other.hasP3() ? other.p3() : DOMPointInit(),
30 other.hasP3() ? other.p4() : DOMPointInit());
31 }
32
33 DOMRect* DOMQuad::getBounds() {
34 return DOMRect::create(m_left, m_top, m_right - m_left, m_bottom - m_top);
35 }
36
37 void DOMQuad::calculateBounds() {
38 m_left = std::min(p1()->x(), p2()->x());
39 m_left = std::min(m_left, p3()->x());
40 m_left = std::min(m_left, p4()->x());
41 m_top = std::min(p1()->y(), p2()->y());
42 m_top = std::min(m_top, p3()->y());
43 m_top = std::min(m_top, p4()->y());
44 m_right = std::max(p1()->x(), p2()->x());
45 m_right = std::max(m_right, p3()->x());
46 m_right = std::max(m_right, p4()->x());
47 m_bottom = std::max(p1()->y(), p2()->y());
48 m_bottom = std::max(m_bottom, p3()->y());
49 m_bottom = std::max(m_bottom, p4()->y());
50 }
51
52 DOMQuad::DOMQuad(const DOMPointInit& p1,
53 const DOMPointInit& p2,
54 const DOMPointInit& p3,
55 const DOMPointInit& p4)
56 : m_p1(DOMPoint::fromPoint(p1)),
57 m_p2(DOMPoint::fromPoint(p2)),
58 m_p3(DOMPoint::fromPoint(p3)),
59 m_p4(DOMPoint::fromPoint(p4)) {
60 calculateBounds();
61 }
62
63 DOMQuad::DOMQuad(double x, double y, double width, double height)
64 : m_p1(DOMPoint::create(x, y, 0, 1)),
65 m_p2(DOMPoint::create(x + width, y, 0, 1)),
66 m_p3(DOMPoint::create(x + width, y + height, 0, 1)),
67 m_p4(DOMPoint::create(x, y + height, 0, 1)) {
68 calculateBounds();
69 }
70
71 ScriptValue DOMQuad::toJSONForBinding(ScriptState* scriptState) const {
72 V8ObjectBuilder result(scriptState);
73 result.add("p1", p1());
74 result.add("p2", p2());
75 result.add("p3", p3());
76 result.add("p4", p4());
77 return result.scriptValue();
78 }
79
80 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/geometry/DOMQuad.h ('k') | third_party/WebKit/Source/core/geometry/DOMQuad.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698