summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-26 22:10:13 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-26 22:10:13 +0000
commitbe36adf48521bae3965b79a852501c696413f133 (patch)
tree0458f2785af75473570b2604431e3f77b7cd9d88
parentb50ed4828c28ac9b4baad3801a1f9938e913d289 (diff)
downloadchromium_src-be36adf48521bae3965b79a852501c696413f133.zip
chromium_src-be36adf48521bae3965b79a852501c696413f133.tar.gz
chromium_src-be36adf48521bae3965b79a852501c696413f133.tar.bz2
Change Size::IsEmpty() to be consistent with Rect::IsEmpty()
Change Size to not accept negative dimensions to be consistent with Rect. BUG=10992 TEST=base_unittests.exe --gtest_filter=RectTest.IsEmpty Review URL: http://codereview.chromium.org/93131 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14567 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xbase/gfx/rect.cc14
-rwxr-xr-xbase/gfx/rect.h2
-rw-r--r--base/gfx/rect_unittest.cc11
-rw-r--r--base/gfx/size.cc25
-rw-r--r--base/gfx/size.h17
5 files changed, 46 insertions, 23 deletions
diff --git a/base/gfx/rect.cc b/base/gfx/rect.cc
index 003766b..b54c13b 100755
--- a/base/gfx/rect.cc
+++ b/base/gfx/rect.cc
@@ -90,19 +90,9 @@ Rect& Rect::operator=(const GdkRectangle& r) {
#endif
void Rect::set_width(int width) {
- if (width < 0) {
- NOTREACHED();
- width = 0;
- }
-
size_.set_width(width);
}
void Rect::set_height(int height) {
- if (height < 0) {
- NOTREACHED();
- height = 0;
- }
-
size_.set_height(height);
}
@@ -123,10 +113,6 @@ void Rect::Offset(int horizontal, int vertical) {
set_y(y() + vertical);
}
-bool Rect::IsEmpty() const {
- return width() == 0 || height() == 0;
-}
-
bool Rect::operator==(const Rect& other) const {
return origin_ == other.origin_ && size_ == other.size_;
}
diff --git a/base/gfx/rect.h b/base/gfx/rect.h
index 21083b2..16c16c1 100755
--- a/base/gfx/rect.h
+++ b/base/gfx/rect.h
@@ -86,7 +86,7 @@ class Rect {
}
// Returns true if the area of the rectangle is zero.
- bool IsEmpty() const;
+ bool IsEmpty() const { return size_.IsEmpty(); }
bool operator==(const Rect& other) const;
diff --git a/base/gfx/rect_unittest.cc b/base/gfx/rect_unittest.cc
index 31ca6c1..50c789d 100644
--- a/base/gfx/rect_unittest.cc
+++ b/base/gfx/rect_unittest.cc
@@ -267,3 +267,14 @@ TEST(RectTest, Subtract) {
gfx::Rect(5, 5, 20, 30)).Equals(
gfx::Rect(25, 10, 5, 20)));
}
+
+TEST(RectTest, IsEmpty) {
+ EXPECT_TRUE(gfx::Rect(0, 0, 0, 0).IsEmpty());
+ EXPECT_TRUE(gfx::Rect(0, 0, 0, 0).size().IsEmpty());
+ EXPECT_TRUE(gfx::Rect(0, 0, 10, 0).IsEmpty());
+ EXPECT_TRUE(gfx::Rect(0, 0, 10, 0).size().IsEmpty());
+ EXPECT_TRUE(gfx::Rect(0, 0, 0, 10).IsEmpty());
+ EXPECT_TRUE(gfx::Rect(0, 0, 0, 10).size().IsEmpty());
+ EXPECT_FALSE(gfx::Rect(0, 0, 10, 10).IsEmpty());
+ EXPECT_FALSE(gfx::Rect(0, 0, 10, 10).size().IsEmpty());
+}
diff --git a/base/gfx/size.cc b/base/gfx/size.cc
index 0264481..018a42c 100644
--- a/base/gfx/size.cc
+++ b/base/gfx/size.cc
@@ -10,8 +10,16 @@
#include <CoreGraphics/CGGeometry.h>
#endif
+#include "base/logging.h"
+
+
namespace gfx {
+Size::Size(int width, int height) {
+ set_width(width);
+ set_height(height);
+}
+
#if defined(OS_WIN)
SIZE Size::ToSIZE() const {
SIZE s;
@@ -25,4 +33,21 @@ CGSize Size::ToCGSize() const {
}
#endif
+void Size::set_width(int width) {
+ if (width < 0) {
+ NOTREACHED();
+ width = 0;
+ }
+ width_ = width;
+}
+
+void Size::set_height(int height) {
+ if (height < 0) {
+ NOTREACHED();
+ height = 0;
+ }
+ height_ = height;
+}
+
+
} // namespace gfx
diff --git a/base/gfx/size.h b/base/gfx/size.h
index f890a51..a7a471d 100644
--- a/base/gfx/size.h
+++ b/base/gfx/size.h
@@ -23,7 +23,7 @@ namespace gfx {
class Size {
public:
Size() : width_(0), height_(0) {}
- Size(int width, int height) : width_(width), height_(height) {}
+ Size(int width, int height);
~Size() {}
@@ -31,17 +31,17 @@ class Size {
int height() const { return height_; }
void SetSize(int width, int height) {
- width_ = width;
- height_ = height;
+ set_width(width);
+ set_height(height);
}
void Enlarge(int width, int height) {
- width_ += width;
- height_ += height;
+ set_width(width_ + width);
+ set_height(height_ + height);
}
- void set_width(int width) { width_ = width; }
- void set_height(int height) { height_ = height; }
+ void set_width(int width);
+ void set_height(int height);
bool operator==(const Size& s) const {
return width_ == s.width_ && height_ == s.height_;
@@ -52,7 +52,8 @@ class Size {
}
bool IsEmpty() const {
- return !width_ && !height_;
+ // Size doesn't allow negative dimensions, so testing for 0 is enough.
+ return (width_ == 0) || (height_ == 0);
}
#if defined(OS_WIN)