Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / geometry / rect_f.h
index fe20965..dc233a7 100644 (file)
@@ -9,7 +9,6 @@
 #include <string>
 
 #include "ui/gfx/geometry/point_f.h"
-#include "ui/gfx/geometry/rect_base.h"
 #include "ui/gfx/geometry/size_f.h"
 #include "ui/gfx/geometry/vector2d_f.h"
 
@@ -18,30 +17,138 @@ namespace gfx {
 class InsetsF;
 
 // A floating version of gfx::Rect.
-class GFX_EXPORT RectF
-    : public RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float> {
+class GFX_EXPORT RectF {
  public:
-  RectF()
-      : RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>
-            (SizeF()) {}
+  RectF() {}
+  RectF(float width, float height) : size_(width, height) {}
+  RectF(float x, float y, float width, float height)
+      : origin_(x, y), size_(width, height) {}
+  explicit RectF(const SizeF& size) : size_(size) {}
+  RectF(const PointF& origin, const SizeF& size)
+      : origin_(origin), size_(size) {}
 
-  RectF(float width, float height)
-      : RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>
-            (SizeF(width, height)) {}
+  ~RectF() {}
 
-  RectF(float x, float y, float width, float height)
-      : RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>
-            (PointF(x, y), SizeF(width, height)) {}
+  float x() const { return origin_.x(); }
+  void set_x(float x) { origin_.set_x(x); }
 
-  explicit RectF(const SizeF& size)
-      : RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>
-            (size) {}
+  float y() const { return origin_.y(); }
+  void set_y(float y) { origin_.set_y(y); }
 
-  RectF(const PointF& origin, const SizeF& size)
-      : RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>
-            (origin, size) {}
+  float width() const { return size_.width(); }
+  void set_width(float width) { size_.set_width(width); }
 
-  ~RectF() {}
+  float height() const { return size_.height(); }
+  void set_height(float height) { size_.set_height(height); }
+
+  const PointF& origin() const { return origin_; }
+  void set_origin(const PointF& origin) { origin_ = origin; }
+
+  const SizeF& size() const { return size_; }
+  void set_size(const SizeF& size) { size_ = size; }
+
+  float right() const { return x() + width(); }
+  float bottom() const { return y() + height(); }
+
+  PointF top_right() const { return PointF(right(), y()); }
+  PointF bottom_left() const { return PointF(x(), bottom()); }
+  PointF bottom_right() const { return PointF(right(), bottom()); }
+
+  Vector2dF OffsetFromOrigin() const { return Vector2dF(x(), y()); }
+
+  void SetRect(float x, float y, float width, float height) {
+    origin_.SetPoint(x, y);
+    size_.SetSize(width, height);
+  }
+
+  // Shrink the rectangle by a horizontal and vertical distance on all sides.
+  void Inset(float horizontal, float vertical) {
+    Inset(horizontal, vertical, horizontal, vertical);
+  }
+
+  // Shrink the rectangle by the given insets.
+  void Inset(const InsetsF& insets);
+
+  // Shrink the rectangle by the specified amount on each side.
+  void Inset(float left, float top, float right, float bottom);
+
+  // Move the rectangle by a horizontal and vertical distance.
+  void Offset(float horizontal, float vertical);
+  void Offset(const Vector2dF& distance) { Offset(distance.x(), distance.y()); }
+  void operator+=(const Vector2dF& offset);
+  void operator-=(const Vector2dF& offset);
+
+  InsetsF InsetsFrom(const RectF& inner) const;
+
+  // Returns true if the area of the rectangle is zero.
+  bool IsEmpty() const { return size_.IsEmpty(); }
+
+  // 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 RectF& other) const;
+
+  // 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(float point_x, float point_y) const;
+
+  // Returns true if the specified point is contained by this rectangle.
+  bool Contains(const PointF& point) const {
+    return Contains(point.x(), point.y());
+  }
+
+  // Returns true if this rectangle contains the specified rectangle.
+  bool Contains(const RectF& rect) const;
+
+  // Returns true if this rectangle intersects the specified rectangle.
+  // An empty rectangle doesn't intersect any rectangle.
+  bool Intersects(const RectF& rect) const;
+
+  // Computes the intersection of this rectangle with the given rectangle.
+  void Intersect(const RectF& rect);
+
+  // Computes the union of this rectangle with the given rectangle.  The union
+  // is the smallest rectangle containing both rectangles.
+  void Union(const RectF& rect);
+
+  // Computes the rectangle resulting from subtracting |rect| from |*this|,
+  // i.e. the bounding rect of |Region(*this) - Region(rect)|.
+  void Subtract(const RectF& rect);
+
+  // Fits as much of the receiving rectangle into the supplied rectangle as
+  // possible, becoming 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.
+  void AdjustToFit(const RectF& rect);
+
+  // Returns the center of this rectangle.
+  PointF CenterPoint() const;
+
+  // Becomes a rectangle that has the same center point but with a size capped
+  // at given |size|.
+  void ClampToCenteredSize(const SizeF& size);
+
+  // Splits |this| in two halves, |left_half| and |right_half|.
+  void SplitVertically(RectF* left_half, RectF* 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 RectF& rect) const;
+
+  // Returns the manhattan distance from the rect to the point. If the point is
+  // inside the rect, returns 0.
+  float ManhattanDistanceToPoint(const PointF& point) const;
+
+  // Returns the manhattan distance between the contents of this rect and the
+  // contents of the given rect. That is, if the intersection of the two rects
+  // is non-empty then the function returns 0. If the rects share a side, it
+  // returns the smallest non-zero value appropriate for float.
+  float ManhattanInternalDistance(const RectF& rect) const;
 
   // Scales the rectangle by |scale|.
   void Scale(float scale) {
@@ -60,6 +167,10 @@ class GFX_EXPORT RectF
   bool IsExpressibleAsRect() const;
 
   std::string ToString() const;
+
+ private:
+  PointF origin_;
+  SizeF size_;
 };
 
 inline bool operator==(const RectF& lhs, const RectF& rhs) {
@@ -105,10 +216,6 @@ inline RectF ScaleRect(const RectF& r, float scale) {
 // contained within the rect, because they will appear on one of these edges.
 GFX_EXPORT RectF BoundingRect(const PointF& p1, const PointF& p2);
 
-#if !defined(COMPILER_MSVC) && !defined(__native_client__)
-extern template class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>;
-#endif
-
 // This is declared here for use in gtest-based unit tests but is defined in
 // the gfx_test_support target. Depend on that to use this in your unit test.
 // This should not be used in production code - call ToString() instead.