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_controller.h" | 5 #include "ash/wm/workspace_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/wm/dock/docked_window_layout_manager.h" | |
| 12 #include "ash/common/wm/fullscreen_window_finder.h" | |
| 11 #include "ash/common/wm/window_state.h" | 13 #include "ash/common/wm/window_state.h" |
| 14 #include "ash/common/wm/wm_window_animations.h" | |
| 12 #include "ash/common/wm/workspace/workspace_layout_manager.h" | 15 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 13 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | 16 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
| 14 #include "ash/root_window_controller.h" | 17 #include "ash/common/wm_root_window_controller.h" |
| 15 #include "ash/shelf/shelf_layout_manager.h" | 18 #include "ash/common/wm_window.h" |
| 16 #include "ash/shell.h" | |
| 17 #include "ash/wm/window_animations.h" | |
| 18 #include "ash/wm/window_state_aura.h" | |
| 19 #include "ash/wm/window_util.h" | |
| 20 #include "ash/wm/workspace/workspace_event_handler.h" | 19 #include "ash/wm/workspace/workspace_event_handler.h" |
| 21 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 22 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 24 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
| 25 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
| 26 #include "ui/compositor/scoped_layer_animation_settings.h" | 25 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 27 #include "ui/wm/core/visibility_controller.h" | 26 #include "ui/wm/core/visibility_controller.h" |
| 28 #include "ui/wm/core/window_animations.h" | 27 #include "ui/wm/core/window_animations.h" |
| 29 #include "ui/wm/public/activation_client.h" | 28 #include "ui/wm/public/activation_client.h" |
| 30 | 29 |
| 31 namespace ash { | 30 namespace ash { |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 // Amount of time to pause before animating anything. Only used during initial | 33 // Amount of time to pause before animating anything. Only used during initial |
| 35 // animation (when logging in). | 34 // animation (when logging in). |
| 36 const int kInitialPauseTimeMS = 750; | 35 const int kInitialPauseTimeMS = 750; |
| 37 | 36 |
| 38 // Returns true if there are visible docked windows in the same screen as the | 37 // The duration of the animation that occurs on first login. |
| 39 // |shelf|. | 38 const int kIntialAnimationDurationMS = 200; |
|
James Cook
2016/08/11 23:27:36
nit: Intial -> Initial
msw
2016/08/12 00:17:15
Done.
| |
| 40 bool IsDockedAreaVisible(const ShelfLayoutManager* shelf) { | |
| 41 return shelf->dock_bounds().width() > 0; | |
| 42 } | |
| 43 | 39 |
| 44 } // namespace | 40 } // namespace |
| 45 | 41 |
| 46 WorkspaceController::WorkspaceController(aura::Window* viewport) | 42 WorkspaceController::WorkspaceController(WmWindow* viewport) |
| 47 : viewport_(viewport), | 43 : viewport_(viewport), |
| 48 shelf_(NULL), | |
| 49 event_handler_(new WorkspaceEventHandler), | 44 event_handler_(new WorkspaceEventHandler), |
| 50 layout_manager_(new WorkspaceLayoutManager(WmWindowAura::Get(viewport))) { | 45 layout_manager_(new WorkspaceLayoutManager(viewport)) { |
| 51 SetWindowVisibilityAnimationTransition(viewport_, ::wm::ANIMATE_NONE); | 46 viewport_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); |
| 52 | 47 viewport_->SetLayoutManager(base::WrapUnique(layout_manager_)); |
| 53 WmWindowAura::Get(viewport_)->SetLayoutManager( | 48 viewport_->AddLimitedPreTargetHandler(event_handler_.get()); |
| 54 base::WrapUnique(layout_manager_)); | |
| 55 viewport_->AddPreTargetHandler(event_handler_.get()); | |
| 56 } | 49 } |
| 57 | 50 |
| 58 WorkspaceController::~WorkspaceController() { | 51 WorkspaceController::~WorkspaceController() { |
| 59 viewport_->SetLayoutManager(NULL); | 52 viewport_->SetLayoutManager(nullptr); |
| 60 viewport_->RemovePreTargetHandler(event_handler_.get()); | 53 viewport_->RemoveLimitedPreTargetHandler(event_handler_.get()); |
| 61 } | 54 } |
| 62 | 55 |
| 63 wm::WorkspaceWindowState WorkspaceController::GetWindowState() const { | 56 wm::WorkspaceWindowState WorkspaceController::GetWindowState() const { |
| 64 if (!shelf_) | 57 const WmWindow* fullscreen = wm::GetWindowForFullscreenMode(viewport_); |
| 58 if (fullscreen && !fullscreen->GetWindowState()->ignored_by_shelf()) | |
| 59 return wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN; | |
| 60 | |
| 61 if (!viewport_->GetRootWindowController()->HasShelf()) | |
|
James Cook
2016/08/11 23:27:36
Q: Does this one have to go second? The previous c
msw
2016/08/12 00:17:15
Restored order.
| |
| 65 return wm::WORKSPACE_WINDOW_STATE_DEFAULT; | 62 return wm::WORKSPACE_WINDOW_STATE_DEFAULT; |
| 66 const aura::Window* topmost_fullscreen_window = | |
| 67 GetRootWindowController(viewport_->GetRootWindow()) | |
| 68 ->GetWindowForFullscreenMode(); | |
| 69 if (topmost_fullscreen_window && | |
| 70 !wm::GetWindowState(topmost_fullscreen_window)->ignored_by_shelf()) { | |
| 71 return wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN; | |
| 72 } | |
| 73 | 63 |
| 74 // These are the container ids of containers which may contain windows that | 64 // These are the container ids of containers which may contain windows that |
| 75 // may overlap the launcher shelf and affect its transparency. | 65 // may overlap the launcher shelf and affect its transparency. |
| 76 const int kWindowContainerIds[] = { | 66 const int kWindowContainerIds[] = { |
| 77 kShellWindowId_DefaultContainer, kShellWindowId_DockedContainer, | 67 kShellWindowId_DefaultContainer, kShellWindowId_DockedContainer, |
| 78 }; | 68 }; |
| 79 const gfx::Rect shelf_bounds(shelf_->GetIdealBounds()); | 69 const gfx::Rect shelf_bounds( |
| 70 viewport_->GetRootWindowController()->GetShelf()->GetIdealBounds()); | |
| 80 bool window_overlaps_launcher = false; | 71 bool window_overlaps_launcher = false; |
| 81 for (size_t idx = 0; idx < arraysize(kWindowContainerIds); idx++) { | 72 for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) { |
| 82 const aura::Window* container = Shell::GetContainer( | 73 WmWindow* container = viewport_->GetRootWindow()->GetChildByShellWindowId( |
| 83 viewport_->GetRootWindow(), kWindowContainerIds[idx]); | 74 kWindowContainerIds[i]); |
| 84 const aura::Window::Windows& windows(container->children()); | 75 for (WmWindow* window : container->GetChildren()) { |
| 85 for (aura::Window::Windows::const_iterator i = windows.begin(); | 76 wm::WindowState* window_state = window->GetWindowState(); |
| 86 i != windows.end(); ++i) { | 77 if ((window_state && window_state->ignored_by_shelf()) || |
|
James Cook
2016/08/11 23:27:36
Kinda weird that window_state can be null. The aur
msw
2016/08/12 00:17:15
This check isn't needed in the latest patch set; r
| |
| 87 wm::WindowState* window_state = wm::GetWindowState(*i); | 78 !window->GetLayer()->GetTargetVisibility()) { |
| 88 if (window_state->ignored_by_shelf()) | |
| 89 continue; | 79 continue; |
| 90 ui::Layer* layer = (*i)->layer(); | 80 } |
| 91 if (!layer->GetTargetVisibility()) | 81 if (window_state && window_state->IsMaximized()) |
| 92 continue; | |
| 93 if (window_state->IsMaximized()) { | |
| 94 return wm::WORKSPACE_WINDOW_STATE_MAXIMIZED; | 82 return wm::WORKSPACE_WINDOW_STATE_MAXIMIZED; |
| 95 } | 83 window_overlaps_launcher |= window->GetBounds().Intersects(shelf_bounds); |
| 96 if (!window_overlaps_launcher && | |
| 97 ((*i)->bounds().Intersects(shelf_bounds))) { | |
| 98 window_overlaps_launcher = true; | |
| 99 } | |
| 100 } | 84 } |
| 101 } | 85 } |
| 102 | 86 |
| 103 return (window_overlaps_launcher || IsDockedAreaVisible(shelf_)) | 87 // Check if there are visible docked windows in the same display. |
| 88 DockedWindowLayoutManager* dock = DockedWindowLayoutManager::Get(viewport_); | |
| 89 const bool docked_area_visible = dock && !dock->docked_bounds().IsEmpty(); | |
| 90 return (window_overlaps_launcher || docked_area_visible) | |
| 104 ? wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF | 91 ? wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF |
| 105 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; | 92 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; |
| 106 } | 93 } |
| 107 | 94 |
| 108 void WorkspaceController::SetShelf(ShelfLayoutManager* shelf) { | |
| 109 shelf_ = shelf; | |
| 110 } | |
| 111 | |
| 112 void WorkspaceController::DoInitialAnimation() { | 95 void WorkspaceController::DoInitialAnimation() { |
| 113 viewport_->Show(); | 96 viewport_->Show(); |
| 114 | 97 |
| 115 viewport_->layer()->SetOpacity(0.0f); | 98 viewport_->GetLayer()->SetOpacity(0.0f); |
|
James Cook
2016/08/11 23:27:36
For 7 calls, I would create a local for the Layer*
msw
2016/08/12 00:17:15
Done.
| |
| 116 SetTransformForScaleAnimation(viewport_->layer(), | 99 SetTransformForScaleAnimation(viewport_->GetLayer(), |
| 117 LAYER_SCALE_ANIMATION_ABOVE); | 100 LAYER_SCALE_ANIMATION_ABOVE); |
| 118 | 101 |
| 119 // In order for pause to work we need to stop animations. | 102 // In order for pause to work we need to stop animations. |
| 120 viewport_->layer()->GetAnimator()->StopAnimating(); | 103 viewport_->GetLayer()->GetAnimator()->StopAnimating(); |
| 121 | 104 |
| 122 { | 105 { |
| 123 ui::ScopedLayerAnimationSettings settings( | 106 ui::ScopedLayerAnimationSettings settings( |
| 124 viewport_->layer()->GetAnimator()); | 107 viewport_->GetLayer()->GetAnimator()); |
| 125 | 108 |
| 126 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 109 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 127 viewport_->layer()->GetAnimator()->SchedulePauseForProperties( | 110 viewport_->GetLayer()->GetAnimator()->SchedulePauseForProperties( |
| 128 base::TimeDelta::FromMilliseconds(kInitialPauseTimeMS), | 111 base::TimeDelta::FromMilliseconds(kInitialPauseTimeMS), |
| 129 ui::LayerAnimationElement::TRANSFORM | | 112 ui::LayerAnimationElement::TRANSFORM | |
| 130 ui::LayerAnimationElement::OPACITY | | 113 ui::LayerAnimationElement::OPACITY | |
| 131 ui::LayerAnimationElement::BRIGHTNESS | | 114 ui::LayerAnimationElement::BRIGHTNESS | |
| 132 ui::LayerAnimationElement::VISIBILITY); | 115 ui::LayerAnimationElement::VISIBILITY); |
| 133 settings.SetTweenType(gfx::Tween::EASE_OUT); | 116 settings.SetTweenType(gfx::Tween::EASE_OUT); |
| 134 settings.SetTransitionDuration( | 117 settings.SetTransitionDuration( |
| 135 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS)); | 118 base::TimeDelta::FromMilliseconds(kIntialAnimationDurationMS)); |
| 136 viewport_->layer()->SetTransform(gfx::Transform()); | 119 viewport_->GetLayer()->SetTransform(gfx::Transform()); |
| 137 viewport_->layer()->SetOpacity(1.0f); | 120 viewport_->GetLayer()->SetOpacity(1.0f); |
| 138 } | 121 } |
| 139 } | 122 } |
| 140 | 123 |
| 141 void WorkspaceController::SetMaximizeBackdropDelegate( | 124 void WorkspaceController::SetMaximizeBackdropDelegate( |
| 142 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 125 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { |
| 143 layout_manager_->SetMaximizeBackdropDelegate(std::move(delegate)); | 126 layout_manager_->SetMaximizeBackdropDelegate(std::move(delegate)); |
| 144 } | 127 } |
| 145 | 128 |
| 146 } // namespace ash | 129 } // namespace ash |
| OLD | NEW |