Chromium Code Reviews| Index: chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| diff --git a/chrome/browser/ui/views/app_list/app_list_controller_win.cc b/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| index c9d334dc1268905c01990cebccd1549c037e2df9..8ec2e4bd41d806a45afacf1c544eeca975e42c94 100644 |
| --- a/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| +++ b/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| @@ -540,118 +540,69 @@ bool GetTaskbarRect(gfx::Rect* rect) { |
| return true; |
| } |
| -// Used to position the view relative to a point, which requires |anchor| to be |
| -// in the center of the desired view location. This helper function updates |
| -// |anchor| thus, using the location of the point in |point|, the distance |
| -// to move the view from |point| in |offset|, and the direction to move |
| -// represented in |direction|. |
| -// To position relative to a screen corner, the absolute values of |direction|.x |
| -// and |direction.y| should both be 1. To position relative to some point on the |
| -// taskbar, one of the absolute values of |direction.x| and |direction.y| should |
| -// be 1 and the other 0. |
| -void FloatFromPoint(const gfx::Point& point, |
| - const gfx::Size& offset, |
| - const gfx::Point& direction, |
| - gfx::Point* anchor) { |
| - anchor->set_x(point.x() + direction.x() * offset.width()); |
| - anchor->set_y(point.y() + direction.y() * offset.height()); |
| -} |
| - |
| -void AppListController::SnapArrowLocationToTaskbarEdge( |
| - const gfx::Display& display, |
| - gfx::Point* anchor) { |
| +gfx::Point FindReferencePoint(const gfx::Display& display, |
| + gfx::Point* anchor) { |
|
tapted
2013/02/27 11:58:48
i think |anchor| can be const reference now
benwells
2013/02/27 22:35:42
Yeah, and in the next function. Done.
|
| const int kSnapDistance = 50; |
| - const int kSnapOffset = 5; |
| - |
| - gfx::Rect taskbar_rect; |
| - gfx::Size float_offset = current_view_->GetPreferredSize(); |
| - float_offset.set_width(float_offset.width() / 2); |
| - float_offset.set_height(float_offset.height() / 2); |
| - float_offset.Enlarge(kSnapOffset, kSnapOffset); |
| // If we can't find the taskbar, snap to the bottom left. |
| // If the display size is the same as the work area, and does not contain the |
| // taskbar, either the taskbar is hidden or on another monitor, so just snap |
| // to the bottom left. |
| + gfx::Rect taskbar_rect; |
| if (!GetTaskbarRect(&taskbar_rect) || |
| (display.work_area() == display.bounds() && |
| !display.work_area().Contains(taskbar_rect))) { |
| - FloatFromPoint(display.work_area().bottom_left(), |
| - float_offset, |
| - gfx::Point(1, -1), |
| - anchor); |
| - return; |
| + return display.work_area().bottom_left(); |
| } |
| - const gfx::Rect& screen_rect = display.bounds(); |
| - |
| // Snap to the taskbar edge. If the cursor is greater than kSnapDistance away, |
| // also move to the left (for horizontal taskbars) or top (for vertical). |
| - |
| + const gfx::Rect& screen_rect = display.bounds(); |
| // First handle taskbar on bottom. |
| if (taskbar_rect.width() == screen_rect.width()) { |
| if (taskbar_rect.bottom() == screen_rect.bottom()) { |
| - if (taskbar_rect.y() - anchor->y() > kSnapDistance) { |
| - FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.y()), |
| - float_offset, |
| - gfx::Point(1, -1), |
| - anchor); |
| - return; |
| - } |
| - |
| - FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.y()), |
| - float_offset, |
| - gfx::Point(0, -1), |
| - anchor); |
| - return; |
| + if (taskbar_rect.y() - anchor->y() > kSnapDistance) |
| + return gfx::Point(screen_rect.x(), taskbar_rect.y()); |
| + |
| + return gfx::Point(anchor->x(), taskbar_rect.y()); |
| } |
| // Now try on the top. |
| - if (anchor->y() - taskbar_rect.bottom() > kSnapDistance) { |
| - FloatFromPoint(gfx::Point(screen_rect.x(), taskbar_rect.bottom()), |
| - float_offset, |
| - gfx::Point(1, 1), |
| - anchor); |
| - return; |
| - } |
| + if (anchor->y() - taskbar_rect.bottom() > kSnapDistance) |
| + return gfx::Point(screen_rect.x(), taskbar_rect.bottom()); |
| - FloatFromPoint(gfx::Point(anchor->x(), taskbar_rect.bottom()), |
| - float_offset, |
| - gfx::Point(0, 1), |
| - anchor); |
| - return; |
| + return gfx::Point(anchor->x(), taskbar_rect.bottom()); |
| } |
| // Now try the left. |
| if (taskbar_rect.x() == screen_rect.x()) { |
| - if (anchor->x() - taskbar_rect.right() > kSnapDistance) { |
| - FloatFromPoint(gfx::Point(taskbar_rect.right(), screen_rect.y()), |
| - float_offset, |
| - gfx::Point(1, 1), |
| - anchor); |
| - return; |
| - } |
| + if (anchor->x() - taskbar_rect.right() > kSnapDistance) |
| + return gfx::Point(taskbar_rect.right(), screen_rect.y()); |
| - FloatFromPoint(gfx::Point(taskbar_rect.right(), anchor->y()), |
| - float_offset, |
| - gfx::Point(1, 0), |
| - anchor); |
| - return; |
| + return gfx::Point(taskbar_rect.right(), anchor->y()); |
| } |
| // Finally, try the right. |
| - if (taskbar_rect.x() - anchor->x() > kSnapDistance) { |
| - FloatFromPoint(gfx::Point(taskbar_rect.x(), screen_rect.y()), |
| - float_offset, |
| - gfx::Point(-1, 1), |
| - anchor); |
| - return; |
| - } |
| + if (taskbar_rect.x() - anchor->x() > kSnapDistance) |
| + return gfx::Point(taskbar_rect.x(), screen_rect.y()); |
| + |
| + return gfx::Point(taskbar_rect.x(), anchor->y()); |
| +} |
| + |
| +void AppListController::SnapArrowLocationToTaskbarEdge( |
| + const gfx::Display& display, |
| + gfx::Point* anchor) { |
| + const int kSnapOffset = 3; |
| + |
| + gfx::Rect bounds_rect(display.work_area()); |
| + gfx::Size view_size(current_view_->GetPreferredSize()); |
| + bounds_rect.Inset(view_size.width() / 2 + kSnapOffset, |
| + view_size.height() / 2 + kSnapOffset); |
| - FloatFromPoint(gfx::Point(taskbar_rect.x(), anchor->y()), |
| - float_offset, |
| - gfx::Point(-1, 0), |
| - anchor); |
| + gfx::Point ref_point(FindReferencePoint(display, anchor)); |
| + anchor->SetPoint(ref_point.x(), ref_point.y()); |
|
tapted
2013/02/27 11:58:48
I don't... think default assignment operator has b
benwells
2013/02/27 22:35:42
Yep, good one.
|
| + anchor->ClampToMin(bounds_rect.origin()); |
|
tapted
2013/02/27 11:58:48
ah, origin - of course ;). (Cocoa has had me think
|
| + anchor->ClampToMax(bounds_rect.bottom_right()); |
| } |
| void AppListController::UpdateArrowPositionAndAnchorPoint( |