OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/wm/window_positioner.h" | 5 #include "ash/wm/window_positioner.h" |
6 | 6 |
7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_port.h" | 9 #include "ash/shell_port.h" |
10 #include "ash/wm/mru_window_tracker.h" | 10 #include "ash/wm/mru_window_tracker.h" |
11 #include "ash/wm/window_positioning_utils.h" | 11 #include "ash/wm/window_positioning_utils.h" |
12 #include "ash/wm/window_state.h" | 12 #include "ash/wm/window_state.h" |
13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
14 #include "ash/wm_window.h" | 14 #include "ash/wm_window.h" |
15 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
16 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
17 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
18 #include "ui/gfx/geometry/insets.h" | 18 #include "ui/gfx/geometry/insets.h" |
| 19 #include "ui/wm/core/window_util.h" |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
21 | 22 |
22 const int WindowPositioner::kMinimumWindowOffset = 32; | 23 const int WindowPositioner::kMinimumWindowOffset = 32; |
23 | 24 |
24 // The number of pixels which are kept free top, left and right when a window | 25 // The number of pixels which are kept free top, left and right when a window |
25 // gets positioned to its default location. | 26 // gets positioned to its default location. |
26 // static | 27 // static |
27 const int WindowPositioner::kDesktopBorderSize = 16; | 28 const int WindowPositioner::kDesktopBorderSize = 16; |
28 | 29 |
(...skipping 13 matching lines...) Expand all Loading... |
42 const int kWindowAutoMoveDurationMS = 125; | 43 const int kWindowAutoMoveDurationMS = 125; |
43 | 44 |
44 // If set to true all window repositioning actions will be ignored. Set through | 45 // If set to true all window repositioning actions will be ignored. Set through |
45 // WindowPositioner::SetIgnoreActivations(). | 46 // WindowPositioner::SetIgnoreActivations(). |
46 static bool disable_auto_positioning = false; | 47 static bool disable_auto_positioning = false; |
47 | 48 |
48 // If set to true, by default the first window in ASH will be maximized. | 49 // If set to true, by default the first window in ASH will be maximized. |
49 static bool maximize_first_window = false; | 50 static bool maximize_first_window = false; |
50 | 51 |
51 // Check if any management should be performed (with a given |window|). | 52 // Check if any management should be performed (with a given |window|). |
52 bool UseAutoWindowManager(const WmWindow* window) { | 53 bool UseAutoWindowManager(const aura::Window* window) { |
53 if (disable_auto_positioning) | 54 if (disable_auto_positioning) |
54 return false; | 55 return false; |
55 const wm::WindowState* window_state = window->GetWindowState(); | 56 const wm::WindowState* window_state = wm::GetWindowState(window); |
56 return !window_state->is_dragged() && window_state->window_position_managed(); | 57 return !window_state->is_dragged() && window_state->window_position_managed(); |
57 } | 58 } |
58 | 59 |
59 // Check if a given |window| can be managed. This includes that its | 60 // Check if a given |window| can be managed. This includes that its |
60 // state is not minimized/maximized/fullscreen/the user has changed | 61 // state is not minimized/maximized/fullscreen/the user has changed |
61 // its size by hand already. It furthermore checks for the | 62 // its size by hand already. It furthermore checks for the |
62 // WindowIsManaged status. | 63 // WindowIsManaged status. |
63 bool WindowPositionCanBeManaged(const WmWindow* window) { | 64 bool WindowPositionCanBeManaged(const aura::Window* window) { |
64 if (disable_auto_positioning) | 65 if (disable_auto_positioning) |
65 return false; | 66 return false; |
66 const wm::WindowState* window_state = window->GetWindowState(); | 67 const wm::WindowState* window_state = wm::GetWindowState(window); |
67 return window_state->window_position_managed() && | 68 return window_state->window_position_managed() && |
68 !window_state->IsMinimized() && !window_state->IsMaximized() && | 69 !window_state->IsMinimized() && !window_state->IsMaximized() && |
69 !window_state->IsFullscreen() && !window_state->IsPinned() && | 70 !window_state->IsFullscreen() && !window_state->IsPinned() && |
70 !window_state->bounds_changed_by_user(); | 71 !window_state->bounds_changed_by_user(); |
71 } | 72 } |
72 | 73 |
73 // Move the given |bounds| on the available |work_area| in the direction | 74 // Move the given |bounds| on the available |work_area| in the direction |
74 // indicated by |move_right|. If |move_right| is true, the rectangle gets moved | 75 // indicated by |move_right|. If |move_right| is true, the rectangle gets moved |
75 // to the right edge, otherwise to the left one. | 76 // to the right edge, otherwise to the left one. |
76 bool MoveRectToOneSide(const gfx::Rect& work_area, | 77 bool MoveRectToOneSide(const gfx::Rect& work_area, |
77 bool move_right, | 78 bool move_right, |
78 gfx::Rect* bounds) { | 79 gfx::Rect* bounds) { |
79 if (move_right) { | 80 if (move_right) { |
80 if (work_area.right() > bounds->right()) { | 81 if (work_area.right() > bounds->right()) { |
81 bounds->set_x(work_area.right() - bounds->width()); | 82 bounds->set_x(work_area.right() - bounds->width()); |
82 return true; | 83 return true; |
83 } | 84 } |
84 } else { | 85 } else { |
85 if (work_area.x() < bounds->x()) { | 86 if (work_area.x() < bounds->x()) { |
86 bounds->set_x(work_area.x()); | 87 bounds->set_x(work_area.x()); |
87 return true; | 88 return true; |
88 } | 89 } |
89 } | 90 } |
90 return false; | 91 return false; |
91 } | 92 } |
92 | 93 |
93 // Move a |window| to new |bounds|. Animate if desired by user. | 94 // Move a |window| to new |bounds|. Animate if desired by user. |
94 // Moves the transient children of the |window| as well by the same |offset| as | 95 // Moves the transient children of the |window| as well by the same |offset| as |
95 // the parent |window|. | 96 // the parent |window|. |
96 void SetBoundsAndOffsetTransientChildren(WmWindow* window, | 97 void SetBoundsAndOffsetTransientChildren(aura::Window* window, |
97 const gfx::Rect& bounds, | 98 const gfx::Rect& bounds, |
98 const gfx::Rect& work_area, | 99 const gfx::Rect& work_area, |
99 const gfx::Vector2d& offset) { | 100 const gfx::Vector2d& offset) { |
100 std::vector<WmWindow*> transient_children = window->GetTransientChildren(); | 101 aura::Window::Windows transient_children = ::wm::GetTransientChildren(window); |
101 for (WmWindow* transient_child : transient_children) { | 102 for (auto* transient_child : transient_children) { |
102 gfx::Rect child_bounds = transient_child->GetBounds(); | 103 gfx::Rect child_bounds = transient_child->bounds(); |
103 gfx::Rect new_child_bounds = child_bounds + offset; | 104 gfx::Rect new_child_bounds = child_bounds + offset; |
104 if ((child_bounds.x() <= work_area.x() && | 105 if ((child_bounds.x() <= work_area.x() && |
105 new_child_bounds.x() <= work_area.x()) || | 106 new_child_bounds.x() <= work_area.x()) || |
106 (child_bounds.right() >= work_area.right() && | 107 (child_bounds.right() >= work_area.right() && |
107 new_child_bounds.right() >= work_area.right())) { | 108 new_child_bounds.right() >= work_area.right())) { |
108 continue; | 109 continue; |
109 } | 110 } |
110 if (new_child_bounds.right() > work_area.right()) | 111 if (new_child_bounds.right() > work_area.right()) |
111 new_child_bounds.set_x(work_area.right() - bounds.width()); | 112 new_child_bounds.set_x(work_area.right() - bounds.width()); |
112 else if (new_child_bounds.x() < work_area.x()) | 113 else if (new_child_bounds.x() < work_area.x()) |
113 new_child_bounds.set_x(work_area.x()); | 114 new_child_bounds.set_x(work_area.x()); |
114 SetBoundsAndOffsetTransientChildren(transient_child, new_child_bounds, | 115 SetBoundsAndOffsetTransientChildren(transient_child, new_child_bounds, |
115 work_area, offset); | 116 work_area, offset); |
116 } | 117 } |
117 | 118 |
118 window->SetBoundsWithTransitionDelay( | 119 if (::wm::WindowAnimationsDisabled(window)) { |
119 bounds, base::TimeDelta::FromMilliseconds(kWindowAutoMoveDurationMS)); | 120 window->SetBounds(bounds); |
| 121 return; |
| 122 } |
| 123 |
| 124 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 125 settings.SetTransitionDuration( |
| 126 base::TimeDelta::FromMilliseconds(kWindowAutoMoveDurationMS)); |
| 127 window->SetBounds(bounds); |
120 } | 128 } |
121 | 129 |
122 // Move a |window| to new |bounds|. Animate if desired by user. | 130 // Move a |window| to new |bounds|. Animate if desired by user. |
123 // Note: The function will do nothing if the bounds did not change. | 131 // Note: The function will do nothing if the bounds did not change. |
124 void SetBoundsAnimated(WmWindow* window, | 132 void SetBoundsAnimated(aura::Window* window, |
125 const gfx::Rect& bounds, | 133 const gfx::Rect& bounds, |
126 const gfx::Rect& work_area) { | 134 const gfx::Rect& work_area) { |
127 gfx::Rect old_bounds = window->GetTargetBounds(); | 135 gfx::Rect old_bounds = window->GetTargetBounds(); |
128 if (bounds == old_bounds) | 136 if (bounds == old_bounds) |
129 return; | 137 return; |
130 gfx::Vector2d offset(bounds.origin() - old_bounds.origin()); | 138 gfx::Vector2d offset(bounds.origin() - old_bounds.origin()); |
131 SetBoundsAndOffsetTransientChildren(window, bounds, work_area, offset); | 139 SetBoundsAndOffsetTransientChildren(window, bounds, work_area, offset); |
132 } | 140 } |
133 | 141 |
134 // Move |window| into the center of the screen - or restore it to the previous | 142 // Move |window| into the center of the screen - or restore it to the previous |
135 // position. | 143 // position. |
136 void AutoPlaceSingleWindow(WmWindow* window, bool animated) { | 144 void AutoPlaceSingleWindow(aura::Window* window, bool animated) { |
137 gfx::Rect work_area = | 145 gfx::Rect work_area = ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); |
138 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); | 146 gfx::Rect bounds = window->bounds(); |
139 gfx::Rect bounds = window->GetBounds(); | |
140 const gfx::Rect* user_defined_area = | 147 const gfx::Rect* user_defined_area = |
141 window->GetWindowState()->pre_auto_manage_window_bounds(); | 148 wm::GetWindowState(window)->pre_auto_manage_window_bounds(); |
142 if (user_defined_area) { | 149 if (user_defined_area) { |
143 bounds = *user_defined_area; | 150 bounds = *user_defined_area; |
144 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &bounds); | 151 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &bounds); |
145 } else { | 152 } else { |
146 // Center the window (only in x). | 153 // Center the window (only in x). |
147 bounds.set_x(work_area.x() + (work_area.width() - bounds.width()) / 2); | 154 bounds.set_x(work_area.x() + (work_area.width() - bounds.width()) / 2); |
148 } | 155 } |
149 | 156 |
150 if (animated) | 157 if (animated) |
151 SetBoundsAnimated(window, bounds, work_area); | 158 SetBoundsAnimated(window, bounds, work_area); |
152 else | 159 else |
153 window->SetBounds(bounds); | 160 window->SetBounds(bounds); |
154 } | 161 } |
155 | 162 |
156 // Get the first open (non minimized) window which is on the screen defined. | 163 // Get the first open (non minimized) window which is on the screen defined. |
157 WmWindow* GetReferenceWindow(const WmWindow* root_window, | 164 aura::Window* GetReferenceWindow(const aura::Window* root_window, |
158 const WmWindow* exclude, | 165 const aura::Window* exclude, |
159 bool* single_window) { | 166 bool* single_window) { |
160 if (single_window) | 167 if (single_window) |
161 *single_window = true; | 168 *single_window = true; |
162 // Get the active window. | 169 // Get the active window. |
163 WmWindow* active = WmWindow::Get(wm::GetActiveWindow()); | 170 aura::Window* active = wm::GetActiveWindow(); |
164 if (active && active->GetRootWindow() != root_window) | 171 if (active && active->GetRootWindow() != root_window) |
165 active = NULL; | 172 active = NULL; |
166 | 173 |
167 // Get a list of all windows. | 174 // Get a list of all windows. |
168 const std::vector<WmWindow*> windows = | 175 const aura::Window::Windows windows = |
169 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); | 176 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); |
170 | 177 |
171 if (windows.empty()) | 178 if (windows.empty()) |
172 return nullptr; | 179 return nullptr; |
173 | 180 |
174 int index = 0; | 181 int index = 0; |
175 // Find the index of the current active window. | 182 // Find the index of the current active window. |
176 if (active) | 183 if (active) |
177 index = std::find(windows.begin(), windows.end(), active) - windows.begin(); | 184 index = std::find(windows.begin(), windows.end(), active) - windows.begin(); |
178 | 185 |
179 // Scan the cycle list backwards to see which is the second topmost window | 186 // Scan the cycle list backwards to see which is the second topmost window |
180 // (and so on). Note that we might cycle a few indices twice if there is no | 187 // (and so on). Note that we might cycle a few indices twice if there is no |
181 // suitable window. However - since the list is fairly small this should be | 188 // suitable window. However - since the list is fairly small this should be |
182 // very fast anyways. | 189 // very fast anyways. |
183 WmWindow* found = nullptr; | 190 aura::Window* found = nullptr; |
184 for (int i = index + windows.size(); i >= 0; i--) { | 191 for (int i = index + windows.size(); i >= 0; i--) { |
185 WmWindow* window = windows[i % windows.size()]; | 192 aura::Window* window = windows[i % windows.size()]; |
186 while (window->GetTransientParent()) | 193 while (::wm::GetTransientParent(window)) |
187 window = window->GetTransientParent(); | 194 window = ::wm::GetTransientParent(window); |
188 if (window != exclude && window->GetType() == ui::wm::WINDOW_TYPE_NORMAL && | 195 if (window != exclude && window->type() == ui::wm::WINDOW_TYPE_NORMAL && |
189 window->GetRootWindow() == root_window && | 196 window->GetRootWindow() == root_window && window->TargetVisibility() && |
190 window->GetTargetVisibility() && | 197 wm::GetWindowState(window)->window_position_managed()) { |
191 window->GetWindowState()->window_position_managed()) { | |
192 if (found && found != window) { | 198 if (found && found != window) { |
193 // no need to check !single_window because the function must have | 199 // no need to check !single_window because the function must have |
194 // been already returned in the "if (!single_window)" below. | 200 // been already returned in the "if (!single_window)" below. |
195 *single_window = false; | 201 *single_window = false; |
196 return found; | 202 return found; |
197 } | 203 } |
198 found = window; | 204 found = window; |
199 // If there is no need to check single window, return now. | 205 // If there is no need to check single window, return now. |
200 if (!single_window) | 206 if (!single_window) |
201 return found; | 207 return found; |
202 } | 208 } |
203 } | 209 } |
204 return found; | 210 return found; |
205 } | 211 } |
206 | 212 |
207 } // namespace | 213 } // namespace |
208 | 214 |
209 // static | 215 // static |
210 int WindowPositioner::GetForceMaximizedWidthLimit() { | 216 int WindowPositioner::GetForceMaximizedWidthLimit() { |
211 return kForceMaximizeWidthLimit; | 217 return kForceMaximizeWidthLimit; |
212 } | 218 } |
213 | 219 |
214 // static | 220 // static |
215 void WindowPositioner::GetBoundsAndShowStateForNewWindow( | 221 void WindowPositioner::GetBoundsAndShowStateForNewWindow( |
216 const WmWindow* new_window, | 222 const aura::Window* new_window, |
217 bool is_saved_bounds, | 223 bool is_saved_bounds, |
218 ui::WindowShowState show_state_in, | 224 ui::WindowShowState show_state_in, |
219 gfx::Rect* bounds_in_out, | 225 gfx::Rect* bounds_in_out, |
220 ui::WindowShowState* show_state_out) { | 226 ui::WindowShowState* show_state_out) { |
221 // Always open new window in the target display. | 227 // Always open new window in the target display. |
222 aura::Window* target = Shell::GetRootWindowForNewWindows(); | 228 aura::Window* target = Shell::GetRootWindowForNewWindows(); |
223 | 229 |
224 WmWindow* top_window = | 230 aura::Window* top_window = GetReferenceWindow(target, nullptr, nullptr); |
225 GetReferenceWindow(WmWindow::Get(target), nullptr, nullptr); | |
226 // Our window should not have any impact if we are already on top. | 231 // Our window should not have any impact if we are already on top. |
227 if (top_window == new_window) | 232 if (top_window == new_window) |
228 top_window = nullptr; | 233 top_window = nullptr; |
229 | 234 |
230 // If there is no valid other window we take and adjust the passed coordinates | 235 // If there is no valid other window we take and adjust the passed coordinates |
231 // and show state. | 236 // and show state. |
232 if (!top_window) { | 237 if (!top_window) { |
233 gfx::Rect work_area = display::Screen::GetScreen() | 238 gfx::Rect work_area = display::Screen::GetScreen() |
234 ->GetDisplayNearestWindow(target) | 239 ->GetDisplayNearestWindow(target) |
235 .work_area(); | 240 .work_area(); |
236 | 241 |
237 bounds_in_out->AdjustToFit(work_area); | 242 bounds_in_out->AdjustToFit(work_area); |
238 // Use adjusted saved bounds, if there is one. | 243 // Use adjusted saved bounds, if there is one. |
239 if (is_saved_bounds) | 244 if (is_saved_bounds) |
240 return; | 245 return; |
241 | 246 |
242 if (show_state_in == ui::SHOW_STATE_DEFAULT) { | 247 if (show_state_in == ui::SHOW_STATE_DEFAULT) { |
243 const bool maximize_first_window_on_first_run = | 248 const bool maximize_first_window_on_first_run = |
244 ShellPort::Get()->IsForceMaximizeOnFirstRun(); | 249 ShellPort::Get()->IsForceMaximizeOnFirstRun(); |
245 // We want to always open maximized on "small screens" or when policy | 250 // We want to always open maximized on "small screens" or when policy |
246 // tells us to. | 251 // tells us to. |
247 const bool set_maximized = | 252 const bool set_maximized = |
248 maximize_first_window || | 253 maximize_first_window || |
249 ((work_area.width() <= GetForceMaximizedWidthLimit() || | 254 ((work_area.width() <= GetForceMaximizedWidthLimit() || |
250 maximize_first_window_on_first_run) && | 255 maximize_first_window_on_first_run) && |
251 (!new_window || !new_window->GetWindowState()->IsFullscreen())); | 256 (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())); |
252 | 257 |
253 if (set_maximized) | 258 if (set_maximized) |
254 *show_state_out = ui::SHOW_STATE_MAXIMIZED; | 259 *show_state_out = ui::SHOW_STATE_MAXIMIZED; |
255 } | 260 } |
256 return; | 261 return; |
257 } | 262 } |
258 | 263 |
259 wm::WindowState* top_window_state = top_window->GetWindowState(); | 264 wm::WindowState* top_window_state = wm::GetWindowState(top_window); |
260 bool maximized = top_window_state->IsMaximized(); | 265 bool maximized = top_window_state->IsMaximized(); |
261 // We ignore the saved show state, but look instead for the top level | 266 // We ignore the saved show state, but look instead for the top level |
262 // window's show state. | 267 // window's show state. |
263 if (show_state_in == ui::SHOW_STATE_DEFAULT) { | 268 if (show_state_in == ui::SHOW_STATE_DEFAULT) { |
264 *show_state_out = | 269 *show_state_out = |
265 maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_DEFAULT; | 270 maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_DEFAULT; |
266 } | 271 } |
267 | 272 |
268 if (maximized || top_window_state->IsFullscreen()) { | 273 if (maximized || top_window_state->IsFullscreen()) { |
269 bool has_restore_bounds = top_window_state->HasRestoreBounds(); | 274 bool has_restore_bounds = top_window_state->HasRestoreBounds(); |
(...skipping 16 matching lines...) Expand all Loading... |
286 } | 291 } |
287 } | 292 } |
288 | 293 |
289 // Use the size of the other window. The window's bound will be rearranged | 294 // Use the size of the other window. The window's bound will be rearranged |
290 // in ash::WorkspaceLayoutManager using this location. | 295 // in ash::WorkspaceLayoutManager using this location. |
291 *bounds_in_out = top_window->GetBoundsInScreen(); | 296 *bounds_in_out = top_window->GetBoundsInScreen(); |
292 } | 297 } |
293 | 298 |
294 // static | 299 // static |
295 void WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( | 300 void WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( |
296 const WmWindow* removed_window) { | 301 const aura::Window* removed_window) { |
297 if (!UseAutoWindowManager(removed_window)) | 302 if (!UseAutoWindowManager(removed_window)) |
298 return; | 303 return; |
299 // Find a single open browser window. | 304 // Find a single open browser window. |
300 bool single_window; | 305 bool single_window; |
301 WmWindow* other_shown_window = GetReferenceWindow( | 306 aura::Window* other_shown_window = GetReferenceWindow( |
302 removed_window->GetRootWindow(), removed_window, &single_window); | 307 removed_window->GetRootWindow(), removed_window, &single_window); |
303 if (!other_shown_window || !single_window || | 308 if (!other_shown_window || !single_window || |
304 !WindowPositionCanBeManaged(other_shown_window)) | 309 !WindowPositionCanBeManaged(other_shown_window)) |
305 return; | 310 return; |
306 AutoPlaceSingleWindow(other_shown_window, true); | 311 AutoPlaceSingleWindow(other_shown_window, true); |
307 } | 312 } |
308 | 313 |
309 // static | 314 // static |
310 bool WindowPositioner::DisableAutoPositioning(bool ignore) { | 315 bool WindowPositioner::DisableAutoPositioning(bool ignore) { |
311 bool old_state = disable_auto_positioning; | 316 bool old_state = disable_auto_positioning; |
312 disable_auto_positioning = ignore; | 317 disable_auto_positioning = ignore; |
313 return old_state; | 318 return old_state; |
314 } | 319 } |
315 | 320 |
316 // static | 321 // static |
317 void WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow* added_window) { | 322 void WindowPositioner::RearrangeVisibleWindowOnShow( |
318 wm::WindowState* added_window_state = added_window->GetWindowState(); | 323 aura::Window* added_window) { |
319 if (!added_window->GetTargetVisibility()) | 324 wm::WindowState* added_window_state = wm::GetWindowState(added_window); |
| 325 if (!added_window->TargetVisibility()) |
320 return; | 326 return; |
321 | 327 |
322 if (!UseAutoWindowManager(added_window) || | 328 if (!UseAutoWindowManager(added_window) || |
323 added_window_state->bounds_changed_by_user()) { | 329 added_window_state->bounds_changed_by_user()) { |
324 if (added_window_state->minimum_visibility()) { | 330 if (added_window_state->minimum_visibility()) { |
325 // Guarantee minimum visibility within the work area. | 331 // Guarantee minimum visibility within the work area. |
326 gfx::Rect work_area = ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 332 gfx::Rect work_area = |
327 added_window->aura_window()); | 333 ScreenUtil::GetDisplayWorkAreaBoundsInParent(added_window); |
328 gfx::Rect bounds = added_window->GetBounds(); | 334 gfx::Rect bounds = added_window->bounds(); |
329 gfx::Rect new_bounds = bounds; | 335 gfx::Rect new_bounds = bounds; |
330 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &new_bounds); | 336 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &new_bounds); |
331 if (new_bounds != bounds) | 337 if (new_bounds != bounds) |
332 added_window->SetBounds(new_bounds); | 338 added_window->SetBounds(new_bounds); |
333 } | 339 } |
334 return; | 340 return; |
335 } | 341 } |
336 // Find a single open managed window. | 342 // Find a single open managed window. |
337 bool single_window; | 343 bool single_window; |
338 WmWindow* other_shown_window = GetReferenceWindow( | 344 aura::Window* other_shown_window = GetReferenceWindow( |
339 added_window->GetRootWindow(), added_window, &single_window); | 345 added_window->GetRootWindow(), added_window, &single_window); |
340 | 346 |
341 if (!other_shown_window) { | 347 if (!other_shown_window) { |
342 // It could be that this window is the first window joining the workspace. | 348 // It could be that this window is the first window joining the workspace. |
343 if (!WindowPositionCanBeManaged(added_window) || other_shown_window) | 349 if (!WindowPositionCanBeManaged(added_window) || other_shown_window) |
344 return; | 350 return; |
345 // Since we might be going from 0 to 1 window, we have to arrange the new | 351 // Since we might be going from 0 to 1 window, we have to arrange the new |
346 // window to a good default. | 352 // window to a good default. |
347 AutoPlaceSingleWindow(added_window, false); | 353 AutoPlaceSingleWindow(added_window, false); |
348 return; | 354 return; |
349 } | 355 } |
350 | 356 |
351 gfx::Rect other_bounds = other_shown_window->GetBounds(); | 357 gfx::Rect other_bounds = other_shown_window->bounds(); |
352 gfx::Rect work_area = | 358 gfx::Rect work_area = |
353 ScreenUtil::GetDisplayWorkAreaBoundsInParent(added_window->aura_window()); | 359 ScreenUtil::GetDisplayWorkAreaBoundsInParent(added_window); |
354 bool move_other_right = | 360 bool move_other_right = |
355 other_bounds.CenterPoint().x() > work_area.x() + work_area.width() / 2; | 361 other_bounds.CenterPoint().x() > work_area.x() + work_area.width() / 2; |
356 | 362 |
357 // Push the other window to the size only if there are two windows left. | 363 // Push the other window to the size only if there are two windows left. |
358 if (single_window) { | 364 if (single_window) { |
359 // When going from one to two windows both windows loose their | 365 // When going from one to two windows both windows loose their |
360 // "positioned by user" flags. | 366 // "positioned by user" flags. |
361 added_window_state->set_bounds_changed_by_user(false); | 367 added_window_state->set_bounds_changed_by_user(false); |
362 wm::WindowState* other_window_state = other_shown_window->GetWindowState(); | 368 wm::WindowState* other_window_state = |
| 369 wm::GetWindowState(other_shown_window); |
363 other_window_state->set_bounds_changed_by_user(false); | 370 other_window_state->set_bounds_changed_by_user(false); |
364 | 371 |
365 if (WindowPositionCanBeManaged(other_shown_window)) { | 372 if (WindowPositionCanBeManaged(other_shown_window)) { |
366 // Don't override pre auto managed bounds as the current bounds | 373 // Don't override pre auto managed bounds as the current bounds |
367 // may not be original. | 374 // may not be original. |
368 if (!other_window_state->pre_auto_manage_window_bounds()) | 375 if (!other_window_state->pre_auto_manage_window_bounds()) |
369 other_window_state->SetPreAutoManageWindowBounds(other_bounds); | 376 other_window_state->SetPreAutoManageWindowBounds(other_bounds); |
370 | 377 |
371 // Push away the other window after remembering its current position. | 378 // Push away the other window after remembering its current position. |
372 if (MoveRectToOneSide(work_area, move_other_right, &other_bounds)) | 379 if (MoveRectToOneSide(work_area, move_other_right, &other_bounds)) |
373 SetBoundsAnimated(other_shown_window, other_bounds, work_area); | 380 SetBoundsAnimated(other_shown_window, other_bounds, work_area); |
374 } | 381 } |
375 } | 382 } |
376 | 383 |
377 // Remember the current location of the window if it's new and push | 384 // Remember the current location of the window if it's new and push |
378 // it also to the opposite location if needed. Since it is just | 385 // it also to the opposite location if needed. Since it is just |
379 // being shown, we do not need to animate it. | 386 // being shown, we do not need to animate it. |
380 gfx::Rect added_bounds = added_window->GetBounds(); | 387 gfx::Rect added_bounds = added_window->bounds(); |
381 if (!added_window_state->pre_auto_manage_window_bounds()) | 388 if (!added_window_state->pre_auto_manage_window_bounds()) |
382 added_window_state->SetPreAutoManageWindowBounds(added_bounds); | 389 added_window_state->SetPreAutoManageWindowBounds(added_bounds); |
383 if (MoveRectToOneSide(work_area, !move_other_right, &added_bounds)) | 390 if (MoveRectToOneSide(work_area, !move_other_right, &added_bounds)) |
384 added_window->SetBounds(added_bounds); | 391 added_window->SetBounds(added_bounds); |
385 } | 392 } |
386 | 393 |
387 WindowPositioner::WindowPositioner() | 394 WindowPositioner::WindowPositioner() |
388 : pop_position_offset_increment_x(0), | 395 : pop_position_offset_increment_x(0), |
389 pop_position_offset_increment_y(0), | 396 pop_position_offset_increment_y(0), |
390 popup_position_offset_from_screen_corner_x(0), | 397 popup_position_offset_from_screen_corner_x(0), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (!reset) { | 485 if (!reset) { |
479 last_popup_position_x_ += pop_position_offset_increment_x; | 486 last_popup_position_x_ += pop_position_offset_increment_x; |
480 last_popup_position_y_ += pop_position_offset_increment_y; | 487 last_popup_position_y_ += pop_position_offset_increment_y; |
481 } | 488 } |
482 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); | 489 return gfx::Rect(x + work_area.x(), y + work_area.y(), w, h); |
483 } | 490 } |
484 | 491 |
485 gfx::Rect WindowPositioner::SmartPopupPosition(const gfx::Rect& old_pos, | 492 gfx::Rect WindowPositioner::SmartPopupPosition(const gfx::Rect& old_pos, |
486 const gfx::Rect& work_area, | 493 const gfx::Rect& work_area, |
487 int grid) { | 494 int grid) { |
488 const std::vector<WmWindow*> windows = | 495 const aura::Window::Windows windows = |
489 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); | 496 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); |
490 | 497 |
491 std::vector<const gfx::Rect*> regions; | 498 std::vector<const gfx::Rect*> regions; |
492 // Process the window list and check if we can bail immediately. | 499 // Process the window list and check if we can bail immediately. |
493 for (size_t i = 0; i < windows.size(); i++) { | 500 for (size_t i = 0; i < windows.size(); i++) { |
494 // We only include opaque and visible windows. | 501 // We only include opaque and visible windows. |
495 if (windows[i] && windows[i]->IsVisible() && windows[i]->GetLayer() && | 502 if (windows[i] && windows[i]->IsVisible() && windows[i]->layer() && |
496 (windows[i]->GetLayer()->fills_bounds_opaquely() || | 503 (windows[i]->layer()->fills_bounds_opaquely() || |
497 windows[i]->GetLayer()->GetTargetOpacity() == 1.0)) { | 504 windows[i]->layer()->GetTargetOpacity() == 1.0)) { |
498 wm::WindowState* window_state = windows[i]->GetWindowState(); | 505 wm::WindowState* window_state = wm::GetWindowState(windows[i]); |
499 // When any window is maximized we cannot find any free space. | 506 // When any window is maximized we cannot find any free space. |
500 if (window_state->IsMaximizedOrFullscreenOrPinned()) | 507 if (window_state->IsMaximizedOrFullscreenOrPinned()) |
501 return gfx::Rect(0, 0, 0, 0); | 508 return gfx::Rect(0, 0, 0, 0); |
502 if (window_state->IsNormalOrSnapped()) | 509 if (window_state->IsNormalOrSnapped()) |
503 regions.push_back(&windows[i]->GetBounds()); | 510 regions.push_back(&windows[i]->bounds()); |
504 } | 511 } |
505 } | 512 } |
506 | 513 |
507 if (regions.empty()) | 514 if (regions.empty()) |
508 return gfx::Rect(0, 0, 0, 0); | 515 return gfx::Rect(0, 0, 0, 0); |
509 | 516 |
510 int w = old_pos.width(); | 517 int w = old_pos.width(); |
511 int h = old_pos.height(); | 518 int h = old_pos.height(); |
512 int x_end = work_area.width() / 2; | 519 int x_end = work_area.width() / 2; |
513 int x, x_increment; | 520 int x, x_increment; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // If the alignment was pushing the window out of the screen, we ignore the | 570 // If the alignment was pushing the window out of the screen, we ignore the |
564 // alignment for that call. | 571 // alignment for that call. |
565 if (abs(pos.right() - work_area.right()) < grid) | 572 if (abs(pos.right() - work_area.right()) < grid) |
566 x = work_area.right() - w; | 573 x = work_area.right() - w; |
567 if (abs(pos.bottom() - work_area.bottom()) < grid) | 574 if (abs(pos.bottom() - work_area.bottom()) < grid) |
568 y = work_area.bottom() - h; | 575 y = work_area.bottom() - h; |
569 return gfx::Rect(x, y, w, h); | 576 return gfx::Rect(x, y, w, h); |
570 } | 577 } |
571 | 578 |
572 } // namespace ash | 579 } // namespace ash |
OLD | NEW |