diff options
-rw-r--r-- | chrome/browser/notifications/balloon_collection_impl.cc | 2 | ||||
-rw-r--r-- | content/renderer/paint_aggregator.cc | 3 | ||||
-rw-r--r-- | ui/base/win/hwnd_util.cc | 2 | ||||
-rw-r--r-- | ui/gfx/point.h | 10 | ||||
-rw-r--r-- | ui/gfx/point_base.h | 8 | ||||
-rw-r--r-- | ui/gfx/point_f.h | 8 | ||||
-rw-r--r-- | ui/gfx/point_unittest.cc | 31 | ||||
-rw-r--r-- | ui/gfx/rect.h | 13 | ||||
-rw-r--r-- | ui/gfx/rect_base.h | 11 | ||||
-rw-r--r-- | ui/gfx/rect_base_impl.h | 10 | ||||
-rw-r--r-- | ui/gfx/rect_f.h | 8 | ||||
-rw-r--r-- | ui/gfx/rect_unittest.cc | 79 | ||||
-rw-r--r-- | ui/gfx/size.h | 10 | ||||
-rw-r--r-- | ui/gfx/size_base.h | 8 | ||||
-rw-r--r-- | ui/gfx/size_f.h | 8 | ||||
-rw-r--r-- | ui/gfx/size_unittest.cc | 31 | ||||
-rw-r--r-- | ui/ui_unittests.gypi | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/webview_plugin.cc | 2 |
19 files changed, 169 insertions, 79 deletions
diff --git a/chrome/browser/notifications/balloon_collection_impl.cc b/chrome/browser/notifications/balloon_collection_impl.cc index f5e7317..1f4435a 100644 --- a/chrome/browser/notifications/balloon_collection_impl.cc +++ b/chrome/browser/notifications/balloon_collection_impl.cc @@ -466,7 +466,7 @@ bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() { #else gfx::Rect new_work_area = gfx::Screen::GetPrimaryDisplay().work_area(); #endif - if (!work_area_.Equals(new_work_area)) { + if (work_area_ != new_work_area) { work_area_.SetRect(new_work_area.x(), new_work_area.y(), new_work_area.width(), new_work_area.height()); changed = true; diff --git a/content/renderer/paint_aggregator.cc b/content/renderer/paint_aggregator.cc index 927630b..d38cca8 100644 --- a/content/renderer/paint_aggregator.cc +++ b/content/renderer/paint_aggregator.cc @@ -164,8 +164,7 @@ void PaintAggregator::ScrollRect(int dx, int dy, const gfx::Rect& clip_rect) { } // We can only scroll one rect at a time. - if (!update_.scroll_rect.IsEmpty() && - !update_.scroll_rect.Equals(clip_rect)) { + if (!update_.scroll_rect.IsEmpty() && update_.scroll_rect != clip_rect) { InvalidateRect(clip_rect); return; } diff --git a/ui/base/win/hwnd_util.cc b/ui/base/win/hwnd_util.cc index 8729545..60efa0c 100644 --- a/ui/base/win/hwnd_util.cc +++ b/ui/base/win/hwnd_util.cc @@ -26,7 +26,7 @@ void AdjustWindowToFit(HWND hwnd, const RECT& bounds, bool fit_to_monitor) { gfx::Rect window_rect(bounds); gfx::Rect monitor_rect(mi.rcWork); gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); - if (!new_window_rect.Equals(window_rect)) { + if (new_window_rect != window_rect) { // Window doesn't fit on monitor, move and possibly resize. SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), new_window_rect.width(), new_window_rect.height(), diff --git a/ui/gfx/point.h b/ui/gfx/point.h index 1f437cd..5984d74 100644 --- a/ui/gfx/point.h +++ b/ui/gfx/point.h @@ -44,7 +44,7 @@ class UI_EXPORT Point : public PointBase<Point, int> { CGPoint ToCGPoint() const; #endif - PointF ToPointF() const { + operator PointF() const { return PointF(x(), y()); } @@ -60,6 +60,14 @@ class UI_EXPORT Point : public PointBase<Point, int> { std::string ToString() const; }; +inline bool operator==(const Point& lhs, const Point& rhs) { + return lhs.x() == rhs.x() && lhs.y() == rhs.y(); +} + +inline bool operator!=(const Point& lhs, const Point& rhs) { + return !(lhs == rhs); +} + inline Point operator+(Point lhs, Point rhs) { return lhs.Add(rhs); } diff --git a/ui/gfx/point_base.h b/ui/gfx/point_base.h index fcb2289..1cec493 100644 --- a/ui/gfx/point_base.h +++ b/ui/gfx/point_base.h @@ -51,14 +51,6 @@ class UI_EXPORT PointBase { return Class((x_ + other.x_) / 2, (y_ + other.y_) / 2); } - bool operator==(const Class& rhs) const { - return x_ == rhs.x_ && y_ == rhs.y_; - } - - bool operator!=(const Class& rhs) const { - return !(*this == rhs); - } - // A point is less than another point if its y-value is closer // to the origin. If the y-values are the same, then point with // the x-value closer to the origin is considered less than the diff --git a/ui/gfx/point_f.h b/ui/gfx/point_f.h index a0b367f..d6cded9 100644 --- a/ui/gfx/point_f.h +++ b/ui/gfx/point_f.h @@ -31,6 +31,14 @@ class UI_EXPORT PointF : public PointBase<PointF, float> { std::string ToString() const; }; +inline bool operator==(const PointF& lhs, const PointF& rhs) { + return lhs.x() == rhs.x() && lhs.y() == rhs.y(); +} + +inline bool operator!=(const PointF& lhs, const PointF& rhs) { + return !(lhs == rhs); +} + inline PointF operator+(PointF lhs, PointF rhs) { return lhs.Add(rhs); } diff --git a/ui/gfx/point_unittest.cc b/ui/gfx/point_unittest.cc new file mode 100644 index 0000000..cac1b1e --- /dev/null +++ b/ui/gfx/point_unittest.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/point_base.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/point.h" +#include "ui/gfx/point_f.h" + +namespace ui { + +static int test_pointf(const gfx::PointF& p) { + return p.x(); +} + +TEST(PointTest, ToPointF) { + // Check that implicit conversion from integer to float compiles. + gfx::Point a(10, 20); + float x = test_pointf(a); + EXPECT_EQ(x, a.x()); + + gfx::PointF b(10, 20); + bool equals = a == b; + EXPECT_EQ(true, equals); + + equals = b == a; + EXPECT_EQ(true, equals); +} + +} // namespace ui diff --git a/ui/gfx/rect.h b/ui/gfx/rect.h index 36f822c..0f07948 100644 --- a/ui/gfx/rect.h +++ b/ui/gfx/rect.h @@ -68,7 +68,7 @@ class UI_EXPORT Rect : public RectBase<Rect, Point, Size, Insets, int> { CGRect ToCGRect() const; #endif - RectF ToRectF() const { + operator RectF() const { return RectF(origin().x(), origin().y(), size().width(), size().height()); } @@ -77,12 +77,21 @@ class UI_EXPORT Rect : public RectBase<Rect, Point, Size, Insets, int> { } RectF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT { - return ToRectF().Scale(x_scale, y_scale); + RectF original = *this; + return original.Scale(x_scale, y_scale); } std::string ToString() const; }; +inline bool operator==(const Rect& lhs, const Rect& rhs) { + return lhs.origin() == rhs.origin() && lhs.size() == rhs.size(); +} + +inline bool operator!=(const Rect& lhs, const Rect& rhs) { + return !(lhs == rhs); +} + #if !defined(COMPILER_MSVC) extern template class RectBase<Rect, Point, Size, Insets, int>; #endif diff --git a/ui/gfx/rect_base.h b/ui/gfx/rect_base.h index b6b5c99..08c9121 100644 --- a/ui/gfx/rect_base.h +++ b/ui/gfx/rect_base.h @@ -75,12 +75,6 @@ class UI_EXPORT RectBase { // Returns true if the area of the rectangle is zero. bool IsEmpty() const { return size_.IsEmpty(); } - bool operator==(const Class& other) const; - - bool operator!=(const Class& 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 @@ -118,11 +112,6 @@ class UI_EXPORT RectBase { // returned. Class Subtract(const Class& rect) const WARN_UNUSED_RESULT; - // Returns true if this rectangle equals that of the supplied rectangle. - bool Equals(const Class& 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 diff --git a/ui/gfx/rect_base_impl.h b/ui/gfx/rect_base_impl.h index d592fde..ab71f42 100644 --- a/ui/gfx/rect_base_impl.h +++ b/ui/gfx/rect_base_impl.h @@ -114,16 +114,6 @@ template<typename Class, typename SizeClass, typename InsetsClass, typename Type> -bool RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::operator==( - const Class& other) const { - return origin_ == other.origin_ && size_ == other.size_; -} - -template<typename Class, - typename PointClass, - typename SizeClass, - typename InsetsClass, - typename Type> bool RectBase<Class, PointClass, SizeClass, InsetsClass, Type>::operator<( const Class& other) const { if (origin_ == other.origin_) { diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h index 4395b52..fbdeb4e 100644 --- a/ui/gfx/rect_f.h +++ b/ui/gfx/rect_f.h @@ -40,6 +40,14 @@ class UI_EXPORT RectF : public RectBase<RectF, PointF, SizeF, InsetsF, float> { std::string ToString() const; }; +inline bool operator==(const RectF& lhs, const RectF& rhs) { + return lhs.origin() == rhs.origin() && lhs.size() == rhs.size(); +} + +inline bool operator!=(const RectF& lhs, const RectF& rhs) { + return !(lhs == rhs); +} + #if !defined(COMPILER_MSVC) extern template class RectBase<RectF, PointF, SizeF, InsetsF, float>; #endif diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc index 6233765..a19d785 100644 --- a/ui/gfx/rect_unittest.cc +++ b/ui/gfx/rect_unittest.cc @@ -165,12 +165,12 @@ TEST(RectTest, Union) { } TEST(RectTest, Equals) { - ASSERT_TRUE(gfx::Rect(0, 0, 0, 0).Equals(gfx::Rect(0, 0, 0, 0))); - ASSERT_TRUE(gfx::Rect(1, 2, 3, 4).Equals(gfx::Rect(1, 2, 3, 4))); - ASSERT_FALSE(gfx::Rect(0, 0, 0, 0).Equals(gfx::Rect(0, 0, 0, 1))); - ASSERT_FALSE(gfx::Rect(0, 0, 0, 0).Equals(gfx::Rect(0, 0, 1, 0))); - ASSERT_FALSE(gfx::Rect(0, 0, 0, 0).Equals(gfx::Rect(0, 1, 0, 0))); - ASSERT_FALSE(gfx::Rect(0, 0, 0, 0).Equals(gfx::Rect(1, 0, 0, 0))); + ASSERT_TRUE(gfx::Rect(0, 0, 0, 0) == gfx::Rect(0, 0, 0, 0)); + ASSERT_TRUE(gfx::Rect(1, 2, 3, 4) == gfx::Rect(1, 2, 3, 4)); + ASSERT_FALSE(gfx::Rect(0, 0, 0, 0) == gfx::Rect(0, 0, 0, 1)); + ASSERT_FALSE(gfx::Rect(0, 0, 0, 0) == gfx::Rect(0, 0, 1, 0)); + ASSERT_FALSE(gfx::Rect(0, 0, 0, 0) == gfx::Rect(0, 1, 0, 0)); + ASSERT_FALSE(gfx::Rect(0, 0, 0, 0) == gfx::Rect(1, 0, 0, 0)); } TEST(RectTest, AdjustToFit) { @@ -220,56 +220,56 @@ TEST(RectTest, Subtract) { // Matching EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(10, 10, 20, 20)).Equals( - gfx::Rect(0, 0, 0, 0))); + gfx::Rect(10, 10, 20, 20)) == + gfx::Rect(0, 0, 0, 0)); // Contains EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(5, 5, 30, 30)).Equals( - gfx::Rect(0, 0, 0, 0))); + gfx::Rect(5, 5, 30, 30)) == + gfx::Rect(0, 0, 0, 0)); // No intersection EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(30, 30, 20, 20)).Equals( - gfx::Rect(10, 10, 20, 20))); + gfx::Rect(30, 30, 20, 20)) == + gfx::Rect(10, 10, 20, 20)); // Not a complete intersection in either direction EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(15, 15, 20, 20)).Equals( - gfx::Rect(10, 10, 20, 20))); + gfx::Rect(15, 15, 20, 20)) == + gfx::Rect(10, 10, 20, 20)); // Complete intersection in the x-direction EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(10, 15, 20, 20)).Equals( - gfx::Rect(10, 10, 20, 5))); + gfx::Rect(10, 15, 20, 20)) == + gfx::Rect(10, 10, 20, 5)); // Complete intersection in the x-direction EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(5, 15, 30, 20)).Equals( - gfx::Rect(10, 10, 20, 5))); + gfx::Rect(5, 15, 30, 20)) == + gfx::Rect(10, 10, 20, 5)); // Complete intersection in the x-direction EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(5, 5, 30, 20)).Equals( - gfx::Rect(10, 25, 20, 5))); + gfx::Rect(5, 5, 30, 20)) == + gfx::Rect(10, 25, 20, 5)); // Complete intersection in the y-direction EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(10, 10, 10, 30)).Equals( - gfx::Rect(20, 10, 10, 20))); + gfx::Rect(10, 10, 10, 30)) == + gfx::Rect(20, 10, 10, 20)); // Complete intersection in the y-direction EXPECT_TRUE( gfx::Rect(10, 10, 20, 20).Subtract( - gfx::Rect(5, 5, 20, 30)).Equals( - gfx::Rect(25, 10, 5, 20))); + gfx::Rect(5, 5, 20, 30)) == + gfx::Rect(25, 10, 5, 20)); } TEST(RectTest, IsEmpty) { @@ -288,23 +288,23 @@ TEST(RectTest, SplitVertically) { // Splitting when origin is (0, 0). gfx::Rect(0, 0, 20, 20).SplitVertically(&left_half, &right_half); - EXPECT_TRUE(left_half.Equals(gfx::Rect(0, 0, 10, 20))); - EXPECT_TRUE(right_half.Equals(gfx::Rect(10, 0, 10, 20))); + EXPECT_TRUE(left_half == gfx::Rect(0, 0, 10, 20)); + EXPECT_TRUE(right_half == gfx::Rect(10, 0, 10, 20)); // Splitting when origin is arbitrary. gfx::Rect(10, 10, 20, 10).SplitVertically(&left_half, &right_half); - EXPECT_TRUE(left_half.Equals(gfx::Rect(10, 10, 10, 10))); - EXPECT_TRUE(right_half.Equals(gfx::Rect(20, 10, 10, 10))); + EXPECT_TRUE(left_half == gfx::Rect(10, 10, 10, 10)); + EXPECT_TRUE(right_half == gfx::Rect(20, 10, 10, 10)); // Splitting a rectangle of zero width. gfx::Rect(10, 10, 0, 10).SplitVertically(&left_half, &right_half); - EXPECT_TRUE(left_half.Equals(gfx::Rect(10, 10, 0, 10))); - EXPECT_TRUE(right_half.Equals(gfx::Rect(10, 10, 0, 10))); + EXPECT_TRUE(left_half == gfx::Rect(10, 10, 0, 10)); + EXPECT_TRUE(right_half == gfx::Rect(10, 10, 0, 10)); // Splitting a rectangle of odd width. gfx::Rect(10, 10, 5, 10).SplitVertically(&left_half, &right_half); - EXPECT_TRUE(left_half.Equals(gfx::Rect(10, 10, 2, 10))); - EXPECT_TRUE(right_half.Equals(gfx::Rect(12, 10, 3, 10))); + EXPECT_TRUE(left_half == gfx::Rect(10, 10, 2, 10)); + EXPECT_TRUE(right_half == gfx::Rect(12, 10, 3, 10)); } TEST(RectTest, CenterPoint) { @@ -567,4 +567,19 @@ TEST(RectTest, ConstructAndAssign) { } #endif +TEST(RectTest, ToRectF) { + // Check that implicit conversion from integer to float compiles. + gfx::Rect a(10, 20, 30, 40); + gfx::RectF b(10, 20, 30, 40); + + gfx::RectF intersect = b.Intersect(a); + EXPECT_EQ(b.ToString(), intersect.ToString()); + + bool equals = a == b; + EXPECT_EQ(true, equals); + + equals = b == a; + EXPECT_EQ(true, equals); +} + } // namespace ui diff --git a/ui/gfx/size.h b/ui/gfx/size.h index a2cdf3e..4425207 100644 --- a/ui/gfx/size.h +++ b/ui/gfx/size.h @@ -43,7 +43,7 @@ class UI_EXPORT Size : public SizeBase<Size, int> { CGSize ToCGSize() const; #endif - SizeF ToSizeF() const { + operator SizeF() const { return SizeF(width(), height()); } @@ -58,6 +58,14 @@ class UI_EXPORT Size : public SizeBase<Size, int> { std::string ToString() const; }; +inline bool operator==(const Size& lhs, const Size& rhs) { + return lhs.width() == rhs.width() && lhs.height() == rhs.height(); +} + +inline bool operator!=(const Size& lhs, const Size& rhs) { + return !(lhs == rhs); +} + #if !defined(COMPILER_MSVC) extern template class SizeBase<Size, int>; #endif diff --git a/ui/gfx/size_base.h b/ui/gfx/size_base.h index d66ca67..cd7221c 100644 --- a/ui/gfx/size_base.h +++ b/ui/gfx/size_base.h @@ -35,14 +35,6 @@ class UI_EXPORT SizeBase { void set_width(Type width) { width_ = width; } void set_height(Type height) { height_ = height; } - bool operator==(const Class& s) const { - return width_ == s.width_ && height_ == s.height_; - } - - bool operator!=(const Class& s) const { - return !(*this == s); - } - bool IsEmpty() const { return (width_ <= 0) || (height_ <= 0); } diff --git a/ui/gfx/size_f.h b/ui/gfx/size_f.h index f3ad7db..f9ac6bd 100644 --- a/ui/gfx/size_f.h +++ b/ui/gfx/size_f.h @@ -30,6 +30,14 @@ class UI_EXPORT SizeF : public SizeBase<SizeF, float> { std::string ToString() const; }; +inline bool operator==(const SizeF& lhs, const SizeF& rhs) { + return lhs.width() == rhs.width() && lhs.height() == rhs.height(); +} + +inline bool operator!=(const SizeF& lhs, const SizeF& rhs) { + return !(lhs == rhs); +} + #if !defined(COMPILER_MSVC) extern template class SizeBase<SizeF, float>; #endif diff --git a/ui/gfx/size_unittest.cc b/ui/gfx/size_unittest.cc new file mode 100644 index 0000000..65d58ca --- /dev/null +++ b/ui/gfx/size_unittest.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/size_base.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/size.h" +#include "ui/gfx/size_f.h" + +namespace ui { + +static int test_sizef(const gfx::SizeF& s) { + return s.width(); +} + +TEST(SizeTest, ToSizeF) { + // Check that implicit conversion from integer to float compiles. + gfx::Size a(10, 20); + float width = test_sizef(a); + EXPECT_EQ(width, a.width()); + + gfx::SizeF b(10, 20); + bool equals = a == b; + EXPECT_EQ(true, equals); + + equals = b == a; + EXPECT_EQ(true, equals); +} + +} // namespace ui diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index c87279e..10ed959 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -80,10 +80,12 @@ 'gfx/image/image_unittest_util_ios.mm', 'gfx/image/image_unittest_util_mac.mm', 'gfx/insets_unittest.cc', + 'gfx/point_unittest.cc', 'gfx/rect_unittest.cc', 'gfx/safe_integer_conversions_unittest.cc', 'gfx/screen_unittest.cc', 'gfx/shadow_value_unittest.cc', + 'gfx/size_unittest.cc', 'gfx/skbitmap_operations_unittest.cc', 'gfx/skia_util_unittest.cc', ], diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc index 85d756d..e92720d 100644 --- a/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc +++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc @@ -66,7 +66,7 @@ TEST(PpapiGraphics2DImplTest, ConvertToLogicalPixels) { gfx::Point delta(tests[i].dx1, tests[i].dy1); bool res = webkit::ppapi::PPB_Graphics2D_Impl::ConvertToLogicalPixels( tests[i].scale, &r1, &delta); - EXPECT_TRUE(r1.Equals(r2)); + EXPECT_EQ(r2.ToString(), r1.ToString()); EXPECT_EQ(res, tests[i].result); if (res) { EXPECT_EQ(delta, gfx::Point(tests[i].dx2, tests[i].dy2)); diff --git a/webkit/plugins/webview_plugin.cc b/webkit/plugins/webview_plugin.cc index 8e3f942..7d3dc7e 100644 --- a/webkit/plugins/webview_plugin.cc +++ b/webkit/plugins/webview_plugin.cc @@ -139,7 +139,7 @@ void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { void WebViewPlugin::updateGeometry( const WebRect& frame_rect, const WebRect& clip_rect, const WebVector<WebRect>& cut_out_rects, bool is_visible) { - if (frame_rect != rect_) { + if (static_cast<gfx::Rect>(frame_rect) != rect_) { rect_ = frame_rect; web_view_->resize(WebSize(frame_rect.width, frame_rect.height)); } |