summaryrefslogtreecommitdiffstats
path: root/base/gfx
diff options
context:
space:
mode:
authoravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-06 20:38:29 +0000
committeravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-06 20:38:29 +0000
commit1924d1048439d9990701a28f8709e01c21a08197 (patch)
tree5557c8c94257ea22ad69a36b6800a9d38a463a4f /base/gfx
parent74873f0b403a944de45c4abb2cd6c8ed5a5f4783 (diff)
downloadchromium_src-1924d1048439d9990701a28f8709e01c21a08197.zip
chromium_src-1924d1048439d9990701a28f8709e01c21a08197.tar.gz
chromium_src-1924d1048439d9990701a28f8709e01c21a08197.tar.bz2
Fixing up the basic set of geometry.
Review URL: http://chrome-reviews.prom.corp.google.com/1211 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@453 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/gfx')
-rw-r--r--base/gfx/point.cc11
-rw-r--r--base/gfx/point.h14
-rw-r--r--base/gfx/rect.cc25
-rw-r--r--base/gfx/rect.h15
-rw-r--r--base/gfx/rect_unittest.cc14
-rw-r--r--base/gfx/size.cc14
-rw-r--r--base/gfx/size.h10
7 files changed, 91 insertions, 12 deletions
diff --git a/base/gfx/point.cc b/base/gfx/point.cc
index 7c435a0..106810a 100644
--- a/base/gfx/point.cc
+++ b/base/gfx/point.cc
@@ -29,7 +29,9 @@
#include "base/gfx/point.h"
+#if defined(OS_WIN)
#include <windows.h>
+#endif
namespace gfx {
@@ -39,6 +41,7 @@ Point::Point() : x_(0), y_(0) {
Point::Point(int x, int y) : x_(x), y_(y) {
}
+#if defined(OS_WIN)
Point::Point(const POINT& point) : x_(point.x), y_(point.y) {
}
@@ -48,5 +51,13 @@ POINT Point::ToPOINT() const {
p.y = y_;
return p;
}
+#elif defined(OS_MACOSX)
+Point::Point(const CGPoint& point) : x_(point.x), y_(point.y) {
+}
+
+CGPoint Point::ToCGPoint() const {
+ return CGPointMake(x_, y_);
+}
+#endif
} // namespace gfx
diff --git a/base/gfx/point.h b/base/gfx/point.h
index 3e09a81..3acb425 100644
--- a/base/gfx/point.h
+++ b/base/gfx/point.h
@@ -30,11 +30,17 @@
#ifndef BASE_GFX_POINT_H__
#define BASE_GFX_POINT_H__
+#include "build/build_config.h"
+
#ifdef UNIT_TEST
#include <iostream>
#endif
+#if defined(OS_WIN)
typedef struct tagPOINT POINT;
+#elif defined(OS_MACOSX)
+#include <ApplicationServices/ApplicationServices.h>
+#endif
namespace gfx {
@@ -45,7 +51,11 @@ class Point {
public:
Point();
Point(int x, int y);
+#if defined(OS_WIN)
explicit Point(const POINT& point);
+#elif defined(OS_MACOSX)
+ explicit Point(const CGPoint& point);
+#endif
~Point() {}
@@ -68,7 +78,11 @@ class Point {
return !(*this == rhs);
}
+#if defined(OS_WIN)
POINT ToPOINT() const;
+#elif defined(OS_MACOSX)
+ CGPoint ToCGPoint() const;
+#endif
private:
int x_;
diff --git a/base/gfx/rect.cc b/base/gfx/rect.cc
index dda7e67..0ee3b6d 100644
--- a/base/gfx/rect.cc
+++ b/base/gfx/rect.cc
@@ -29,7 +29,11 @@
#include "base/gfx/rect.h"
+#if defined(OS_WIN)
#include <windows.h>
+#elif defined(OS_MACOSX)
+#include <CoreGraphics/CGGeometry.h>
+#endif
#include "base/logging.h"
@@ -63,6 +67,7 @@ Rect::Rect(int x, int y, int width, int height)
set_height(height);
}
+#if defined(OS_WIN)
Rect::Rect(const RECT& r)
: origin_(r.left, r.top) {
set_width(r.right - r.left);
@@ -75,6 +80,20 @@ Rect& Rect::operator=(const RECT& r) {
set_height(r.bottom - r.top);
return *this;
}
+#elif defined(OS_MACOSX)
+Rect::Rect(const CGRect& r)
+ : origin_(r.origin.x, r.origin.y) {
+ set_width(r.size.width);
+ set_height(r.size.height);
+}
+
+Rect& Rect::operator=(const CGRect& r) {
+ origin_.SetPoint(r.origin.x, r.origin.y);
+ set_width(r.size.width);
+ set_height(r.size.height);
+ return *this;
+}
+#endif
void Rect::set_width(int width) {
if (width < 0) {
@@ -119,6 +138,7 @@ bool Rect::operator==(const Rect& other) const {
return origin_ == other.origin_ && size_ == other.size_;
}
+#if defined(OS_WIN)
RECT Rect::ToRECT() const {
RECT r;
r.left = x();
@@ -127,6 +147,11 @@ RECT Rect::ToRECT() const {
r.bottom = bottom();
return r;
}
+#elif defined(OS_MACOSX)
+CGRect Rect::ToCGRect() const {
+ return CGRectMake(x(), y(), width(), height());
+}
+#endif
bool Rect::Contains(int point_x, int point_y) const {
return (point_x >= x()) && (point_x < right()) &&
diff --git a/base/gfx/rect.h b/base/gfx/rect.h
index 486f799..d19bf7e 100644
--- a/base/gfx/rect.h
+++ b/base/gfx/rect.h
@@ -40,7 +40,9 @@
#include "base/gfx/size.h"
#include "base/gfx/point.h"
+#if defined(OS_WIN)
typedef struct tagRECT RECT;
+#endif
namespace gfx {
@@ -49,12 +51,20 @@ class Rect {
Rect();
Rect(int width, int height);
Rect(int x, int y, int width, int height);
+#if defined(OS_WIN)
explicit Rect(const RECT& r);
+#elif defined(OS_MACOSX)
+ explicit Rect(const CGRect& r);
+#endif
Rect(const gfx::Point& origin, const gfx::Size& size);
~Rect() {}
+#if defined(OS_WIN)
Rect& operator=(const RECT& r);
+#elif defined(OS_MACOSX)
+ Rect& operator=(const CGRect& r);
+#endif
int x() const { return origin_.x(); }
void set_x(int x) { origin_.set_x(x); }
@@ -93,8 +103,13 @@ class Rect {
return !(*this == other);
}
+#if defined(OS_WIN)
// Construct an equivalent Win32 RECT object.
RECT ToRECT() const;
+#elif defined(OS_MACOSX)
+ // Construct an equivalent CoreGraphics object.
+ 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
diff --git a/base/gfx/rect_unittest.cc b/base/gfx/rect_unittest.cc
index c218cc9..2bfcac2 100644
--- a/base/gfx/rect_unittest.cc
+++ b/base/gfx/rect_unittest.cc
@@ -55,7 +55,7 @@ TEST(RectTest, Contains) {
{0, 0, -10, -10, 0, 0, false},
#endif // NDEBUG
};
- for (int i = 0; i < arraysize(contains_cases); ++i) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(contains_cases); ++i) {
const ContainsCase& value = contains_cases[i];
gfx::Rect rect(value.rect_x, value.rect_y,
value.rect_width, value.rect_height);
@@ -84,7 +84,7 @@ TEST(RectTest, Intersects) {
{ 10, 10, 10, 10, 20, 15, 10, 10, false },
{ 10, 10, 10, 10, 21, 15, 10, 10, false }
};
- for (size_t i = 0; i < arraysize(tests); ++i) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
EXPECT_EQ(tests[i].intersects, r1.Intersects(r2));
@@ -125,7 +125,7 @@ TEST(RectTest, Intersect) {
0, 0, 2, 2,
0, 0, 0, 0 }
};
- for (size_t i = 0; i < arraysize(tests); ++i) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3);
@@ -138,7 +138,7 @@ TEST(RectTest, Intersect) {
}
TEST(RectTest, Union) {
- static const struct {
+ static const struct Test {
int x1; // rect 1
int y1;
int w1;
@@ -174,7 +174,7 @@ TEST(RectTest, Union) {
2, 2, 2, 2,
2, 2, 2, 2 }
};
- for (size_t i = 0; i < arraysize(tests); ++i) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3);
@@ -196,7 +196,7 @@ TEST(RectTest, Equals) {
}
TEST(RectTest, AdjustToFit) {
- static const struct {
+ static const struct Test {
int x1; // source
int y1;
int w1;
@@ -226,7 +226,7 @@ TEST(RectTest, AdjustToFit) {
0, 0, 3, 3,
2, 2, 1, 1 }
};
- for (size_t i = 0; i < arraysize(tests); ++i) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
gfx::Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
gfx::Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
gfx::Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3);
diff --git a/base/gfx/size.cc b/base/gfx/size.cc
index 153c29e..b7c30b3 100644
--- a/base/gfx/size.cc
+++ b/base/gfx/size.cc
@@ -29,21 +29,25 @@
#include "base/gfx/size.h"
+#if defined(OS_WIN)
#include <windows.h>
-
-#include <ostream>
+#elif defined(OS_MACOSX)
+#include <CoreGraphics/CGGeometry.h>
+#endif
namespace gfx {
+#if defined(OS_WIN)
SIZE Size::ToSIZE() const {
SIZE s;
s.cx = width_;
s.cy = height_;
return s;
}
-
-std::ostream& operator<<(std::ostream& out, const gfx::Size& s) {
- return out << s.width() << "x" << s.height();
+#elif defined(OS_MACOSX)
+CGSize Size::ToCGSize() const {
+ return CGSizeMake(width_, height_);
}
+#endif
} // namespace gfx
diff --git a/base/gfx/size.h b/base/gfx/size.h
index cba2e51..c719c2e 100644
--- a/base/gfx/size.h
+++ b/base/gfx/size.h
@@ -30,11 +30,17 @@
#ifndef BASE_GFX_SIZE_H__
#define BASE_GFX_SIZE_H__
+#include "build/build_config.h"
+
#ifdef UNIT_TEST
#include <iostream>
#endif
+#if defined(OS_WIN)
typedef struct tagSIZE SIZE;
+#elif defined(OS_MACOSX)
+#include <ApplicationServices/ApplicationServices.h>
+#endif
namespace gfx {
@@ -71,7 +77,11 @@ class Size {
return !width_ && !height_;
}
+#if defined(OS_WIN)
SIZE ToSIZE() const;
+#elif defined(OS_MACOSX)
+ CGSize ToCGSize() const;
+#endif
private:
int width_;