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

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

Issue 21979005: Make sure that 30%of restored window is always visible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
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 "ash/wm/workspace/workspace_layout_manager.h" 5 #include "ash/wm/workspace/workspace_layout_manager.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 14 matching lines...) Expand all
25 #include "ui/views/corewm/window_util.h" 25 #include "ui/views/corewm/window_util.h"
26 26
27 using aura::Window; 27 using aura::Window;
28 28
29 namespace ash { 29 namespace ash {
30 30
31 namespace internal { 31 namespace internal {
32 32
33 namespace { 33 namespace {
34 34
35 // This specifies how much percent (2/3=66%) of a window must be visible when 35 // This specifies how much percent 1/3 of a window rect (width / height)
36 // the window is added to the workspace. 36 // must be visible when the window is added to the workspace.
Mr4D (OOO till 08-26) 2013/08/06 20:22:51 you might want to say 30% - seems better then 1/3.
oshima 2013/08/06 23:13:20 Done.
37 const float kMinimumPercentOnScreenArea = 0.66f; 37 const float kMinimumPercentOnScreenArea = 0.33f;
38 38
39 bool IsMaximizedState(ui::WindowShowState state) { 39 bool IsMaximizedState(ui::WindowShowState state) {
40 return state == ui::SHOW_STATE_MAXIMIZED || 40 return state == ui::SHOW_STATE_MAXIMIZED ||
41 state == ui::SHOW_STATE_FULLSCREEN; 41 state == ui::SHOW_STATE_FULLSCREEN;
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) 46 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window)
47 : BaseLayoutManager(window->GetRootWindow()), 47 : BaseLayoutManager(window->GetRootWindow()),
48 shelf_(NULL), 48 shelf_(NULL),
49 window_(window), 49 window_(window),
50 work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 50 work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
51 window->parent())) { 51 window->parent())) {
52 } 52 }
53 53
54 WorkspaceLayoutManager::~WorkspaceLayoutManager() { 54 WorkspaceLayoutManager::~WorkspaceLayoutManager() {
55 } 55 }
56 56
57 void WorkspaceLayoutManager::SetShelf(internal::ShelfLayoutManager* shelf) { 57 void WorkspaceLayoutManager::SetShelf(internal::ShelfLayoutManager* shelf) {
58 shelf_ = shelf; 58 shelf_ = shelf;
59 } 59 }
60 60
61 void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) { 61 void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) {
62 // Adjust window bounds in case that the new child is out of the workspace. 62 // Adjust window bounds in case that the new child is out of the workspace.
Mr4D (OOO till 08-26) 2013/08/06 20:22:51 You should at least change the comment to explain
oshima 2013/08/06 23:13:20 Done.
63 AdjustWindowSizeForScreenChange(child, ADJUST_WINDOW_WINDOW_ADDED); 63 if (!child->bounds().IsEmpty() &&
64 !wm::HasUserChangedWindowPositionOrSize(child))
65 AdjustWindowBounds(child, ADJUST_WINDOW_WINDOW_ADDED);
64 BaseLayoutManager::OnWindowAddedToLayout(child); 66 BaseLayoutManager::OnWindowAddedToLayout(child);
65 UpdateDesktopVisibility(); 67 UpdateDesktopVisibility();
66 RearrangeVisibleWindowOnShow(child); 68 RearrangeVisibleWindowOnShow(child);
67 } 69 }
68 70
69 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) { 71 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(Window* child) {
70 BaseLayoutManager::OnWillRemoveWindowFromLayout(child); 72 BaseLayoutManager::OnWillRemoveWindowFromLayout(child);
71 if (child->TargetVisibility()) 73 if (child->TargetVisibility())
72 RearrangeVisibleWindowOnHideOrRemove(child); 74 RearrangeVisibleWindowOnHideOrRemove(child);
73 } 75 }
(...skipping 30 matching lines...) Expand all
104 std::min(work_area_.height(), child_bounds.height())); 106 std::min(work_area_.height(), child_bounds.height()));
105 SetChildBoundsDirect(child, child_bounds); 107 SetChildBoundsDirect(child, child_bounds);
106 } 108 }
107 UpdateDesktopVisibility(); 109 UpdateDesktopVisibility();
108 } 110 }
109 111
110 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { 112 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() {
111 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 113 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
112 window_->parent())); 114 window_->parent()));
113 if (work_area != work_area_) 115 if (work_area != work_area_)
114 AdjustWindowSizesForScreenChange(ADJUST_WINDOW_DISPLAY_INSETS_CHANGED); 116 AdjustWindowsBounds(ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED);
115 } 117 }
116 118
117 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window, 119 void WorkspaceLayoutManager::OnWindowPropertyChanged(Window* window,
118 const void* key, 120 const void* key,
119 intptr_t old) { 121 intptr_t old) {
120 if (key == aura::client::kShowStateKey) { 122 if (key == aura::client::kShowStateKey) {
121 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); 123 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old);
122 ui::WindowShowState new_state = 124 ui::WindowShowState new_state =
123 window->GetProperty(aura::client::kShowStateKey); 125 window->GetProperty(aura::client::kShowStateKey);
124 if (old_state != ui::SHOW_STATE_MINIMIZED && 126 if (old_state != ui::SHOW_STATE_MINIMIZED &&
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 165 }
164 } 166 }
165 167
166 void WorkspaceLayoutManager::ShowStateChanged( 168 void WorkspaceLayoutManager::ShowStateChanged(
167 Window* window, 169 Window* window,
168 ui::WindowShowState last_show_state) { 170 ui::WindowShowState last_show_state) {
169 BaseLayoutManager::ShowStateChanged(window, last_show_state); 171 BaseLayoutManager::ShowStateChanged(window, last_show_state);
170 UpdateDesktopVisibility(); 172 UpdateDesktopVisibility();
171 } 173 }
172 174
173 void WorkspaceLayoutManager::AdjustWindowSizesForScreenChange( 175 void WorkspaceLayoutManager::AdjustWindowsBounds(
174 AdjustWindowReason reason) { 176 AdjustWindowReason reason) {
175 work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent()); 177 work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent());
176 BaseLayoutManager::AdjustWindowSizesForScreenChange(reason); 178 BaseLayoutManager::AdjustWindowsBounds(reason);
177 } 179 }
178 180
179 void WorkspaceLayoutManager::AdjustWindowSizeForScreenChange( 181 void WorkspaceLayoutManager::AdjustWindowBounds(
180 Window* window, 182 Window* window,
181 AdjustWindowReason reason) { 183 AdjustWindowReason reason) {
182 if (!GetTrackedByWorkspace(window)) 184 if (!GetTrackedByWorkspace(window))
183 return; 185 return;
184 186
185 // Use cross fade transition for the maximized window if the adjustment 187 // Use cross fade transition for the maximized window if the adjustment
186 // happens due to the shelf's visibility change. Otherwise the background 188 // happens due to the shelf's visibility change. Otherwise the background
187 // can be seen slightly between the bottom edge of resized-window and 189 // can be seen slightly between the bottom edge of resized-window and
188 // the animating shelf. 190 // the animating shelf.
189 // TODO(mukai): this cause slight blur at the window frame because of the 191 // TODO(mukai): this cause slight blur at the window frame because of the
190 // cross fade. I think this is better, but should reconsider if someone 192 // cross fade. I think this is better, but should reconsider if someone
191 // raises voice for this. 193 // raises voice for this.
192 if (wm::IsWindowMaximized(window) && 194 if (wm::IsWindowMaximized(window) &&
193 reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) { 195 reason == ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED) {
194 CrossFadeToBounds(window, ScreenAsh::GetMaximizedWindowBoundsInParent( 196 CrossFadeToBounds(window, ScreenAsh::GetMaximizedWindowBoundsInParent(
195 window->parent()->parent())); 197 window->parent()->parent()));
196 return; 198 return;
197 } 199 }
198 200
199 if (SetMaximizedOrFullscreenBounds(window)) 201 if (SetMaximizedOrFullscreenBounds(window))
200 return; 202 return;
201 203
202 gfx::Rect bounds = window->bounds(); 204 gfx::Rect bounds = window->bounds();
203 if (reason == ADJUST_WINDOW_SCREEN_SIZE_CHANGED) { 205 switch (reason) {
204 // The work area may be smaller than the full screen. Put as much of the 206 case ADJUST_WINDOW_DISPLAY_SIZE_CHANGED:
205 // window as possible within the display area. 207 // The work area may be smaller than the full screen. Put as much of the
206 bounds.AdjustToFit(work_area_); 208 // window as possible within the display area.
207 } else if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) { 209 bounds.AdjustToFit(work_area_);
208 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds); 210 break;
209 } else if (reason == ADJUST_WINDOW_WINDOW_ADDED) { 211 case ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED:
210 int min_width = bounds.width() * kMinimumPercentOnScreenArea; 212 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds);
211 int min_height = bounds.height() * kMinimumPercentOnScreenArea; 213 break;
212 ash::wm::AdjustBoundsToEnsureWindowVisibility( 214 case ADJUST_WINDOW_WINDOW_ADDED: {
Mr4D (OOO till 08-26) 2013/08/06 20:22:51 I am weary about this case that it might adjust wi
oshima 2013/08/06 23:13:20 These conditions are excluded by if statement in O
213 work_area_, min_width, min_height, &bounds); 215 int min_width = bounds.width() * kMinimumPercentOnScreenArea;
216 int min_height = bounds.height() * kMinimumPercentOnScreenArea;
217 ash::wm::AdjustBoundsToEnsureWindowVisibility(
218 work_area_, min_width, min_height, &bounds);
219 break;
220 }
214 } 221 }
215 if (window->bounds() != bounds) 222 if (window->bounds() != bounds)
216 window->SetBounds(bounds); 223 window->SetBounds(bounds);
217 } 224 }
218 225
219 void WorkspaceLayoutManager::UpdateDesktopVisibility() { 226 void WorkspaceLayoutManager::UpdateDesktopVisibility() {
220 if (shelf_) 227 if (shelf_)
221 shelf_->UpdateVisibilityState(); 228 shelf_->UpdateVisibilityState();
222 FramePainter::UpdateSoloWindowHeader(window_->GetRootWindow()); 229 FramePainter::UpdateSoloWindowHeader(window_->GetRootWindow());
223 } 230 }
224 231
225 void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) { 232 void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) {
226 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in 233 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in
227 // these calculation. 234 // these calculation.
228 switch (window->GetProperty(aura::client::kShowStateKey)) { 235 switch (window->GetProperty(aura::client::kShowStateKey)) {
229 case ui::SHOW_STATE_DEFAULT: 236 case ui::SHOW_STATE_DEFAULT:
230 case ui::SHOW_STATE_NORMAL: { 237 case ui::SHOW_STATE_NORMAL: {
231 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); 238 const gfx::Rect* restore = GetRestoreBoundsInScreen(window);
239 // Make sure that the part of the window is always visible
240 // when restored.
241 gfx::Rect bounds_in_parent;
232 if (restore) { 242 if (restore) {
233 gfx::Rect bounds_in_parent = 243 bounds_in_parent =
234 ScreenAsh::ConvertRectFromScreen(window->parent()->parent(), 244 ScreenAsh::ConvertRectFromScreen(window->parent()->parent(),
235 *restore); 245 *restore);
246
247 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
248 work_area_, &bounds_in_parent);
249 } else {
250 // Minimized windows have no restore bounds.
251 // Use the current bounds instead.
252 bounds_in_parent = window->bounds();
253 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
254 work_area_, &bounds_in_parent);
255 // Don't start animation if the bounds didn't change.
256 if (bounds_in_parent == window->bounds())
257 bounds_in_parent.SetRect(0, 0, 0, 0);
258 }
259 if (!bounds_in_parent.IsEmpty()) {
236 CrossFadeToBounds( 260 CrossFadeToBounds(
237 window, 261 window,
238 BaseLayoutManager::BoundsWithScreenEdgeVisible( 262 BaseLayoutManager::BoundsWithScreenEdgeVisible(
239 window->parent()->parent(), 263 window->parent()->parent(),
240 bounds_in_parent)); 264 bounds_in_parent));
241 } 265 }
242 ClearRestoreBounds(window); 266 ClearRestoreBounds(window);
243 break; 267 break;
244 } 268 }
245 269
(...skipping 29 matching lines...) Expand all
275 SetChildBoundsDirect( 299 SetChildBoundsDirect(
276 window, 300 window,
277 ScreenAsh::GetDisplayBoundsInParent(window->parent()->parent())); 301 ScreenAsh::GetDisplayBoundsInParent(window->parent()->parent()));
278 return true; 302 return true;
279 } 303 }
280 return false; 304 return false;
281 } 305 }
282 306
283 } // namespace internal 307 } // namespace internal
284 } // namespace ash 308 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698