| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/common/wm/dock/docked_window_layout_manager.h" | 5 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/shelf/shelf_background_animator.h" | 8 #include "ash/common/shelf/shelf_background_animator.h" |
| 9 #include "ash/common/shelf/shelf_background_animator_observer.h" | 9 #include "ash/common/shelf/shelf_background_animator_observer.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ash/common/wm_window.h" | 22 #include "ash/common/wm_window.h" |
| 23 #include "base/auto_reset.h" | 23 #include "base/auto_reset.h" |
| 24 #include "base/metrics/histogram.h" | 24 #include "base/metrics/histogram.h" |
| 25 #include "grit/ash_resources.h" | 25 #include "grit/ash_resources.h" |
| 26 #include "third_party/skia/include/core/SkColor.h" | 26 #include "third_party/skia/include/core/SkColor.h" |
| 27 #include "third_party/skia/include/core/SkPaint.h" | 27 #include "third_party/skia/include/core/SkPaint.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/compositor/paint_recorder.h" | 29 #include "ui/compositor/paint_recorder.h" |
| 30 #include "ui/compositor/scoped_layer_animation_settings.h" | 30 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 31 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
| 32 #include "ui/display/screen.h" |
| 32 #include "ui/gfx/canvas.h" | 33 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/image/image_skia_operations.h" | 34 #include "ui/gfx/image/image_skia_operations.h" |
| 34 #include "ui/views/background.h" | 35 #include "ui/views/background.h" |
| 35 | 36 |
| 36 namespace ash { | 37 namespace ash { |
| 37 | 38 |
| 38 // Minimum, maximum width of the dock area and a width of the gap | 39 // Minimum, maximum width of the dock area and a width of the gap |
| 39 // static | 40 // static |
| 40 const int DockedWindowLayoutManager::kMaxDockWidth = 360; | 41 const int DockedWindowLayoutManager::kMaxDockWidth = 360; |
| 41 // static | 42 // static |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 in_overview_(false), | 426 in_overview_(false), |
| 426 alignment_(DOCKED_ALIGNMENT_NONE), | 427 alignment_(DOCKED_ALIGNMENT_NONE), |
| 427 preferred_alignment_(DOCKED_ALIGNMENT_NONE), | 428 preferred_alignment_(DOCKED_ALIGNMENT_NONE), |
| 428 event_source_(DOCKED_ACTION_SOURCE_UNKNOWN), | 429 event_source_(DOCKED_ACTION_SOURCE_UNKNOWN), |
| 429 last_active_window_(nullptr), | 430 last_active_window_(nullptr), |
| 430 last_action_time_(base::Time::Now()), | 431 last_action_time_(base::Time::Now()), |
| 431 background_widget_(nullptr) { | 432 background_widget_(nullptr) { |
| 432 DCHECK(dock_container); | 433 DCHECK(dock_container); |
| 433 dock_container_->GetShell()->AddShellObserver(this); | 434 dock_container_->GetShell()->AddShellObserver(this); |
| 434 dock_container->GetShell()->AddActivationObserver(this); | 435 dock_container->GetShell()->AddActivationObserver(this); |
| 435 root_window_controller_->AddObserver(this); | 436 display::Screen::GetScreen()->AddObserver(this); |
| 436 } | 437 } |
| 437 | 438 |
| 438 DockedWindowLayoutManager::~DockedWindowLayoutManager() { | 439 DockedWindowLayoutManager::~DockedWindowLayoutManager() { |
| 439 Shutdown(); | 440 Shutdown(); |
| 440 } | 441 } |
| 441 | 442 |
| 442 // static | 443 // static |
| 443 DockedWindowLayoutManager* DockedWindowLayoutManager::Get(WmWindow* window) { | 444 DockedWindowLayoutManager* DockedWindowLayoutManager::Get(WmWindow* window) { |
| 444 if (!window) | 445 if (!window) |
| 445 return nullptr; | 446 return nullptr; |
| 446 | 447 |
| 447 WmWindow* root = window->GetRootWindow(); | 448 WmWindow* root = window->GetRootWindow(); |
| 448 return static_cast<DockedWindowLayoutManager*>( | 449 return static_cast<DockedWindowLayoutManager*>( |
| 449 root->GetChildByShellWindowId(kShellWindowId_DockedContainer) | 450 root->GetChildByShellWindowId(kShellWindowId_DockedContainer) |
| 450 ->GetLayoutManager()); | 451 ->GetLayoutManager()); |
| 451 } | 452 } |
| 452 | 453 |
| 453 void DockedWindowLayoutManager::Shutdown() { | 454 void DockedWindowLayoutManager::Shutdown() { |
| 454 background_widget_.reset(); | 455 background_widget_.reset(); |
| 455 shelf_observer_.reset(); | 456 shelf_observer_.reset(); |
| 456 shelf_ = nullptr; | 457 shelf_ = nullptr; |
| 457 for (WmWindow* child : dock_container_->GetChildren()) { | 458 for (WmWindow* child : dock_container_->GetChildren()) { |
| 458 child->RemoveObserver(this); | 459 child->RemoveObserver(this); |
| 459 child->GetWindowState()->RemoveObserver(this); | 460 child->GetWindowState()->RemoveObserver(this); |
| 460 } | 461 } |
| 461 dock_container_->GetShell()->RemoveActivationObserver(this); | 462 dock_container_->GetShell()->RemoveActivationObserver(this); |
| 462 dock_container_->GetShell()->RemoveShellObserver(this); | 463 dock_container_->GetShell()->RemoveShellObserver(this); |
| 463 root_window_controller_->RemoveObserver(this); | 464 display::Screen::GetScreen()->RemoveObserver(this); |
| 464 } | 465 } |
| 465 | 466 |
| 466 void DockedWindowLayoutManager::AddObserver( | 467 void DockedWindowLayoutManager::AddObserver( |
| 467 DockedWindowLayoutManagerObserver* observer) { | 468 DockedWindowLayoutManagerObserver* observer) { |
| 468 observer_list_.AddObserver(observer); | 469 observer_list_.AddObserver(observer); |
| 469 } | 470 } |
| 470 | 471 |
| 471 void DockedWindowLayoutManager::RemoveObserver( | 472 void DockedWindowLayoutManager::RemoveObserver( |
| 472 DockedWindowLayoutManagerObserver* observer) { | 473 DockedWindowLayoutManagerObserver* observer) { |
| 473 observer_list_.RemoveObserver(observer); | 474 observer_list_.RemoveObserver(observer); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 return; | 764 return; |
| 764 wm::WmSnapToPixelLayoutManager::SetChildBounds(child, actual_new_bounds); | 765 wm::WmSnapToPixelLayoutManager::SetChildBounds(child, actual_new_bounds); |
| 765 if (IsPopupOrTransient(child)) | 766 if (IsPopupOrTransient(child)) |
| 766 return; | 767 return; |
| 767 // Whenever one of our windows is moved or resized enforce layout. | 768 // Whenever one of our windows is moved or resized enforce layout. |
| 768 if (shelf_) | 769 if (shelf_) |
| 769 shelf_->UpdateVisibilityState(); | 770 shelf_->UpdateVisibilityState(); |
| 770 } | 771 } |
| 771 | 772 |
| 772 //////////////////////////////////////////////////////////////////////////////// | 773 //////////////////////////////////////////////////////////////////////////////// |
| 773 // DockedWindowLayoutManager, WmRootWindowControllerObserver implementation: | 774 // DockedWindowLayoutManager, display::DisplayObserver implementation: |
| 774 | 775 |
| 775 void DockedWindowLayoutManager::OnWorkAreaChanged() { | 776 void DockedWindowLayoutManager::OnDisplayMetricsChanged( |
| 777 const display::Display& display, |
| 778 uint32_t changed_metrics) { |
| 779 if (dock_container_->GetDisplayNearestWindow().id() != display.id()) |
| 780 return; |
| 781 |
| 776 Relayout(); | 782 Relayout(); |
| 777 UpdateDockBounds(DockedWindowLayoutManagerObserver::DISPLAY_INSETS_CHANGED); | 783 UpdateDockBounds(DockedWindowLayoutManagerObserver::DISPLAY_INSETS_CHANGED); |
| 778 MaybeMinimizeChildrenExcept(dragged_window_); | 784 MaybeMinimizeChildrenExcept(dragged_window_); |
| 779 } | 785 } |
| 780 | 786 |
| 781 void DockedWindowLayoutManager::OnShelfAlignmentChanged() { | |
| 782 if (!shelf_ || alignment_ == DOCKED_ALIGNMENT_NONE) | |
| 783 return; | |
| 784 | |
| 785 // Do not allow shelf and dock on the same side. Switch side that | |
| 786 // the dock is attached to and move all dock windows to that new side. | |
| 787 ShelfAlignment shelf_alignment = shelf_->GetAlignment(); | |
| 788 if (alignment_ == DOCKED_ALIGNMENT_LEFT && | |
| 789 shelf_alignment == SHELF_ALIGNMENT_LEFT) { | |
| 790 alignment_ = DOCKED_ALIGNMENT_RIGHT; | |
| 791 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && | |
| 792 shelf_alignment == SHELF_ALIGNMENT_RIGHT) { | |
| 793 alignment_ = DOCKED_ALIGNMENT_LEFT; | |
| 794 } | |
| 795 Relayout(); | |
| 796 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); | |
| 797 } | |
| 798 | |
| 799 ///////////////////////////////////////////////////////////////////////////// | 787 ///////////////////////////////////////////////////////////////////////////// |
| 800 // DockedWindowLayoutManager, WindowStateObserver implementation: | 788 // DockedWindowLayoutManager, WindowStateObserver implementation: |
| 801 | 789 |
| 802 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( | 790 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( |
| 803 wm::WindowState* window_state, | 791 wm::WindowState* window_state, |
| 804 wm::WindowStateType old_type) { | 792 wm::WindowStateType old_type) { |
| 805 WmWindow* window = window_state->window(); | 793 WmWindow* window = window_state->window(); |
| 806 if (IsPopupOrTransient(window)) | 794 if (IsPopupOrTransient(window)) |
| 807 return; | 795 return; |
| 808 // The window property will still be set, but no actual change will occur | 796 // The window property will still be set, but no actual change will occur |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 MaybeMinimizeChildrenExcept(gained_active); | 873 MaybeMinimizeChildrenExcept(gained_active); |
| 886 Relayout(); | 874 Relayout(); |
| 887 UpdateStacking(ancestor); | 875 UpdateStacking(ancestor); |
| 888 } | 876 } |
| 889 } | 877 } |
| 890 | 878 |
| 891 //////////////////////////////////////////////////////////////////////////////// | 879 //////////////////////////////////////////////////////////////////////////////// |
| 892 // DockedWindowLayoutManager, ShellObserver implementation: | 880 // DockedWindowLayoutManager, ShellObserver implementation: |
| 893 | 881 |
| 894 void DockedWindowLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { | 882 void DockedWindowLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { |
| 883 if (!shelf_ || alignment_ == DOCKED_ALIGNMENT_NONE || |
| 884 root_window != shelf_->GetWindow()->GetRootWindow()) { |
| 885 return; |
| 886 } |
| 887 |
| 888 // Do not allow shelf and dock on the same side. Switch side that |
| 889 // the dock is attached to and move all dock windows to that new side. |
| 890 ShelfAlignment shelf_alignment = shelf_->GetAlignment(); |
| 891 if (alignment_ == DOCKED_ALIGNMENT_LEFT && |
| 892 shelf_alignment == SHELF_ALIGNMENT_LEFT) { |
| 893 alignment_ = DOCKED_ALIGNMENT_RIGHT; |
| 894 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && |
| 895 shelf_alignment == SHELF_ALIGNMENT_RIGHT) { |
| 896 alignment_ = DOCKED_ALIGNMENT_LEFT; |
| 897 } |
| 898 Relayout(); |
| 899 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); |
| 895 } | 900 } |
| 896 | 901 |
| 897 void DockedWindowLayoutManager::OnFullscreenStateChanged( | 902 void DockedWindowLayoutManager::OnFullscreenStateChanged( |
| 898 bool is_fullscreen, | 903 bool is_fullscreen, |
| 899 WmWindow* root_window) { | 904 WmWindow* root_window) { |
| 900 if (root_window != dock_container_->GetRootWindow()) | 905 if (root_window != dock_container_->GetRootWindow()) |
| 901 return; | 906 return; |
| 902 | 907 |
| 903 // Entering fullscreen mode (including immersive) hides docked windows. | 908 // Entering fullscreen mode (including immersive) hides docked windows. |
| 904 in_fullscreen_ = root_window_controller_->GetWorkspaceWindowState() == | 909 in_fullscreen_ = root_window_controller_->GetWorkspaceWindowState() == |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 | 1380 |
| 1376 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1381 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 1377 const gfx::Rect& keyboard_bounds) { | 1382 const gfx::Rect& keyboard_bounds) { |
| 1378 // This bounds change will have caused a change to the Shelf which does not | 1383 // This bounds change will have caused a change to the Shelf which does not |
| 1379 // propagate automatically to this class, so manually recalculate bounds. | 1384 // propagate automatically to this class, so manually recalculate bounds. |
| 1380 Relayout(); | 1385 Relayout(); |
| 1381 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1386 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1382 } | 1387 } |
| 1383 | 1388 |
| 1384 } // namespace ash | 1389 } // namespace ash |
| OLD | NEW |