Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Unified Diff: chrome/browser/ui/views/ash/window_positioner.cc

Issue 9969164: Ignoring alignment when it pushes a window out of the screen (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Not my code anymore Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2780060f77e6654342bb414aa4bd42167349fe00 100644
--- a/chrome/browser/ui/views/ash/window_positioner.cc
+++ b/chrome/browser/ui/views/ash/window_positioner.cc
@@ -6,6 +6,7 @@
#include "ash/shell.h"
#include "ash/wm/window_cycle_controller.h"
+#include "ash/wm/window_resizer.h"
#include "ash/wm/window_util.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
@@ -55,10 +56,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 +98,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 +152,11 @@ 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();
+ if (grid > 1) {
+ // Align to the (next) grid step.
+ y = ash::WindowResizer::AlignToGridRoundUp(y, grid);
+ }
break;
}
}
@@ -161,3 +167,24 @@ gfx::Rect WindowPositioner::SmartPopupPosition(
}
return gfx::Rect(0, 0, 0, 0);
}
+
+gfx::Rect WindowPositioner::AlignPopupPosition(
+ const gfx::Rect& pos,
+ const gfx::Rect& work_area,
+ int grid) {
+ if (grid <= 1)
+ return pos;
+
+ int x = pos.x() - (pos.x() - work_area.x()) % grid;
+ int y = pos.y() - (pos.y() - work_area.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_area.right()) < grid)
+ x = work_area.right() - w;
+ if (abs(pos.bottom() - work_area.bottom()) < grid)
+ y = work_area.bottom() - h;
+ return gfx::Rect(x, y, w, h);
+}
« no previous file with comments | « chrome/browser/ui/views/ash/window_positioner.h ('k') | chrome/browser/ui/views/ash/window_positioner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698