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

Side by Side Diff: ash/wm/window_positioner.cc

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

Powered by Google App Engine
This is Rietveld 408576698