Chromium Code Reviews| Index: chrome/browser/ui/views/ash/window_positioner.cc |
| diff --git a/chrome/browser/ui/views/ash/window_positioner.cc b/chrome/browser/ui/views/ash/window_positioner.cc |
| index 4b19f6dfd336377b01359355e6d313867bb0cb35..196f0c5a1d580613fd1bacdc5c784ff3217d1f54 100644 |
| --- a/chrome/browser/ui/views/ash/window_positioner.cc |
| +++ b/chrome/browser/ui/views/ash/window_positioner.cc |
| @@ -55,10 +55,10 @@ gfx::Rect WindowPositioner::GetPopupPosition(const gfx::Rect& old_pos) { |
| work_area.width()) || |
| (old_pos.height() + popup_position_offset_from_screen_corner_y >= |
| work_area.height())) |
| - return old_pos; |
| - const gfx::Rect result = SmartPopupPosition(old_pos, work_area); |
| + return AlignPopupPosition(old_pos, work_area, grid); |
| + const gfx::Rect result = SmartPopupPosition(old_pos, work_area, grid); |
| if (!result.IsEmpty()) |
| - return result; |
| + return AlignPopupPosition(result, work_area, grid); |
| return NormalPopupPosition(old_pos, work_area); |
| } |
| @@ -97,7 +97,8 @@ gfx::Rect WindowPositioner::NormalPopupPosition( |
| gfx::Rect WindowPositioner::SmartPopupPosition( |
| const gfx::Rect& old_pos, |
| - const gfx::Rect& work_area) { |
| + const gfx::Rect& work_area, |
| + int grid) { |
| const std::vector<aura::Window*> windows = |
| ash::WindowCycleController::BuildWindowList(); |
| @@ -150,7 +151,12 @@ gfx::Rect WindowPositioner::SmartPopupPosition( |
| for (i = 0; i < regions.size(); i++) { |
| if (regions[i]->Intersects(gfx::Rect(x + work_area.x(), |
| y + work_area.y(), w, h))) { |
| - y = regions[i]->y() + regions[i]->height() - work_area.y(); |
| + y = regions[i]->bottom() - work_area.y(); |
| + // Align to the next 'full' grid step. |
| + if (grid > 1) { |
| + // Align to the grid. |
| + y += (grid - (y + grid - 1) % grid) % grid; |
|
sky
2012/04/13 19:44:02
I don't understand this code. I'm sure I missing s
Mr4D (OOO till 08-26)
2012/04/13 20:47:39
y / grid * grid: Certainly not. The compiler (wind
sky
2012/04/13 21:42:03
That sounds like a compiler bug, we have code like
Mr4D (OOO till 08-26)
2012/04/13 22:33:48
It is not exactly a compiler bug - it is a behavio
|
| + } |
| break; |
| } |
| } |
| @@ -161,3 +167,26 @@ gfx::Rect WindowPositioner::SmartPopupPosition( |
| } |
| return gfx::Rect(0, 0, 0, 0); |
| } |
| + |
| +gfx::Rect WindowPositioner::AlignPopupPosition( |
| + const gfx::Rect& pos, |
| + const gfx::Rect& work_space, |
| + int grid) { |
| + if (grid <= 1) |
| + return pos; |
| + |
| + int x = pos.x() - (pos.x() - work_space.x()) % grid; |
| + int y = pos.y() - (pos.y() - work_space.y()) % grid; |
| + int w = pos.width(); |
| + int h = pos.height(); |
| + |
| + // If the alignment was pushing the window out of the screen, we ignore the |
| + // alignment for that call. |
| + if (abs(pos.right() - work_space.right()) < grid) { |
|
sky
2012/04/13 19:44:02
nit: no {} here and 188
Mr4D (OOO till 08-26)
2012/04/13 20:47:39
Done.
|
| + x = work_space.right() - w; |
| + } |
| + if (abs(pos.bottom() - work_space.bottom()) < grid) { |
| + y = work_space.bottom() - h; |
| + } |
| + return gfx::Rect(x, y, w, h); |
| +} |