OLD | NEW |
---|---|
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/views/ash/window_positioner.h" | 5 #include "chrome/browser/ui/views/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_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 aura::Window* window = ash::wm::GetActiveWindow(); | 48 aura::Window* window = ash::wm::GetActiveWindow(); |
49 const gfx::Rect work_area = window && window->IsVisible() ? | 49 const gfx::Rect work_area = window && window->IsVisible() ? |
50 gfx::Screen::GetMonitorWorkAreaNearestWindow(window) : | 50 gfx::Screen::GetMonitorWorkAreaNearestWindow(window) : |
51 gfx::Screen::GetPrimaryMonitorWorkArea(); | 51 gfx::Screen::GetPrimaryMonitorWorkArea(); |
52 // Only try to reposition the popup when it is not spanning the entire | 52 // Only try to reposition the popup when it is not spanning the entire |
53 // screen. | 53 // screen. |
54 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= | 54 if ((old_pos.width() + popup_position_offset_from_screen_corner_x >= |
55 work_area.width()) || | 55 work_area.width()) || |
56 (old_pos.height() + popup_position_offset_from_screen_corner_y >= | 56 (old_pos.height() + popup_position_offset_from_screen_corner_y >= |
57 work_area.height())) | 57 work_area.height())) |
58 return old_pos; | 58 return AlignPopupPosition(old_pos, work_area, grid); |
59 const gfx::Rect result = SmartPopupPosition(old_pos, work_area); | 59 const gfx::Rect result = SmartPopupPosition(old_pos, work_area, grid); |
60 if (!result.IsEmpty()) | 60 if (!result.IsEmpty()) |
61 return result; | 61 return AlignPopupPosition(result, work_area, grid); |
62 return NormalPopupPosition(old_pos, work_area); | 62 return NormalPopupPosition(old_pos, work_area); |
63 } | 63 } |
64 | 64 |
65 gfx::Rect WindowPositioner::NormalPopupPosition( | 65 gfx::Rect WindowPositioner::NormalPopupPosition( |
66 const gfx::Rect& old_pos, | 66 const gfx::Rect& old_pos, |
67 const gfx::Rect& work_area) { | 67 const gfx::Rect& work_area) { |
68 int w = old_pos.width(); | 68 int w = old_pos.width(); |
69 int h = old_pos.height(); | 69 int h = old_pos.height(); |
70 // Note: The 'last_popup_position' is checked and kept relative to the | 70 // Note: The 'last_popup_position' is checked and kept relative to the |
71 // screen size. The offsetting will be done in the last step when the | 71 // screen size. The offsetting will be done in the last step when the |
(...skipping 18 matching lines...) Expand all Loading... | |
90 int y = last_popup_position_y_; | 90 int y = last_popup_position_y_; |
91 if (!reset) { | 91 if (!reset) { |
92 last_popup_position_x_ += pop_position_offset_increment_x; | 92 last_popup_position_x_ += pop_position_offset_increment_x; |
93 last_popup_position_y_ += pop_position_offset_increment_y; | 93 last_popup_position_y_ += pop_position_offset_increment_y; |
94 } | 94 } |
95 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); | 95 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); |
96 } | 96 } |
97 | 97 |
98 gfx::Rect WindowPositioner::SmartPopupPosition( | 98 gfx::Rect WindowPositioner::SmartPopupPosition( |
99 const gfx::Rect& old_pos, | 99 const gfx::Rect& old_pos, |
100 const gfx::Rect& work_area) { | 100 const gfx::Rect& work_area, |
101 int grid) { | |
101 const std::vector<aura::Window*> windows = | 102 const std::vector<aura::Window*> windows = |
102 ash::WindowCycleController::BuildWindowList(); | 103 ash::WindowCycleController::BuildWindowList(); |
103 | 104 |
104 std::vector<const gfx::Rect*> regions; | 105 std::vector<const gfx::Rect*> regions; |
105 // Process the window list and check if we can bail immediately. | 106 // Process the window list and check if we can bail immediately. |
106 for (size_t i = 0; i < windows.size(); i++) { | 107 for (size_t i = 0; i < windows.size(); i++) { |
107 // We only include opaque and visible windows. | 108 // We only include opaque and visible windows. |
108 if (windows[i] && windows[i]->IsVisible() && windows[i]->layer() && | 109 if (windows[i] && windows[i]->IsVisible() && windows[i]->layer() && |
109 (!windows[i]->transparent() || | 110 (!windows[i]->transparent() || |
110 windows[i]->layer()->GetTargetOpacity() == 1.0)) { | 111 windows[i]->layer()->GetTargetOpacity() == 1.0)) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 } | 144 } |
144 // 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 |
145 // origin. | 146 // origin. |
146 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) { |
147 int y = 0; | 148 int y = 0; |
148 while (y + h <= work_area.height()) { | 149 while (y + h <= work_area.height()) { |
149 size_t i; | 150 size_t i; |
150 for (i = 0; i < regions.size(); i++) { | 151 for (i = 0; i < regions.size(); i++) { |
151 if (regions[i]->Intersects(gfx::Rect(x + work_area.x(), | 152 if (regions[i]->Intersects(gfx::Rect(x + work_area.x(), |
152 y + work_area.y(), w, h))) { | 153 y + work_area.y(), w, h))) { |
153 y = regions[i]->y() + regions[i]->height() - work_area.y(); | 154 y = regions[i]->bottom() - work_area.y(); |
155 // Align to the next 'full' grid step. | |
156 if (grid > 1) { | |
157 // Align to the grid. | |
158 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
| |
159 } | |
154 break; | 160 break; |
155 } | 161 } |
156 } | 162 } |
157 if (i >= regions.size()) | 163 if (i >= regions.size()) |
158 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); | 164 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); |
159 } | 165 } |
160 } | 166 } |
161 } | 167 } |
162 return gfx::Rect(0, 0, 0, 0); | 168 return gfx::Rect(0, 0, 0, 0); |
163 } | 169 } |
170 | |
171 gfx::Rect WindowPositioner::AlignPopupPosition( | |
172 const gfx::Rect& pos, | |
173 const gfx::Rect& work_space, | |
174 int grid) { | |
175 if (grid <= 1) | |
176 return pos; | |
177 | |
178 int x = pos.x() - (pos.x() - work_space.x()) % grid; | |
179 int y = pos.y() - (pos.y() - work_space.y()) % grid; | |
180 int w = pos.width(); | |
181 int h = pos.height(); | |
182 | |
183 // If the alignment was pushing the window out of the screen, we ignore the | |
184 // alignment for that call. | |
185 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.
| |
186 x = work_space.right() - w; | |
187 } | |
188 if (abs(pos.bottom() - work_space.bottom()) < grid) { | |
189 y = work_space.bottom() - h; | |
190 } | |
191 return gfx::Rect(x, y, w, h); | |
192 } | |
OLD | NEW |