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

Side by Side Diff: chrome/browser/ui/ash/window_positioner.cc

Issue 10910164: Removes the grid from ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ShelfBrowserTest Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/window_positioner.h" 5 #include "chrome/browser/ui/ash/window_positioner.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/window_cycle_controller.h" 8 #include "ash/wm/window_cycle_controller.h"
9 #include "ash/wm/window_resizer.h" 9 #include "ash/wm/window_resizer.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/aura/window_delegate.h" 12 #include "ui/aura/window_delegate.h"
13 #include "ui/compositor/layer.h" 13 #include "ui/compositor/layer.h"
14 #include "ui/gfx/screen.h" 14 #include "ui/gfx/screen.h"
15 15
16 namespace ash { 16 namespace ash {
17 17
18 // statics 18 // statics
19 19
20 // Currently matches kGridSize * 2 (defined in ash/wm/workspace_controller.cc).
21 const int WindowPositioner::kMinimumWindowOffset = 32; 20 const int WindowPositioner::kMinimumWindowOffset = 32;
22 21
23 WindowPositioner::WindowPositioner() 22 WindowPositioner::WindowPositioner()
24 : pop_position_offset_increment_x(0), 23 : pop_position_offset_increment_x(0),
25 pop_position_offset_increment_y(0), 24 pop_position_offset_increment_y(0),
26 popup_position_offset_from_screen_corner_x(0), 25 popup_position_offset_from_screen_corner_x(0),
27 popup_position_offset_from_screen_corner_y(0), 26 popup_position_offset_from_screen_corner_y(0),
28 last_popup_position_x_(0), 27 last_popup_position_x_(0),
29 last_popup_position_y_(0) { 28 last_popup_position_y_(0) {
30 } 29 }
31 30
32 WindowPositioner::~WindowPositioner() { 31 WindowPositioner::~WindowPositioner() {
33 } 32 }
34 33
35 gfx::Rect WindowPositioner::GetPopupPosition(const gfx::Rect& old_pos) { 34 gfx::Rect WindowPositioner::GetPopupPosition(const gfx::Rect& old_pos) {
36 int grid = ash::Shell::GetInstance()->GetGridSize(); 35 int grid = kMinimumWindowOffset;
37 // Make sure that the grid has a minimum resolution.
38 if (!grid) {
39 grid = kMinimumWindowOffset;
40 } else {
41 while (grid < kMinimumWindowOffset)
42 grid *= 2;
43 }
44 popup_position_offset_from_screen_corner_x = grid; 36 popup_position_offset_from_screen_corner_x = grid;
45 popup_position_offset_from_screen_corner_y = grid; 37 popup_position_offset_from_screen_corner_y = grid;
46 if (!pop_position_offset_increment_x) { 38 if (!pop_position_offset_increment_x) {
47 // When the popup position increment is , the last popup position 39 // When the popup position increment is , the last popup position
48 // was not yet initialized. 40 // was not yet initialized.
49 last_popup_position_x_ = popup_position_offset_from_screen_corner_x; 41 last_popup_position_x_ = popup_position_offset_from_screen_corner_x;
50 last_popup_position_y_ = popup_position_offset_from_screen_corner_y; 42 last_popup_position_y_ = popup_position_offset_from_screen_corner_y;
51 } 43 }
52 pop_position_offset_increment_x = grid; 44 pop_position_offset_increment_x = grid;
53 pop_position_offset_increment_y = grid; 45 pop_position_offset_increment_y = grid;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Note: The passing (x,y,w,h) window is always relative to the work area's 145 // Note: The passing (x,y,w,h) window is always relative to the work area's
154 // origin. 146 // origin.
155 for (; x_increment > 0 ? (x < x_end) : (x > x_end); x += x_increment) { 147 for (; x_increment > 0 ? (x < x_end) : (x > x_end); x += x_increment) {
156 int y = 0; 148 int y = 0;
157 while (y + h <= work_area.height()) { 149 while (y + h <= work_area.height()) {
158 size_t i; 150 size_t i;
159 for (i = 0; i < regions.size(); i++) { 151 for (i = 0; i < regions.size(); i++) {
160 if (regions[i]->Intersects(gfx::Rect(x + work_area.x(), 152 if (regions[i]->Intersects(gfx::Rect(x + work_area.x(),
161 y + work_area.y(), w, h))) { 153 y + work_area.y(), w, h))) {
162 y = regions[i]->bottom() - work_area.y(); 154 y = regions[i]->bottom() - work_area.y();
163 if (grid > 1) {
164 // Align to the (next) grid step.
165 y = ash::WindowResizer::AlignToGridRoundUp(y, grid);
166 }
167 break; 155 break;
168 } 156 }
169 } 157 }
170 if (i >= regions.size()) 158 if (i >= regions.size())
171 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); 159 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h);
172 } 160 }
173 } 161 }
174 } 162 }
175 return gfx::Rect(0, 0, 0, 0); 163 return gfx::Rect(0, 0, 0, 0);
176 } 164 }
(...skipping 13 matching lines...) Expand all
190 // If the alignment was pushing the window out of the screen, we ignore the 178 // If the alignment was pushing the window out of the screen, we ignore the
191 // alignment for that call. 179 // alignment for that call.
192 if (abs(pos.right() - work_area.right()) < grid) 180 if (abs(pos.right() - work_area.right()) < grid)
193 x = work_area.right() - w; 181 x = work_area.right() - w;
194 if (abs(pos.bottom() - work_area.bottom()) < grid) 182 if (abs(pos.bottom() - work_area.bottom()) < grid)
195 y = work_area.bottom() - h; 183 y = work_area.bottom() - h;
196 return gfx::Rect(x, y, w, h); 184 return gfx::Rect(x, y, w, h);
197 } 185 }
198 186
199 } // namespace ash 187 } // namespace ash
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/shelf_browsertest.cc ('k') | chrome/browser/ui/ash/window_positioner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698