Chromium Code Reviews| 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) { | |
| 776 Relayout(); | 779 Relayout(); | 
| 
 
sky
2016/08/31 16:04:30
Should this early out if display id is not the sam
 
msw
2016/08/31 17:07:32
Done. I did in the prior patch set, but the old co
 
sky
2016/08/31 17:45:41
The reason the old code didn't need to is because
 
msw
2016/08/31 17:55:29
AFAICT, that's not true. Each WmRootWindowControll
 
 | |
| 777 UpdateDockBounds(DockedWindowLayoutManagerObserver::DISPLAY_INSETS_CHANGED); | 780 UpdateDockBounds(DockedWindowLayoutManagerObserver::DISPLAY_INSETS_CHANGED); | 
| 778 MaybeMinimizeChildrenExcept(dragged_window_); | 781 MaybeMinimizeChildrenExcept(dragged_window_); | 
| 779 } | 782 } | 
| 780 | 783 | 
| 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 ///////////////////////////////////////////////////////////////////////////// | 784 ///////////////////////////////////////////////////////////////////////////// | 
| 800 // DockedWindowLayoutManager, WindowStateObserver implementation: | 785 // DockedWindowLayoutManager, WindowStateObserver implementation: | 
| 801 | 786 | 
| 802 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( | 787 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( | 
| 803 wm::WindowState* window_state, | 788 wm::WindowState* window_state, | 
| 804 wm::WindowStateType old_type) { | 789 wm::WindowStateType old_type) { | 
| 805 WmWindow* window = window_state->window(); | 790 WmWindow* window = window_state->window(); | 
| 806 if (IsPopupOrTransient(window)) | 791 if (IsPopupOrTransient(window)) | 
| 807 return; | 792 return; | 
| 808 // The window property will still be set, but no actual change will occur | 793 // 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); | 870 MaybeMinimizeChildrenExcept(gained_active); | 
| 886 Relayout(); | 871 Relayout(); | 
| 887 UpdateStacking(ancestor); | 872 UpdateStacking(ancestor); | 
| 888 } | 873 } | 
| 889 } | 874 } | 
| 890 | 875 | 
| 891 //////////////////////////////////////////////////////////////////////////////// | 876 //////////////////////////////////////////////////////////////////////////////// | 
| 892 // DockedWindowLayoutManager, ShellObserver implementation: | 877 // DockedWindowLayoutManager, ShellObserver implementation: | 
| 893 | 878 | 
| 894 void DockedWindowLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { | 879 void DockedWindowLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { | 
| 880 if (!shelf_ || alignment_ == DOCKED_ALIGNMENT_NONE || | |
| 881 root_window != shelf_->GetWindow()->GetRootWindow()) { | |
| 882 return; | |
| 883 } | |
| 884 | |
| 885 // Do not allow shelf and dock on the same side. Switch side that | |
| 886 // the dock is attached to and move all dock windows to that new side. | |
| 887 ShelfAlignment shelf_alignment = shelf_->GetAlignment(); | |
| 888 if (alignment_ == DOCKED_ALIGNMENT_LEFT && | |
| 889 shelf_alignment == SHELF_ALIGNMENT_LEFT) { | |
| 890 alignment_ = DOCKED_ALIGNMENT_RIGHT; | |
| 891 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && | |
| 892 shelf_alignment == SHELF_ALIGNMENT_RIGHT) { | |
| 893 alignment_ = DOCKED_ALIGNMENT_LEFT; | |
| 894 } | |
| 895 Relayout(); | |
| 896 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); | |
| 895 } | 897 } | 
| 896 | 898 | 
| 897 void DockedWindowLayoutManager::OnFullscreenStateChanged( | 899 void DockedWindowLayoutManager::OnFullscreenStateChanged( | 
| 898 bool is_fullscreen, | 900 bool is_fullscreen, | 
| 899 WmWindow* root_window) { | 901 WmWindow* root_window) { | 
| 900 if (root_window != dock_container_->GetRootWindow()) | 902 if (root_window != dock_container_->GetRootWindow()) | 
| 901 return; | 903 return; | 
| 902 | 904 | 
| 903 // Entering fullscreen mode (including immersive) hides docked windows. | 905 // Entering fullscreen mode (including immersive) hides docked windows. | 
| 904 in_fullscreen_ = root_window_controller_->GetWorkspaceWindowState() == | 906 in_fullscreen_ = root_window_controller_->GetWorkspaceWindowState() == | 
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1375 | 1377 | 
| 1376 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1378 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 
| 1377 const gfx::Rect& keyboard_bounds) { | 1379 const gfx::Rect& keyboard_bounds) { | 
| 1378 // This bounds change will have caused a change to the Shelf which does not | 1380 // This bounds change will have caused a change to the Shelf which does not | 
| 1379 // propagate automatically to this class, so manually recalculate bounds. | 1381 // propagate automatically to this class, so manually recalculate bounds. | 
| 1380 Relayout(); | 1382 Relayout(); | 
| 1381 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1383 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 
| 1382 } | 1384 } | 
| 1383 | 1385 | 
| 1384 } // namespace ash | 1386 } // namespace ash | 
| OLD | NEW |