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_resizer.h" | 9 #include "ash/wm/window_resizer.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); | 96 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); |
97 } | 97 } |
98 | 98 |
99 gfx::Rect WindowPositioner::SmartPopupPosition( | 99 gfx::Rect WindowPositioner::SmartPopupPosition( |
100 const gfx::Rect& old_pos, | 100 const gfx::Rect& old_pos, |
101 const gfx::Rect& work_area, | 101 const gfx::Rect& work_area, |
102 int grid) { | 102 int grid) { |
103 const std::vector<aura::Window*> windows = | 103 const std::vector<aura::Window*> windows = |
104 ash::WindowCycleController::BuildWindowList(); | 104 ash::WindowCycleController::BuildWindowList(); |
105 | 105 |
106 std::vector<gfx::Rect> regions; | 106 std::vector<const gfx::Rect*> regions; |
107 // Process the window list and check if we can bail immediately. | 107 // Process the window list and check if we can bail immediately. |
108 for (size_t i = 0; i < windows.size(); i++) { | 108 for (size_t i = 0; i < windows.size(); i++) { |
109 // We only include opaque and visible windows. | 109 // We only include opaque and visible windows. |
110 if (windows[i] && windows[i]->IsVisible() && windows[i]->layer() && | 110 if (windows[i] && windows[i]->IsVisible() && windows[i]->layer() && |
111 (!windows[i]->transparent() || | 111 (!windows[i]->transparent() || |
112 windows[i]->layer()->GetTargetOpacity() == 1.0)) { | 112 windows[i]->layer()->GetTargetOpacity() == 1.0)) { |
113 // When any window is maximized we cannot find any free space. | 113 // When any window is maximized we cannot find any free space. |
114 if (ash::wm::IsWindowMaximized(windows[i]) || | 114 if (ash::wm::IsWindowMaximized(windows[i]) || |
115 ash::wm::IsWindowFullscreen(windows[i])) | 115 ash::wm::IsWindowFullscreen(windows[i])) |
116 return gfx::Rect(0, 0, 0, 0); | 116 return gfx::Rect(0, 0, 0, 0); |
117 if (ash::wm::IsWindowNormal(windows[i])) | 117 if (ash::wm::IsWindowNormal(windows[i])) |
118 regions.push_back(windows[i]->bounds()); | 118 regions.push_back(&windows[i]->bounds()); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 if (regions.empty()) | 122 if (regions.empty()) |
123 return gfx::Rect(0, 0, 0, 0); | 123 return gfx::Rect(0, 0, 0, 0); |
124 | 124 |
125 int w = old_pos.width(); | 125 int w = old_pos.width(); |
126 int h = old_pos.height(); | 126 int h = old_pos.height(); |
127 int x_end = work_area.width() / 2; | 127 int x_end = work_area.width() / 2; |
128 int x, x_increment; | 128 int x, x_increment; |
(...skipping 14 matching lines...) Expand all Loading... |
143 x = work_area.width() - w; | 143 x = work_area.width() - w; |
144 x_increment = -pop_position_offset_increment_x; | 144 x_increment = -pop_position_offset_increment_x; |
145 } | 145 } |
146 // Note: The passing (x,y,w,h) window is always relative to the work area's | 146 // Note: The passing (x,y,w,h) window is always relative to the work area's |
147 // origin. | 147 // origin. |
148 for (; x_increment > 0 ? (x < x_end) : (x > x_end); x += x_increment) { | 148 for (; x_increment > 0 ? (x < x_end) : (x > x_end); x += x_increment) { |
149 int y = 0; | 149 int y = 0; |
150 while (y + h <= work_area.height()) { | 150 while (y + h <= work_area.height()) { |
151 size_t i; | 151 size_t i; |
152 for (i = 0; i < regions.size(); i++) { | 152 for (i = 0; i < regions.size(); i++) { |
153 if (regions[i].Intersects(gfx::Rect(x + work_area.x(), | 153 if (regions[i]->Intersects(gfx::Rect(x + work_area.x(), |
154 y + work_area.y(), w, h))) { | 154 y + work_area.y(), w, h))) { |
155 y = regions[i].bottom() - work_area.y(); | 155 y = regions[i]->bottom() - work_area.y(); |
156 if (grid > 1) { | 156 if (grid > 1) { |
157 // Align to the (next) grid step. | 157 // Align to the (next) grid step. |
158 y = ash::WindowResizer::AlignToGridRoundUp(y, grid); | 158 y = ash::WindowResizer::AlignToGridRoundUp(y, grid); |
159 } | 159 } |
160 break; | 160 break; |
161 } | 161 } |
162 } | 162 } |
163 if (i >= regions.size()) | 163 if (i >= regions.size()) |
164 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); |
165 } | 165 } |
(...skipping 15 matching lines...) Expand all Loading... |
181 int h = pos.height(); | 181 int h = pos.height(); |
182 | 182 |
183 // If the alignment was pushing the window out of the screen, we ignore the | 183 // If the alignment was pushing the window out of the screen, we ignore the |
184 // alignment for that call. | 184 // alignment for that call. |
185 if (abs(pos.right() - work_area.right()) < grid) | 185 if (abs(pos.right() - work_area.right()) < grid) |
186 x = work_area.right() - w; | 186 x = work_area.right() - w; |
187 if (abs(pos.bottom() - work_area.bottom()) < grid) | 187 if (abs(pos.bottom() - work_area.bottom()) < grid) |
188 y = work_area.bottom() - h; | 188 y = work_area.bottom() - h; |
189 return gfx::Rect(x, y, w, h); | 189 return gfx::Rect(x, y, w, h); |
190 } | 190 } |
OLD | NEW |