summaryrefslogtreecommitdiffstats
path: root/ui/gfx/rect.h
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx/rect.h')
-rw-r--r--ui/gfx/rect.h121
1 files changed, 3 insertions, 118 deletions
diff --git a/ui/gfx/rect.h b/ui/gfx/rect.h
index 4343825..804754b 100644
--- a/ui/gfx/rect.h
+++ b/ui/gfx/rect.h
@@ -16,6 +16,7 @@
#include <string>
#include "ui/gfx/point.h"
+#include "ui/gfx/rect_base.h"
#include "ui/gfx/size.h"
#if defined(OS_WIN)
@@ -28,7 +29,7 @@ namespace gfx {
class Insets;
-class UI_EXPORT Rect {
+class UI_EXPORT Rect : public RectBase<Rect, Point, Size, Insets, int> {
public:
Rect();
Rect(int width, int height);
@@ -43,7 +44,7 @@ class UI_EXPORT Rect {
explicit Rect(const gfx::Size& size);
Rect(const gfx::Point& origin, const gfx::Size& size);
- ~Rect();
+ virtual ~Rect();
#if defined(OS_WIN)
Rect& operator=(const RECT& r);
@@ -53,63 +54,6 @@ class UI_EXPORT Rect {
Rect& operator=(const GdkRectangle& r);
#endif
- int x() const { return origin_.x(); }
- void set_x(int x) { origin_.set_x(x); }
-
- int y() const { return origin_.y(); }
- void set_y(int y) { origin_.set_y(y); }
-
- int width() const { return size_.width(); }
- void set_width(int width) { size_.set_width(width); }
-
- int height() const { return size_.height(); }
- void set_height(int height) { size_.set_height(height); }
-
- const gfx::Point& origin() const { return origin_; }
- void set_origin(const gfx::Point& origin) { origin_ = origin; }
-
- const gfx::Size& size() const { return size_; }
- void set_size(const gfx::Size& size) { size_ = size; }
-
- int right() const { return x() + width(); }
- int bottom() const { return y() + height(); }
-
- void SetRect(int x, int y, int width, int height);
-
- // Shrink the rectangle by a horizontal and vertical distance on all sides.
- void Inset(int horizontal, int vertical) {
- Inset(horizontal, vertical, horizontal, vertical);
- }
-
- // Shrink the rectangle by the given insets.
- void Inset(const gfx::Insets& insets);
-
- // Shrink the rectangle by the specified amount on each side.
- void Inset(int left, int top, int right, int bottom);
-
- // Move the rectangle by a horizontal and vertical distance.
- void Offset(int horizontal, int vertical);
- void Offset(const gfx::Point& point) {
- Offset(point.x(), point.y());
- }
-
- // Returns true if the area of the rectangle is zero.
- bool IsEmpty() const { return size_.IsEmpty(); }
-
- bool operator==(const Rect& other) const;
-
- bool operator!=(const Rect& other) const {
- return !(*this == other);
- }
-
- // A rect is less than another rect if its origin is less than
- // the other rect's origin. If the origins are equal, then the
- // shortest rect is less than the other. If the origin and the
- // height are equal, then the narrowest rect is less than.
- // This comparison is required to use Rects in sets, or sorted
- // vectors.
- bool operator<(const Rect& other) const;
-
#if defined(OS_WIN)
// Construct an equivalent Win32 RECT object.
RECT ToRECT() const;
@@ -120,66 +64,7 @@ class UI_EXPORT Rect {
CGRect ToCGRect() const;
#endif
- // Returns true if the point identified by point_x and point_y falls inside
- // this rectangle. The point (x, y) is inside the rectangle, but the
- // point (x + width, y + height) is not.
- bool Contains(int point_x, int point_y) const;
-
- // Returns true if the specified point is contained by this rectangle.
- bool Contains(const gfx::Point& point) const {
- return Contains(point.x(), point.y());
- }
-
- // Returns true if this rectangle contains the specified rectangle.
- bool Contains(const Rect& rect) const;
-
- // Returns true if this rectangle intersects the specified rectangle.
- bool Intersects(const Rect& rect) const;
-
- // Computes the intersection of this rectangle with the given rectangle.
- Rect Intersect(const Rect& rect) const;
-
- // Computes the union of this rectangle with the given rectangle. The union
- // is the smallest rectangle containing both rectangles.
- Rect Union(const Rect& rect) const;
-
- // Computes the rectangle resulting from subtracting |rect| from |this|. If
- // |rect| does not intersect completely in either the x- or y-direction, then
- // |*this| is returned. If |rect| contains |this|, then an empty Rect is
- // returned.
- Rect Subtract(const Rect& rect) const;
-
- // Returns true if this rectangle equals that of the supplied rectangle.
- bool Equals(const Rect& rect) const {
- return *this == rect;
- }
-
- // Fits as much of the receiving rectangle into the supplied rectangle as
- // possible, returning the result. For example, if the receiver had
- // a x-location of 2 and a width of 4, and the supplied rectangle had
- // an x-location of 0 with a width of 5, the returned rectangle would have
- // an x-location of 1 with a width of 4.
- Rect AdjustToFit(const Rect& rect) const;
-
- // Returns the center of this rectangle.
- Point CenterPoint() const;
-
- // Return a rectangle that has the same center point but with a size capped
- // at given |size|.
- Rect Center(const gfx::Size& size) const;
-
- // Splits |this| in two halves, |left_half| and |right_half|.
- void SplitVertically(gfx::Rect* left_half, gfx::Rect* right_half) const;
-
- // Returns true if this rectangle shares an entire edge (i.e., same width or
- // same height) with the given rectangle, and the rectangles do not overlap.
- bool SharesEdgeWith(const gfx::Rect& rect) const;
-
std::string ToString() const;
-
- private:
- gfx::Point origin_;
- gfx::Size size_;
};
} // namespace gfx