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

Side by Side Diff: Source/core/dom/DOMQuad.cpp

Issue 412373003: Implement DOMQuad of geometry interfaces. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: expected.txt Created 6 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 unified diff | Download patch
« no previous file with comments | « Source/core/dom/DOMQuad.h ('k') | Source/core/dom/DOMQuad.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/dom/DOMQuad.h"
7
8 namespace blink {
9
10 DOMQuadPoint* DOMQuadPoint::create(DOMPointInit& point, Member<DOMQuad> quad)
11 {
12 double x = 0;
13 double y = 0;
14
15 if (!DictionaryHelper::get(point, "x", x))
16 x = 0;
17 if (!DictionaryHelper::get(point, "y", y))
18 y = 0;
19
20 return new DOMQuadPoint(x, y, quad);
21 }
22
23 DOMQuadPoint* DOMQuadPoint::create(double x, double y, Member<DOMQuad> quad)
24 {
25 return new DOMQuadPoint(x, y, quad);
26 }
27
28 DOMQuadPoint::DOMQuadPoint(double x, double y, Member<DOMQuad> quad)
29 : DOMPoint(x, y, 0, 1)
30 , m_quad(quad)
31 {
32 }
33
34 void DOMQuadPoint::setX(double x)
35 {
36 m_x = x;
37 m_quad->updateHorizontalBounds();
38 }
39
40 void DOMQuadPoint::setY(double y)
41 {
42 m_y = y;
43 m_quad->updateVerticalBounds();
44 }
45
46 void DOMQuadPoint::trace(Visitor* visitor)
47 {
48 DOMPoint::trace(visitor);
49 visitor->trace(m_quad);
50 }
51
52 DOMQuad* DOMQuad::create(DOMPointInit& p1, DOMPointInit& p2, DOMPointInit& p3, D OMPointInit& p4)
53 {
54 return new DOMQuad(p1, p2, p3, p4);
55 }
56
57 DOMQuad* DOMQuad::create(DOMRectInit& rect)
58 {
59 double x = 0;
60 double y = 0;
61 double width = 0;
62 double height = 0;
63
64 if (!DictionaryHelper::get(rect, "x", x))
65 x = 0;
66 if (!DictionaryHelper::get(rect, "y", y))
67 y = 0;
68 if (!DictionaryHelper::get(rect, "width", width))
69 width = 0;
70 if (!DictionaryHelper::get(rect, "height", height))
71 height = 0;
72
73 return new DOMQuad(x, y, width, height);
74 }
75
76 DOMQuad::DOMQuad(double x, double y, double width, double height)
77 : m_p1(DOMQuadPoint::create(x, y, this))
78 , m_p2(DOMQuadPoint::create(x + width, y, this))
79 , m_p3(DOMQuadPoint::create(x + width, y + height, this))
80 , m_p4(DOMQuadPoint::create(x, y + height, this))
81 , m_bounds(DOMRect::create(x, y, width, height))
82 {
83 }
84
85 DOMQuad::DOMQuad(DOMPointInit& p1, DOMPointInit& p2,
86 DOMPointInit& p3, DOMPointInit& p4)
87 : m_p1(DOMQuadPoint::create(p1, this))
88 , m_p2(DOMQuadPoint::create(p2, this))
89 , m_p3(DOMQuadPoint::create(p3, this))
90 , m_p4(DOMQuadPoint::create(p4, this))
91 , m_bounds(nullptr)
92 {
93 }
94
95 static inline double min4(double a, double b, double c, double d)
96 {
97 return std::min(std::min(a, b), std::min(c, d));
98 }
99
100 static inline double max4(double a, double b, double c, double d)
101 {
102 return std::max(std::max(a, b), std::max(c, d));
103 }
104
105 DOMRectReadOnly* DOMQuad::bounds()
106 {
107 if (!m_bounds) {
108 m_bounds = DOMRect::create();
109 updateHorizontalBounds();
110 updateVerticalBounds();
111 }
112
113 return m_bounds.get();
114 }
115
116 void DOMQuad::updateHorizontalBounds()
117 {
118 double left = min4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x());
119 double right = max4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x());
120
121 m_bounds->setX(left);
122 m_bounds->setWidth(right - left);
123 }
124
125 void DOMQuad::updateVerticalBounds()
126 {
127 double top = min4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y());
128 double bottom = max4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y());
129
130 m_bounds->setY(top);
131 m_bounds->setHeight(bottom - top);
132 }
133
134 void DOMQuad::trace(Visitor* visitor)
135 {
136 visitor->trace(m_p1);
137 visitor->trace(m_p2);
138 visitor->trace(m_p3);
139 visitor->trace(m_p4);
140 visitor->trace(m_bounds);
141 }
142
143 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/DOMQuad.h ('k') | Source/core/dom/DOMQuad.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698