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

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

Issue 13896026: Stick windows to sides of workspaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Correcting logic to avoid getting stuck on resize Created 7 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 (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/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/session_state_delegate.h" 9 #include "ash/session_state_delegate.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/wm/always_on_top_controller.h" 11 #include "ash/wm/always_on_top_controller.h"
12 #include "ash/wm/base_layout_manager.h" 12 #include "ash/wm/base_layout_manager.h"
13 #include "ash/wm/window_animations.h" 13 #include "ash/wm/window_animations.h"
14 #include "ash/wm/window_properties.h" 14 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
16 #include "ash/wm/workspace/stuck_edge_types.h"
16 #include "ash/wm/workspace/workspace.h" 17 #include "ash/wm/workspace/workspace.h"
17 #include "ash/wm/workspace/workspace_manager.h" 18 #include "ash/wm/workspace/workspace_manager.h"
18 #include "ash/wm/workspace/workspace_window_resizer.h" 19 #include "ash/wm/workspace/workspace_window_resizer.h"
19 #include "base/auto_reset.h" 20 #include "base/auto_reset.h"
20 #include "base/command_line.h" 21 #include "base/command_line.h"
21 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/root_window.h" 23 #include "ui/aura/root_window.h"
23 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
24 #include "ui/aura/window_observer.h" 25 #include "ui/aura/window_observer.h"
25 #include "ui/base/events/event.h" 26 #include "ui/base/events/event.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 void WorkspaceLayoutManager::AdjustWindowSizeForScreenChange( 309 void WorkspaceLayoutManager::AdjustWindowSizeForScreenChange(
309 Window* window, 310 Window* window,
310 AdjustWindowReason reason) { 311 AdjustWindowReason reason) {
311 if (GetTrackedByWorkspace(window) && 312 if (GetTrackedByWorkspace(window) &&
312 !SetMaximizedOrFullscreenBounds(window)) { 313 !SetMaximizedOrFullscreenBounds(window)) {
313 if (reason == ADJUST_WINDOW_SCREEN_SIZE_CHANGED) { 314 if (reason == ADJUST_WINDOW_SCREEN_SIZE_CHANGED) {
314 // The work area may be smaller than the full screen. Put as much of the 315 // The work area may be smaller than the full screen. Put as much of the
315 // window as possible within the display area. 316 // window as possible within the display area.
316 gfx::Rect bounds = window->bounds(); 317 gfx::Rect bounds = window->bounds();
317 bounds.AdjustToFit(work_area_); 318 bounds.AdjustToFit(work_area_);
319 bounds = AdjustWindowBoundsForStuckEdges(window, bounds);
318 window->SetBounds(bounds); 320 window->SetBounds(bounds);
319 } else if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) { 321 } else if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) {
320 gfx::Rect bounds = window->bounds(); 322 gfx::Rect bounds = window->bounds();
321 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds); 323 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds);
324 bounds = AdjustWindowBoundsForStuckEdges(window, bounds);
322 if (window->bounds() != bounds) 325 if (window->bounds() != bounds)
323 window->SetBounds(bounds); 326 window->SetBounds(bounds);
324 } else if (reason == ADJUST_WINDOW_WINDOW_ADDED) { 327 } else if (reason == ADJUST_WINDOW_WINDOW_ADDED) {
325 gfx::Rect bounds = window->bounds(); 328 gfx::Rect bounds = window->bounds();
326 int min_width = bounds.width() * kMinimumPercentOnScreenArea; 329 int min_width = bounds.width() * kMinimumPercentOnScreenArea;
327 int min_height = bounds.height() * kMinimumPercentOnScreenArea; 330 int min_height = bounds.height() * kMinimumPercentOnScreenArea;
328 ash::wm::AdjustBoundsToEnsureWindowVisibility( 331 ash::wm::AdjustBoundsToEnsureWindowVisibility(
329 work_area_, min_width, min_height, &bounds); 332 work_area_, min_width, min_height, &bounds);
330 if (window->bounds() != bounds) 333 if (window->bounds() != bounds)
331 window->SetBounds(bounds); 334 window->SetBounds(bounds);
332 } 335 }
333 } 336 }
334 } 337 }
335 338
336 void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) { 339 void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) {
337 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in 340 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in
338 // these calculation. 341 // these calculation.
342 int stuck_edges_mask = GetStuckToEdge(window);
339 switch (window->GetProperty(aura::client::kShowStateKey)) { 343 switch (window->GetProperty(aura::client::kShowStateKey)) {
340 case ui::SHOW_STATE_DEFAULT: 344 case ui::SHOW_STATE_DEFAULT:
341 case ui::SHOW_STATE_NORMAL: { 345 case ui::SHOW_STATE_NORMAL: {
342 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); 346 const gfx::Rect* restore = GetRestoreBoundsInScreen(window);
343 if (restore) { 347 if (restore) {
344 gfx::Rect bounds_in_parent = 348 gfx::Rect bounds_in_parent =
345 ScreenAsh::ConvertRectFromScreen(window->parent()->parent(), 349 ScreenAsh::ConvertRectFromScreen(window->parent()->parent(),
346 *restore); 350 *restore);
347 SetChildBoundsDirect( 351 SetChildBoundsDirect(
348 window, 352 window,
349 BaseLayoutManager::BoundsWithScreenEdgeVisible( 353 BaseLayoutManager::BoundsWithScreenEdgeVisible(
350 window->parent()->parent(), 354 window->parent()->parent(),
351 bounds_in_parent)); 355 bounds_in_parent));
356
357 // getting unstuck
358 stuck_edges_mask = STUCK_EDGE_NONE;
352 } 359 }
353 ClearRestoreBounds(window); 360 ClearRestoreBounds(window);
354 break; 361 break;
355 } 362 }
356 363
357 case ui::SHOW_STATE_MAXIMIZED: 364 case ui::SHOW_STATE_MAXIMIZED:
358 case ui::SHOW_STATE_FULLSCREEN: 365 case ui::SHOW_STATE_FULLSCREEN:
359 SetMaximizedOrFullscreenBounds(window); 366 SetMaximizedOrFullscreenBounds(window);
367 stuck_edges_mask = STUCK_EDGE_NONE;
360 break; 368 break;
361 369
362 default: 370 default:
363 break; 371 break;
364 } 372 }
373 if (GetStuckToEdge(window) != stuck_edges_mask &&
374 CommandLine::ForCurrentProcess()->HasSwitch(
375 switches::kAshEnableDockedWindows))
376 SetStuckToEdge(window, stuck_edges_mask);
365 } 377 }
366 378
367 bool WorkspaceLayoutManager::SetMaximizedOrFullscreenBounds( 379 bool WorkspaceLayoutManager::SetMaximizedOrFullscreenBounds(
368 aura::Window* window) { 380 aura::Window* window) {
369 if (!GetTrackedByWorkspace(window)) 381 if (!GetTrackedByWorkspace(window))
370 return false; 382 return false;
371 383
372 // During animations there is a transform installed on the workspace 384 // During animations there is a transform installed on the workspace
373 // windows. For this reason this code uses the parent so that the transform is 385 // windows. For this reason this code uses the parent so that the transform is
374 // ignored. 386 // ignored.
375 if (wm::IsWindowMaximized(window)) { 387 if (wm::IsWindowMaximized(window)) {
376 SetChildBoundsDirect( 388 SetChildBoundsDirect(
377 window, ScreenAsh::GetMaximizedWindowBoundsInParent( 389 window, ScreenAsh::GetMaximizedWindowBoundsInParent(
378 window->parent()->parent())); 390 window->parent()->parent()));
379 return true; 391 return true;
380 } 392 }
381 if (wm::IsWindowFullscreen(window)) { 393 if (wm::IsWindowFullscreen(window)) {
382 SetChildBoundsDirect( 394 SetChildBoundsDirect(
383 window, 395 window,
384 ScreenAsh::GetDisplayBoundsInParent(window->parent()->parent())); 396 ScreenAsh::GetDisplayBoundsInParent(window->parent()->parent()));
385 return true; 397 return true;
386 } 398 }
387 return false; 399 return false;
388 } 400 }
389 401
402 gfx::Rect WorkspaceLayoutManager::AdjustWindowBoundsForStuckEdges(
403 aura::Window* window,
404 const gfx::Rect& bounds) {
flackr 2013/05/22 02:00:56 We should do all docked window specific layout cha
405 gfx::Rect new_bounds(bounds);
406 if ((GetStuckToEdge(window) & STUCK_EDGE_LEFT) &&
407 bounds.x() != work_area_.x())
408 new_bounds.set_x(work_area_.x());
409 if ((GetStuckToEdge(window) & STUCK_EDGE_RIGHT) &&
410 new_bounds.right() != work_area_.right()) {
411 if (GetStuckToEdge(window) & STUCK_EDGE_LEFT)
412 new_bounds.set_width(work_area_.right() - new_bounds.x());
413 else
414 new_bounds.set_x(work_area_.right() - bounds.width());
415 }
416 if ((GetStuckToEdge(window) & STUCK_EDGE_TOP) && bounds.y() != work_area_.y())
417 new_bounds.set_y(work_area_.y());
418 if ((GetStuckToEdge(window) & STUCK_EDGE_BOTTOM) &&
419 new_bounds.bottom() != work_area_.bottom()) {
420 if (GetStuckToEdge(window) & STUCK_EDGE_TOP)
421 new_bounds.set_height(work_area_.bottom() - new_bounds.y());
422 else
423 new_bounds.set_y(work_area_.bottom() - bounds.height());
424 }
425 return new_bounds;
426 }
427
390 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() { 428 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() {
391 return workspace_->workspace_manager(); 429 return workspace_->workspace_manager();
392 } 430 }
393 431
394 } // namespace internal 432 } // namespace internal
395 } // namespace ash 433 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698