Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 // Some windows rely on this to set their initial bounds. | 144 // Some windows rely on this to set their initial bounds. |
| 145 if (!SetMaximizedOrFullscreenBounds(child)) { | 145 if (!SetMaximizedOrFullscreenBounds(child)) { |
| 146 // Non-maximized/full-screen windows have their size constrained to the | 146 // Non-maximized/full-screen windows have their size constrained to the |
| 147 // work-area. | 147 // work-area. |
| 148 child_bounds.set_width(std::min(work_area_.width(), child_bounds.width())); | 148 child_bounds.set_width(std::min(work_area_.width(), child_bounds.width())); |
| 149 child_bounds.set_height( | 149 child_bounds.set_height( |
| 150 std::min(work_area_.height(), child_bounds.height())); | 150 std::min(work_area_.height(), child_bounds.height())); |
| 151 SetChildBoundsDirect(child, child_bounds); | 151 SetChildBoundsDirect(child, child_bounds); |
| 152 } | 152 } |
| 153 workspace_manager()->OnWorkspaceWindowChildBoundsChanged(workspace_, child); | 153 workspace_manager()->OnWorkspaceWindowChildBoundsChanged(workspace_, child); |
| 154 | |
| 155 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshEnableGutter)) { | |
| 156 if (child->type() == aura::client::WINDOW_TYPE_NORMAL && | |
| 157 wm::CanResizeWindow(child)) { | |
| 158 int stuck_edges_mask = CalculateStuckEdges(child); | |
| 159 if (GetStuckToEdge(child) != stuck_edges_mask) | |
| 160 SetStuckToEdge(child, stuck_edges_mask); | |
| 161 } | |
| 162 } | |
| 154 } | 163 } |
| 155 | 164 |
| 156 void WorkspaceLayoutManager::OnRootWindowResized(const aura::RootWindow* root, | 165 void WorkspaceLayoutManager::OnRootWindowResized(const aura::RootWindow* root, |
| 157 const gfx::Size& old_size) { | 166 const gfx::Size& old_size) { |
| 158 AdjustWindowSizesForScreenChange(ADJUST_WINDOW_SCREEN_SIZE_CHANGED); | 167 AdjustWindowSizesForScreenChange(ADJUST_WINDOW_SCREEN_SIZE_CHANGED); |
| 159 } | 168 } |
| 160 | 169 |
| 161 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { | 170 void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() { |
| 162 if (workspace_manager()->active_workspace_ == workspace_) { | 171 if (workspace_manager()->active_workspace_ == workspace_) { |
| 163 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( | 172 const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 void WorkspaceLayoutManager::AdjustWindowSizeForScreenChange( | 317 void WorkspaceLayoutManager::AdjustWindowSizeForScreenChange( |
| 309 Window* window, | 318 Window* window, |
| 310 AdjustWindowReason reason) { | 319 AdjustWindowReason reason) { |
| 311 if (GetTrackedByWorkspace(window) && | 320 if (GetTrackedByWorkspace(window) && |
| 312 !SetMaximizedOrFullscreenBounds(window)) { | 321 !SetMaximizedOrFullscreenBounds(window)) { |
| 313 if (reason == ADJUST_WINDOW_SCREEN_SIZE_CHANGED) { | 322 if (reason == ADJUST_WINDOW_SCREEN_SIZE_CHANGED) { |
| 314 // The work area may be smaller than the full screen. Put as much of the | 323 // The work area may be smaller than the full screen. Put as much of the |
| 315 // window as possible within the display area. | 324 // window as possible within the display area. |
| 316 gfx::Rect bounds = window->bounds(); | 325 gfx::Rect bounds = window->bounds(); |
| 317 bounds.AdjustToFit(work_area_); | 326 bounds.AdjustToFit(work_area_); |
| 327 bounds = AdjustWindowBoundsForStuckEdges(window, bounds); | |
| 318 window->SetBounds(bounds); | 328 window->SetBounds(bounds); |
| 319 } else if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) { | 329 } else if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) { |
| 320 gfx::Rect bounds = window->bounds(); | 330 gfx::Rect bounds = window->bounds(); |
| 321 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds); | 331 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds); |
| 332 bounds = AdjustWindowBoundsForStuckEdges(window, bounds); | |
| 322 if (window->bounds() != bounds) | 333 if (window->bounds() != bounds) |
| 323 window->SetBounds(bounds); | 334 window->SetBounds(bounds); |
| 324 } else if (reason == ADJUST_WINDOW_WINDOW_ADDED) { | 335 } else if (reason == ADJUST_WINDOW_WINDOW_ADDED) { |
| 325 gfx::Rect bounds = window->bounds(); | 336 gfx::Rect bounds = window->bounds(); |
| 326 int min_width = bounds.width() * kMinimumPercentOnScreenArea; | 337 int min_width = bounds.width() * kMinimumPercentOnScreenArea; |
| 327 int min_height = bounds.height() * kMinimumPercentOnScreenArea; | 338 int min_height = bounds.height() * kMinimumPercentOnScreenArea; |
| 328 ash::wm::AdjustBoundsToEnsureWindowVisibility( | 339 ash::wm::AdjustBoundsToEnsureWindowVisibility( |
| 329 work_area_, min_width, min_height, &bounds); | 340 work_area_, min_width, min_height, &bounds); |
| 330 if (window->bounds() != bounds) | 341 if (window->bounds() != bounds) |
| 331 window->SetBounds(bounds); | 342 window->SetBounds(bounds); |
| 332 } | 343 } |
| 333 } | 344 } |
| 334 } | 345 } |
| 335 | 346 |
| 336 void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) { | 347 void WorkspaceLayoutManager::UpdateBoundsFromShowState(Window* window) { |
| 337 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in | 348 // See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in |
| 338 // these calculation. | 349 // these calculation. |
| 350 int stuck_edges_mask = EDGE_NONE; | |
| 339 switch (window->GetProperty(aura::client::kShowStateKey)) { | 351 switch (window->GetProperty(aura::client::kShowStateKey)) { |
| 340 case ui::SHOW_STATE_DEFAULT: | 352 case ui::SHOW_STATE_DEFAULT: |
| 341 case ui::SHOW_STATE_NORMAL: { | 353 case ui::SHOW_STATE_NORMAL: { |
| 342 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); | 354 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); |
| 343 if (restore) { | 355 if (restore) { |
| 344 gfx::Rect bounds_in_parent = | 356 gfx::Rect bounds_in_parent = |
| 345 ScreenAsh::ConvertRectFromScreen(window->parent()->parent(), | 357 ScreenAsh::ConvertRectFromScreen(window->parent()->parent(), |
| 346 *restore); | 358 *restore); |
| 347 SetChildBoundsDirect( | 359 SetChildBoundsDirect( |
| 348 window, | 360 window, |
| 349 BaseLayoutManager::BoundsWithScreenEdgeVisible( | 361 BaseLayoutManager::BoundsWithScreenEdgeVisible( |
| 350 window->parent()->parent(), | 362 window->parent()->parent(), |
| 351 bounds_in_parent)); | 363 bounds_in_parent)); |
| 352 } | 364 } |
| 353 ClearRestoreBounds(window); | 365 ClearRestoreBounds(window); |
| 366 stuck_edges_mask = CalculateStuckEdges(window); | |
|
flackr
2013/05/01 17:34:04
We probably only want to "stick" windows when they
varkha
2013/05/18 03:06:37
Done.
| |
| 354 break; | 367 break; |
| 355 } | 368 } |
| 356 | 369 |
| 357 case ui::SHOW_STATE_MAXIMIZED: | 370 case ui::SHOW_STATE_MAXIMIZED: |
| 358 case ui::SHOW_STATE_FULLSCREEN: | 371 case ui::SHOW_STATE_FULLSCREEN: |
| 359 SetMaximizedOrFullscreenBounds(window); | 372 SetMaximizedOrFullscreenBounds(window); |
| 373 stuck_edges_mask = EDGE_ALL; | |
| 360 break; | 374 break; |
| 361 | 375 |
| 362 default: | 376 default: |
| 363 break; | 377 break; |
| 364 } | 378 } |
| 379 | |
| 380 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshEnableGutter)) | |
| 381 if (window->type() == aura::client::WINDOW_TYPE_NORMAL && | |
| 382 wm::CanResizeWindow(window)) | |
| 383 if (GetStuckToEdge(window) != stuck_edges_mask) | |
| 384 SetStuckToEdge(window, stuck_edges_mask); | |
| 365 } | 385 } |
| 366 | 386 |
| 367 bool WorkspaceLayoutManager::SetMaximizedOrFullscreenBounds( | 387 bool WorkspaceLayoutManager::SetMaximizedOrFullscreenBounds( |
| 368 aura::Window* window) { | 388 aura::Window* window) { |
| 369 if (!GetTrackedByWorkspace(window)) | 389 if (!GetTrackedByWorkspace(window)) |
| 370 return false; | 390 return false; |
| 371 | 391 |
| 372 // During animations there is a transform installed on the workspace | 392 // 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 | 393 // windows. For this reason this code uses the parent so that the transform is |
| 374 // ignored. | 394 // ignored. |
| 375 if (wm::IsWindowMaximized(window)) { | 395 if (wm::IsWindowMaximized(window)) { |
| 376 SetChildBoundsDirect( | 396 SetChildBoundsDirect( |
| 377 window, ScreenAsh::GetMaximizedWindowBoundsInParent( | 397 window, ScreenAsh::GetMaximizedWindowBoundsInParent( |
| 378 window->parent()->parent())); | 398 window->parent()->parent())); |
| 379 return true; | 399 return true; |
| 380 } | 400 } |
| 381 if (wm::IsWindowFullscreen(window)) { | 401 if (wm::IsWindowFullscreen(window)) { |
| 382 SetChildBoundsDirect( | 402 SetChildBoundsDirect( |
| 383 window, | 403 window, |
| 384 ScreenAsh::GetDisplayBoundsInParent(window->parent()->parent())); | 404 ScreenAsh::GetDisplayBoundsInParent(window->parent()->parent())); |
| 385 return true; | 405 return true; |
| 386 } | 406 } |
| 387 return false; | 407 return false; |
| 388 } | 408 } |
| 389 | 409 |
| 410 int WorkspaceLayoutManager::CalculateStuckEdges(aura::Window* window) { | |
| 411 int stuck_edges_mask = EDGE_NONE; | |
| 412 if (window->bounds().x() == work_area_.x()) | |
| 413 stuck_edges_mask |= EDGE_LEFT; | |
| 414 if (window->bounds().right() == work_area_.right()) | |
| 415 stuck_edges_mask |= EDGE_RIGHT; | |
| 416 if (window->bounds().y() == work_area_.y()) | |
| 417 stuck_edges_mask |= EDGE_TOP; | |
| 418 if (window->bounds().bottom() == work_area_.bottom()) | |
| 419 stuck_edges_mask |= EDGE_BOTTOM; | |
| 420 return stuck_edges_mask; | |
| 421 } | |
| 422 | |
| 423 gfx::Rect WorkspaceLayoutManager::AdjustWindowBoundsForStuckEdges( | |
| 424 aura::Window* window, | |
| 425 const gfx::Rect& bounds) { | |
| 426 gfx::Rect adjusted_bounds(bounds); | |
| 427 if ((0 != (GetStuckToEdge(window) & EDGE_RIGHT) && | |
|
flackr
2013/05/01 17:34:04
why the 0 !=? This should be fine as just if ((Get
varkha
2013/05/18 03:06:37
Done.
| |
| 428 bounds.right() != work_area_.right()) || | |
|
flackr
2013/05/01 17:34:04
These seem like they should be handled separately
varkha
2013/05/18 03:06:37
Done.
| |
| 429 (0 != (GetStuckToEdge(window) & EDGE_LEFT) && | |
| 430 bounds.x() != work_area_.x())) { | |
| 431 if (0 != (GetStuckToEdge(window) & EDGE_LEFT)) { | |
| 432 adjusted_bounds.set_x(work_area_.x()); | |
| 433 adjusted_bounds.set_width(work_area_.width()); | |
| 434 } else { | |
| 435 adjusted_bounds.set_x(work_area_.width() - bounds.width()); | |
| 436 } | |
| 437 } else { | |
|
flackr
2013/05/01 17:34:04
} else if (X) {
..
}
instead of:
} else {
if (
varkha
2013/05/18 03:06:37
The code got broken when I was chasing launcher au
| |
| 438 if (0 != (GetStuckToEdge(window) & EDGE_LEFT) && | |
| 439 bounds.x() != work_area_.x()) | |
|
flackr
2013/05/01 17:34:04
This seems the same as the case above.
varkha
2013/05/18 03:06:37
Done.
| |
| 440 adjusted_bounds.set_x(work_area_.x()); | |
| 441 } | |
| 442 if ((0 != (GetStuckToEdge(window) & EDGE_BOTTOM) && | |
| 443 bounds.bottom() != work_area_.bottom()) || | |
| 444 (0 != (GetStuckToEdge(window) & EDGE_TOP) && | |
| 445 bounds.y() != work_area_.y())) { | |
| 446 if (0 != (GetStuckToEdge(window) & EDGE_TOP)) { | |
| 447 adjusted_bounds.set_y(work_area_.y()); | |
| 448 adjusted_bounds.set_height(work_area_.height()); | |
| 449 } else { | |
| 450 adjusted_bounds.set_y(work_area_.height() - bounds.height()); | |
| 451 } | |
| 452 } else { | |
| 453 if (0 != (GetStuckToEdge(window) & EDGE_TOP) && | |
| 454 bounds.y() != work_area_.y()) | |
| 455 adjusted_bounds.set_y(work_area_.y()); | |
| 456 } | |
|
flackr
2013/05/01 17:34:04
I don't think we'll support sticking to the bottom
varkha
2013/05/18 03:06:37
The top and bottom are useful when launcher auto-h
| |
| 457 return adjusted_bounds; | |
| 458 } | |
| 459 | |
| 390 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() { | 460 WorkspaceManager* WorkspaceLayoutManager::workspace_manager() { |
| 391 return workspace_->workspace_manager(); | 461 return workspace_->workspace_manager(); |
| 392 } | 462 } |
| 393 | 463 |
| 394 } // namespace internal | 464 } // namespace internal |
| 395 } // namespace ash | 465 } // namespace ash |
| OLD | NEW |