From d40305001bfd61bef7e118c8580895f68d36b163 Mon Sep 17 00:00:00 2001 From: "danakj@chromium.org" Date: Tue, 23 Oct 2012 16:51:47 +0000 Subject: Make gfx::Rect class operations consistently mutate the class they are called on. Currently some methods mutate the class, and some return a new value, requiring API users to know what kind of method they are calling each time, and making inconsistent code. For example: gfx::Rect rect; rect.Inset(1, 1, 1, 1); rect = rect.Intersect(other_rect); rect.Offset(1, 1); Instead of: gfx::Rect rect; rect.Inset(1, 1, 1, 1); rect.Intersect(other_rect); rect.Offset(1, 1); We could go either way - making the class immutable or all methods return a new instance - but I believe it is better to instead make all methods mutate the class. This allows for shorter lines of code by avoiding having to repeat the object's name twice in order to change it. This patch changes gfx::Rect classes and all the callsites that uses these methods. It should make no change in behaviour, so no new tests added. R=sky BUG=147395 Review URL: https://codereview.chromium.org/11110004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163579 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/tooltips/tooltip_controller.cc | 3 ++- ash/tooltips/tooltip_controller_unittest.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'ash/tooltips') diff --git a/ash/tooltips/tooltip_controller.cc b/ash/tooltips/tooltip_controller.cc index 3bb99bc..45c4785 100644 --- a/ash/tooltips/tooltip_controller.cc +++ b/ash/tooltips/tooltip_controller.cc @@ -179,7 +179,8 @@ class TooltipController::Tooltip : public views::WidgetObserver { if (tooltip_rect.bottom() > display_bounds.bottom()) tooltip_rect.set_y(mouse_pos.y() - tooltip_height); - GetWidget()->SetBounds(tooltip_rect.AdjustToFit(display_bounds)); + tooltip_rect.AdjustToFit(display_bounds); + GetWidget()->SetBounds(tooltip_rect); } views::Widget* GetWidget() { diff --git a/ash/tooltips/tooltip_controller_unittest.cc b/ash/tooltips/tooltip_controller_unittest.cc index d48db06..9efbd75 100644 --- a/ash/tooltips/tooltip_controller_unittest.cc +++ b/ash/tooltips/tooltip_controller_unittest.cc @@ -72,7 +72,7 @@ void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) { contents_view->AddChildView(view); view->SetBounds(contents_view->width(), 0, 100, 100); gfx::Rect contents_view_bounds = contents_view->bounds(); - contents_view_bounds = contents_view_bounds.Union(view->bounds()); + contents_view_bounds.Union(view->bounds()); contents_view->SetBoundsRect(contents_view_bounds); widget->SetBounds(gfx::Rect(widget->GetWindowBoundsInScreen().origin(), contents_view_bounds.size())); -- cgit v1.1