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

Side by Side Diff: ash/wm/workspace/auto_window_management.cc

Issue 11085053: Improving window auto management between workspaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed as requested. Corner cases will have to be addressed as they show Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/workspace/auto_window_management.h"
6
7 #include "ash/shell.h"
8 #include "ash/wm/window_animations.h"
9 #include "ash/wm/window_util.h"
10 #include "ui/aura/window.h"
11 #include "ui/compositor/layer_animator.h"
12 #include "ui/compositor/scoped_layer_animation_settings.h"
13 #include "ui/gfx/screen.h"
14
15 namespace ash {
16 namespace internal {
17
18 namespace {
19
20 // The time which should be used to visually move a window through an
21 // automatic "intelligent" window management option.
22 const base::TimeDelta kWindowAutoMoveDuration =
sky 2012/10/16 17:25:34 This triggers a static initializer, increasing sta
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
23 base::TimeDelta::FromMilliseconds(125);
24
25 // Check if the given |window| is visible on the screen and has therefore
sky 2012/10/16 17:25:34 This doesn't check visibility.
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
26 // an impact on the position manage ability. Note: The minimized/maximized
27 // state is not included in this test since a window which just got changed
28 // states might have an impact on the window management system.
29 bool WindowHasImpactOnPositioning(const aura::Window* window) {
30 return (!window->bounds().IsEmpty() && wm::IsWindowPositionManaged(window));
31 }
32
33 // Check if a given |window| is considered to be an auto location manageable
sky 2012/10/16 17:25:34 Clarify how this and WindowHasImpactOnPositioning
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
34 // window or not.
35 bool IsWindowPositionManageable(const aura::Window* window) {
36 return (WindowHasImpactOnPositioning(window) &&
37 !wm::IsWindowMinimized(window) &&
38 !wm::IsWindowMaximized(window) &&
39 !wm::HasUserChangedWindowPositionOrSize(window));
40 }
41
42 // Given a |window|, return the |work_area| of the desktop on which it is
43 // located as well as the only |other_window| which has an impact on the
44 // automated window location management. If there are more then one windows,
sky 2012/10/16 17:25:34 'there are' -> 'there is'
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
45 // false get returned, but the |other_window| will be set to the first one
sky 2012/10/16 17:25:34 get -> is
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
46 // found.
47 // If the return value is true a single window was found.
48 // Note: |work_area| is undefined if false is returned and |other_window| is
49 // NULL.
50 bool GetOtherVisibleAndManageableWindow(const aura::Window* window,
51 gfx::Rect* work_area,
52 aura::Window** other_window) {
53 *other_window = NULL;
54 // If the given window was not manageable, it cannot have caused a management
55 // operation earlier.
56 if (!WindowHasImpactOnPositioning(window))
57 return false;
58
59 // Get our work area.
60 *work_area = window->parent()->bounds();
sky 2012/10/16 17:25:34 *work_area = gfx::Rect(window->parent()->bounds().
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 I have the feeling that this (including the remova
61 work_area->Inset(Shell::GetScreen()->GetDisplayMatching(
62 *work_area).GetWorkAreaInsets());
63
64 const aura::Window::Windows& windows = window->parent()->children();
65 // Find a single open browser window.
sky 2012/10/16 17:25:34 browser -> managed
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
66 for (size_t i = 0; i < windows.size(); i++) {
67 aura::Window* j = windows[i];
sky 2012/10/16 17:25:34 nit: use something more descriptive than 'j'. 'j'
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
68 if (window != j && j->type() == aura::client::WINDOW_TYPE_NORMAL &&
69 work_area->Intersects(j->GetBoundsInScreen()) &&
sky 2012/10/16 17:25:34 You're comparing coordinates in different coordina
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
70 j->TargetVisibility() && WindowHasImpactOnPositioning(j)) {
71 // Bail if we find a second usable window.
72 if (*other_window)
73 return false;
74 *other_window = j;
75 }
76 }
77 return *other_window != NULL;
78 }
79
80 // Move the given |bounds| on the available |parent_width| to the
81 // direction. If |move_right| is true, the rectangle gets moved to the right
82 // corner, otherwise to the left one.
83 bool MoveRectToOneSide(int parent_width, gfx::Rect& bounds, bool move_right) {
sky 2012/10/16 17:25:34 gfx::Rect& -> gfx::Rect* and it should be the last
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
84 if (move_right) {
85 if (parent_width > bounds.right()) {
86 bounds.set_x(parent_width - bounds.width());
87 return true;
88 }
89 } else {
90 if (0 < bounds.x()) {
91 bounds.set_x(0);
92 return true;
93 }
94 }
95 return false;
96 }
97
98 } // namespace
99
100 // Check if after removal of the given |removed_window| an automated desktop
101 // location management can be performed and rearrange accordingly
102 void RearrangeVisibleWindowOnHide(const aura::Window* removed_window) {
103 // Find a single open browser window.
104 aura::Window* shown_window = NULL;
105 gfx::Rect work_area;
106 if (!GetOtherVisibleAndManageableWindow(removed_window,
107 &work_area,
108 &shown_window))
109 return;
110
111 if (IsWindowPositionManageable(shown_window)) {
112 // Center the window (only in x).
sky 2012/10/16 17:25:34 How come only in x? Shouldn't this restore to the
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Because we only center in X. There was no mentioni
113 gfx::Rect bounds = shown_window->bounds();
114 bounds.set_x((work_area.width() - bounds.width()) / 2);
115 if (bounds != shown_window->bounds()) {
116 ui::LayerAnimator* animator = shown_window->layer()->GetAnimator();
117 ui::ScopedLayerAnimationSettings animation_setter(animator);
118 animation_setter.SetTransitionDuration(kWindowAutoMoveDuration);
119 shown_window->SetBounds(bounds);
120 }
121 }
122 }
123
124 // Check if after insertion of the given |added_window| an automated desktop
sky 2012/10/16 17:25:34 Don't duplicate comments here.
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
125 // location management can be performed and rearrange accordingly.
126 void RearrangeVisibleWindowOnShow(aura::Window* added_window) {
127 // Find a single open browser window.
sky 2012/10/16 17:25:34 browser->managed
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Done.
128 aura::Window* shown_window = NULL;
129 gfx::Rect work_area;
130 if (!GetOtherVisibleAndManageableWindow(added_window,
131 &work_area,
132 &shown_window)) {
133 // It could be that this window is the first window joining the workspace.
134 if (!IsWindowPositionManageable(added_window) || shown_window)
135 return;
136 // If so we have to make sure it is centered.
sky 2012/10/16 17:25:34 How come you don't vertically center?
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Again - see comment above.
137 gfx::Rect bounds = added_window->bounds();
138 bounds.set_x((work_area.width() - bounds.width()) / 2);
139 added_window->SetBounds(bounds);
140 return;
141 }
142
143 if (IsWindowPositionManageable(shown_window)) {
144 // Push away the other window.
145 gfx::Rect other_bounds = shown_window->bounds();
146 bool move_right = other_bounds.CenterPoint().x() < work_area.width() / 2;
147 if (MoveRectToOneSide(work_area.width(), other_bounds, move_right)) {
148 if (other_bounds != shown_window->bounds()) {
149 ui::LayerAnimator* animator = shown_window->layer()->GetAnimator();
sky 2012/10/16 17:25:34 Don't animate if either of the are set: win
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 Sorry - isn't this something which belongs into th
sky 2012/10/16 22:01:14 Different packages.
150 ui::ScopedLayerAnimationSettings animation_setter(animator);
151 animation_setter.SetTransitionDuration(kWindowAutoMoveDuration);
152 shown_window->SetBounds(other_bounds);
153 }
154 }
155 // Push the new window also to the opposite location (if needed).
156 // Since it is just coming into view, we do not need to animate it.
157 gfx::Rect added_bounds = added_window->bounds();
158 if (MoveRectToOneSide(work_area.width(), added_bounds, !move_right))
159 added_window->SetBounds(added_bounds);
sky 2012/10/16 17:25:34 Don't you want to animate this too?
Mr4D (OOO till 08-26) 2012/10/16 19:00:28 No. As you can read in the comment above, this win
160 }
161 }
162
163 } // namespace internal
164 } // namespace ash
165
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698