Remove WebKitTestRunner::setClientWindowRect.
[chromium-blink-merge.git] / ui / gfx / point_base.h
blobd7a3951913e904d77d6ae84a81f0ce974a2e84c2
1 // Copyright (c) 2012 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.
5 #ifndef UI_GFX_POINT_BASE_H_
6 #define UI_GFX_POINT_BASE_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "build/build_config.h"
12 #include "ui/gfx/gfx_export.h"
14 namespace gfx {
16 // A point has an x and y coordinate.
17 template<typename Class, typename Type, typename VectorClass>
18 class GFX_EXPORT PointBase {
19 public:
20 Type x() const { return x_; }
21 Type y() const { return y_; }
23 void SetPoint(Type x, Type y) {
24 x_ = x;
25 y_ = y;
28 void set_x(Type x) { x_ = x; }
29 void set_y(Type y) { y_ = y; }
31 void Offset(Type delta_x, Type delta_y) {
32 x_ += delta_x;
33 y_ += delta_y;
36 void operator+=(const VectorClass& vector) {
37 x_ += vector.x();
38 y_ += vector.y();
41 void operator-=(const VectorClass& vector) {
42 x_ -= vector.x();
43 y_ -= vector.y();
46 void SetToMin(const Class& other) {
47 x_ = x_ <= other.x_ ? x_ : other.x_;
48 y_ = y_ <= other.y_ ? y_ : other.y_;
51 void SetToMax(const Class& other) {
52 x_ = x_ >= other.x_ ? x_ : other.x_;
53 y_ = y_ >= other.y_ ? y_ : other.y_;
56 bool IsOrigin() const {
57 return x_ == 0 && y_ == 0;
60 VectorClass OffsetFromOrigin() const {
61 return VectorClass(x_, y_);
64 // A point is less than another point if its y-value is closer
65 // to the origin. If the y-values are the same, then point with
66 // the x-value closer to the origin is considered less than the
67 // other.
68 // This comparison is required to use Point in sets, or sorted
69 // vectors.
70 bool operator<(const Class& rhs) const {
71 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
74 protected:
75 PointBase(Type x, Type y) : x_(x), y_(y) {}
76 // Destructor is intentionally made non virtual and protected.
77 // Do not make this public.
78 ~PointBase() {}
80 private:
81 Type x_;
82 Type y_;
85 } // namespace gfx
87 #endif // UI_GFX_POINT_BASE_H_