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

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

Issue 964333002: Implement DOMQuad of geometry interfaces. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: expected Created 5 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
« 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 2015 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 #include "core/dom/DOMPointInit.h"
9 #include "core/dom/DOMRectInit.h"
10
11 namespace blink {
12
13 DOMQuadPoint* DOMQuadPoint::create(const DOMPointInit& point, Member<DOMQuad> qu ad)
14 {
15 return new DOMQuadPoint(point.x(), point.y(), quad);
16 }
17
18 DOMQuadPoint* DOMQuadPoint::create(double x, double y, Member<DOMQuad> quad)
19 {
20 return new DOMQuadPoint(x, y, quad);
21 }
22
23 DOMQuadPoint::DOMQuadPoint(double x, double y, Member<DOMQuad> quad)
24 : DOMPoint(x, y, 0, 1)
25 , m_quad(quad)
26 {
27 }
28
29 void DOMQuadPoint::setX(double x)
30 {
31 m_x = x;
32 m_quad->updateHorizontalBounds();
33 }
34
35 void DOMQuadPoint::setY(double y)
36 {
37 m_y = y;
38 m_quad->updateVerticalBounds();
39 }
40
41 DOMQuad* DOMQuad::create(const DOMRectInit& rect)
42 {
43 return new DOMQuad(rect);
44 }
45
46 DOMQuad* DOMQuad::create(const DOMPointInit& p1, const DOMPointInit& p2,
47 const DOMPointInit& p3, const DOMPointInit& p4)
48 {
49 return new DOMQuad(p1, p2, p3, p4);
50 }
51
52 DOMQuad::DOMQuad(const DOMRectInit& rect)
53 : m_p1(DOMQuadPoint::create(rect.x(), rect.y(), this))
54 , m_p2(DOMQuadPoint::create(rect.x() + rect.width(), rect.y(), this))
55 , m_p3(DOMQuadPoint::create(rect.x() + rect.width(), rect.y() + rect.height( ), this))
56 , m_p4(DOMQuadPoint::create(rect.x(), rect.y() + rect.height(), this))
57 , m_bounds(DOMRect::create(rect.x(), rect.y(), rect.width(), rect.height()))
58 {
59 }
60
61 DOMQuad::DOMQuad(const DOMPointInit& p1, const DOMPointInit& p2,
62 const DOMPointInit& p3, const DOMPointInit& p4)
63 : m_p1(DOMQuadPoint::create(p1, this))
64 , m_p2(DOMQuadPoint::create(p2, this))
65 , m_p3(DOMQuadPoint::create(p3, this))
66 , m_p4(DOMQuadPoint::create(p4, this))
67 , m_bounds(nullptr)
68 {
69 }
70
71 DOMRectReadOnly* DOMQuad::bounds()
72 {
73 if (!m_bounds) {
74 m_bounds = DOMRect::create();
75 updateHorizontalBounds();
76 updateVerticalBounds();
77 }
78
79 return m_bounds;
80 }
81
82 static inline double min4(double a, double b, double c, double d)
83 {
84 return std::min(std::min(a, b), std::min(c, d));
85 }
86
87 static inline double max4(double a, double b, double c, double d)
88 {
89 return std::max(std::max(a, b), std::max(c, d));
90 }
91
92 void DOMQuad::updateHorizontalBounds()
93 {
94 double left = min4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x());
95 double right = max4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x());
96
97 m_bounds->setX(left);
98 m_bounds->setWidth(right - left);
99 }
100
101 void DOMQuad::updateVerticalBounds()
102 {
103 double top = min4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y());
104 double bottom = max4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y());
105
106 m_bounds->setY(top);
107 m_bounds->setHeight(bottom - top);
108 }
109
110 } // 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