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

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

Issue 2860163005: chromeos: gets rid of wm_screen_util (Closed)
Patch Set: include 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/shell.h" 8 #include "ash/shell.h"
8 #include "ash/shell_port.h" 9 #include "ash/shell_port.h"
9 #include "ash/wm/mru_window_tracker.h" 10 #include "ash/wm/mru_window_tracker.h"
10 #include "ash/wm/window_positioning_utils.h" 11 #include "ash/wm/window_positioning_utils.h"
11 #include "ash/wm/window_state.h" 12 #include "ash/wm/window_state.h"
12 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
13 #include "ash/wm/wm_screen_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 19
20 namespace ash { 20 namespace ash {
21 21
22 const int WindowPositioner::kMinimumWindowOffset = 32; 22 const int WindowPositioner::kMinimumWindowOffset = 32;
23 23
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 gfx::Rect old_bounds = window->GetTargetBounds(); 127 gfx::Rect old_bounds = window->GetTargetBounds();
128 if (bounds == old_bounds) 128 if (bounds == old_bounds)
129 return; 129 return;
130 gfx::Vector2d offset(bounds.origin() - old_bounds.origin()); 130 gfx::Vector2d offset(bounds.origin() - old_bounds.origin());
131 SetBoundsAndOffsetTransientChildren(window, bounds, work_area, offset); 131 SetBoundsAndOffsetTransientChildren(window, bounds, work_area, offset);
132 } 132 }
133 133
134 // Move |window| into the center of the screen - or restore it to the previous 134 // Move |window| into the center of the screen - or restore it to the previous
135 // position. 135 // position.
136 void AutoPlaceSingleWindow(WmWindow* window, bool animated) { 136 void AutoPlaceSingleWindow(WmWindow* window, bool animated) {
137 gfx::Rect work_area = wm::GetDisplayWorkAreaBoundsInParent(window); 137 gfx::Rect work_area =
138 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window());
138 gfx::Rect bounds = window->GetBounds(); 139 gfx::Rect bounds = window->GetBounds();
139 const gfx::Rect* user_defined_area = 140 const gfx::Rect* user_defined_area =
140 window->GetWindowState()->pre_auto_manage_window_bounds(); 141 window->GetWindowState()->pre_auto_manage_window_bounds();
141 if (user_defined_area) { 142 if (user_defined_area) {
142 bounds = *user_defined_area; 143 bounds = *user_defined_area;
143 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &bounds); 144 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &bounds);
144 } else { 145 } else {
145 // Center the window (only in x). 146 // Center the window (only in x).
146 bounds.set_x(work_area.x() + (work_area.width() - bounds.width()) / 2); 147 bounds.set_x(work_area.x() + (work_area.width() - bounds.width()) / 2);
147 } 148 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // static 311 // static
311 void WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow* added_window) { 312 void WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow* added_window) {
312 wm::WindowState* added_window_state = added_window->GetWindowState(); 313 wm::WindowState* added_window_state = added_window->GetWindowState();
313 if (!added_window->GetTargetVisibility()) 314 if (!added_window->GetTargetVisibility())
314 return; 315 return;
315 316
316 if (!UseAutoWindowManager(added_window) || 317 if (!UseAutoWindowManager(added_window) ||
317 added_window_state->bounds_changed_by_user()) { 318 added_window_state->bounds_changed_by_user()) {
318 if (added_window_state->minimum_visibility()) { 319 if (added_window_state->minimum_visibility()) {
319 // Guarantee minimum visibility within the work area. 320 // Guarantee minimum visibility within the work area.
320 gfx::Rect work_area = wm::GetDisplayWorkAreaBoundsInParent(added_window); 321 gfx::Rect work_area = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
322 added_window->aura_window());
321 gfx::Rect bounds = added_window->GetBounds(); 323 gfx::Rect bounds = added_window->GetBounds();
322 gfx::Rect new_bounds = bounds; 324 gfx::Rect new_bounds = bounds;
323 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &new_bounds); 325 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &new_bounds);
324 if (new_bounds != bounds) 326 if (new_bounds != bounds)
325 added_window->SetBounds(new_bounds); 327 added_window->SetBounds(new_bounds);
326 } 328 }
327 return; 329 return;
328 } 330 }
329 // Find a single open managed window. 331 // Find a single open managed window.
330 bool single_window; 332 bool single_window;
331 WmWindow* other_shown_window = GetReferenceWindow( 333 WmWindow* other_shown_window = GetReferenceWindow(
332 added_window->GetRootWindow(), added_window, &single_window); 334 added_window->GetRootWindow(), added_window, &single_window);
333 335
334 if (!other_shown_window) { 336 if (!other_shown_window) {
335 // It could be that this window is the first window joining the workspace. 337 // It could be that this window is the first window joining the workspace.
336 if (!WindowPositionCanBeManaged(added_window) || other_shown_window) 338 if (!WindowPositionCanBeManaged(added_window) || other_shown_window)
337 return; 339 return;
338 // Since we might be going from 0 to 1 window, we have to arrange the new 340 // Since we might be going from 0 to 1 window, we have to arrange the new
339 // window to a good default. 341 // window to a good default.
340 AutoPlaceSingleWindow(added_window, false); 342 AutoPlaceSingleWindow(added_window, false);
341 return; 343 return;
342 } 344 }
343 345
344 gfx::Rect other_bounds = other_shown_window->GetBounds(); 346 gfx::Rect other_bounds = other_shown_window->GetBounds();
345 gfx::Rect work_area = wm::GetDisplayWorkAreaBoundsInParent(added_window); 347 gfx::Rect work_area =
348 ScreenUtil::GetDisplayWorkAreaBoundsInParent(added_window->aura_window());
346 bool move_other_right = 349 bool move_other_right =
347 other_bounds.CenterPoint().x() > work_area.x() + work_area.width() / 2; 350 other_bounds.CenterPoint().x() > work_area.x() + work_area.width() / 2;
348 351
349 // Push the other window to the size only if there are two windows left. 352 // Push the other window to the size only if there are two windows left.
350 if (single_window) { 353 if (single_window) {
351 // When going from one to two windows both windows loose their 354 // When going from one to two windows both windows loose their
352 // "positioned by user" flags. 355 // "positioned by user" flags.
353 added_window_state->set_bounds_changed_by_user(false); 356 added_window_state->set_bounds_changed_by_user(false);
354 wm::WindowState* other_window_state = other_shown_window->GetWindowState(); 357 wm::WindowState* other_window_state = other_shown_window->GetWindowState();
355 other_window_state->set_bounds_changed_by_user(false); 358 other_window_state->set_bounds_changed_by_user(false);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 // If the alignment was pushing the window out of the screen, we ignore the 558 // If the alignment was pushing the window out of the screen, we ignore the
556 // alignment for that call. 559 // alignment for that call.
557 if (abs(pos.right() - work_area.right()) < grid) 560 if (abs(pos.right() - work_area.right()) < grid)
558 x = work_area.right() - w; 561 x = work_area.right() - w;
559 if (abs(pos.bottom() - work_area.bottom()) < grid) 562 if (abs(pos.bottom() - work_area.bottom()) < grid)
560 y = work_area.bottom() - h; 563 y = work_area.bottom() - h;
561 return gfx::Rect(x, y, w, h); 564 return gfx::Rect(x, y, w, h);
562 } 565 }
563 566
564 } // namespace ash 567 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698