File: layout_point.h

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (221 lines) | stat: -rw-r--r-- 7,526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright (c) 2012, Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_LAYOUT_POINT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_LAYOUT_POINT_H_

#include <iosfwd>
#include "third_party/blink/renderer/platform/geometry/double_point.h"
#include "third_party/blink/renderer/platform/geometry/float_point.h"
#include "third_party/blink/renderer/platform/geometry/layout_size.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"

namespace blink {

class PLATFORM_EXPORT LayoutPoint {
  DISALLOW_NEW();

 public:
  constexpr LayoutPoint() = default;
  constexpr LayoutPoint(LayoutUnit x, LayoutUnit y) : x_(x), y_(y) {}
  LayoutPoint(int x, int y) : x_(LayoutUnit(x)), y_(LayoutUnit(y)) {}
  LayoutPoint(const IntPoint& point) : x_(point.X()), y_(point.Y()) {}
  explicit LayoutPoint(const FloatPoint& point)
      : x_(point.X()), y_(point.Y()) {}
  explicit LayoutPoint(const DoublePoint& point)
      : x_(point.X()), y_(point.Y()) {}
  constexpr explicit LayoutPoint(const LayoutSize& size)
      : x_(size.Width()), y_(size.Height()) {}

  static constexpr LayoutPoint Zero() { return LayoutPoint(); }

  constexpr LayoutUnit X() const { return x_; }
  constexpr LayoutUnit Y() const { return y_; }

  void SetX(LayoutUnit x) { x_ = x; }
  void SetY(LayoutUnit y) { y_ = y; }

  void Move(const LayoutSize& s) { Move(s.Width(), s.Height()); }
  void Move(const IntSize& s) { Move(s.Width(), s.Height()); }
  void MoveBy(const LayoutPoint& offset) { Move(offset.X(), offset.Y()); }
  void Move(int dx, int dy) { Move(LayoutUnit(dx), LayoutUnit(dy)); }
  void Move(LayoutUnit dx, LayoutUnit dy) {
    x_ += dx;
    y_ += dy;
  }
  void Scale(float sx, float sy) {
    x_ *= sx;
    y_ *= sy;
  }

  LayoutPoint ExpandedTo(const LayoutPoint&) const;
  LayoutPoint ShrunkTo(const LayoutPoint&) const;

  void ClampNegativeToZero() { *this = ExpandedTo(Zero()); }

  LayoutPoint TransposedPoint() const { return LayoutPoint(y_, x_); }

  String ToString() const;

 private:
  LayoutUnit x_, y_;
};

ALWAYS_INLINE LayoutPoint& operator+=(LayoutPoint& a, const LayoutSize& b) {
  a.Move(b.Width(), b.Height());
  return a;
}

ALWAYS_INLINE LayoutPoint& operator+=(LayoutPoint& a, const LayoutPoint& b) {
  a.Move(b.X(), b.Y());
  return a;
}

inline LayoutPoint& operator+=(LayoutPoint& a, const IntSize& b) {
  a.Move(b.Width(), b.Height());
  return a;
}

ALWAYS_INLINE LayoutPoint& operator-=(LayoutPoint& a, const LayoutPoint& b) {
  a.Move(-b.X(), -b.Y());
  return a;
}

ALWAYS_INLINE LayoutPoint& operator-=(LayoutPoint& a, const LayoutSize& b) {
  a.Move(-b.Width(), -b.Height());
  return a;
}

inline LayoutPoint& operator-=(LayoutPoint& a, const IntSize& b) {
  a.Move(-b.Width(), -b.Height());
  return a;
}

inline LayoutPoint operator+(const LayoutPoint& a, const LayoutSize& b) {
  return LayoutPoint(a.X() + b.Width(), a.Y() + b.Height());
}

ALWAYS_INLINE LayoutPoint operator+(const LayoutPoint& a,
                                    const LayoutPoint& b) {
  return LayoutPoint(a.X() + b.X(), a.Y() + b.Y());
}

ALWAYS_INLINE LayoutSize operator-(const LayoutPoint& a, const LayoutPoint& b) {
  return LayoutSize(a.X() - b.X(), a.Y() - b.Y());
}

ALWAYS_INLINE LayoutSize operator-(const LayoutPoint& a, const IntPoint& b) {
  return LayoutSize(a.X() - b.X(), a.Y() - b.Y());
}

inline LayoutPoint operator-(const LayoutPoint& a, const LayoutSize& b) {
  return LayoutPoint(a.X() - b.Width(), a.Y() - b.Height());
}

inline LayoutPoint operator-(const LayoutPoint& a, const IntSize& b) {
  return LayoutPoint(a.X() - b.Width(), a.Y() - b.Height());
}

inline LayoutPoint operator-(const LayoutPoint& point) {
  return LayoutPoint(-point.X(), -point.Y());
}

constexpr ALWAYS_INLINE bool operator==(const LayoutPoint& a,
                                        const LayoutPoint& b) {
  return a.X() == b.X() && a.Y() == b.Y();
}

constexpr bool operator!=(const LayoutPoint& a, const LayoutPoint& b) {
  return !(a == b);
}

constexpr inline LayoutPoint ToPoint(const LayoutSize& size) {
  return LayoutPoint(size.Width(), size.Height());
}

constexpr inline LayoutPoint ToLayoutPoint(const LayoutSize& p) {
  return LayoutPoint(p.Width(), p.Height());
}

constexpr inline LayoutSize ToSize(const LayoutPoint& a) {
  return LayoutSize(a.X(), a.Y());
}

inline IntPoint FlooredIntPoint(const LayoutPoint& point) {
  return IntPoint(point.X().Floor(), point.Y().Floor());
}

inline IntPoint RoundedIntPoint(const LayoutPoint& point) {
  return IntPoint(point.X().Round(), point.Y().Round());
}

inline IntPoint RoundedIntPoint(const LayoutSize& size) {
  return IntPoint(size.Width().Round(), size.Height().Round());
}

inline IntPoint CeiledIntPoint(const LayoutPoint& point) {
  return IntPoint(point.X().Ceil(), point.Y().Ceil());
}

inline LayoutPoint FlooredLayoutPoint(const FloatPoint& p) {
  return LayoutPoint(LayoutUnit::FromFloatFloor(p.X()),
                     LayoutUnit::FromFloatFloor(p.Y()));
}

inline LayoutPoint CeiledLayoutPoint(const FloatPoint& p) {
  return LayoutPoint(LayoutUnit::FromFloatCeil(p.X()),
                     LayoutUnit::FromFloatCeil(p.Y()));
}

inline IntSize PixelSnappedIntSize(const LayoutSize& s, const LayoutPoint& p) {
  return IntSize(SnapSizeToPixel(s.Width(), p.X()),
                 SnapSizeToPixel(s.Height(), p.Y()));
}

inline IntSize RoundedIntSize(const LayoutPoint& p) {
  return IntSize(p.X().Round(), p.Y().Round());
}

inline LayoutSize ToLayoutSize(const LayoutPoint& p) {
  return LayoutSize(p.X(), p.Y());
}

inline LayoutPoint FlooredLayoutPoint(const FloatSize& s) {
  return FlooredLayoutPoint(FloatPoint(s));
}

PLATFORM_EXPORT std::ostream& operator<<(std::ostream&, const LayoutPoint&);
PLATFORM_EXPORT WTF::TextStream& operator<<(WTF::TextStream&,
                                            const LayoutPoint&);

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_LAYOUT_POINT_H_