| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/common/wm/workspace_controller.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "ash/common/shelf/wm_shelf.h" | |
| 10 #include "ash/common/wm/dock/docked_window_layout_manager.h" | |
| 11 #include "ash/common/wm/fullscreen_window_finder.h" | |
| 12 #include "ash/common/wm/window_state.h" | |
| 13 #include "ash/common/wm/wm_window_animations.h" | |
| 14 #include "ash/common/wm/workspace/workspace_event_handler.h" | |
| 15 #include "ash/common/wm/workspace/workspace_layout_manager.h" | |
| 16 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | |
| 17 #include "ash/common/wm_shell.h" | |
| 18 #include "ash/common/wm_window.h" | |
| 19 #include "ash/public/cpp/shell_window_ids.h" | |
| 20 #include "ash/root_window_controller.h" | |
| 21 #include "base/memory/ptr_util.h" | |
| 22 #include "ui/compositor/layer.h" | |
| 23 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 24 | |
| 25 namespace ash { | |
| 26 namespace { | |
| 27 | |
| 28 // Amount of time to pause before animating anything. Only used during initial | |
| 29 // animation (when logging in). | |
| 30 const int kInitialPauseTimeMS = 750; | |
| 31 | |
| 32 // The duration of the animation that occurs on first login. | |
| 33 const int kInitialAnimationDurationMS = 200; | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 WorkspaceController::WorkspaceController(WmWindow* viewport) | |
| 38 : viewport_(viewport), | |
| 39 event_handler_(WmShell::Get()->CreateWorkspaceEventHandler(viewport)), | |
| 40 layout_manager_(new WorkspaceLayoutManager(viewport)) { | |
| 41 viewport_->aura_window()->AddObserver(this); | |
| 42 viewport_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); | |
| 43 viewport_->SetLayoutManager(base::WrapUnique(layout_manager_)); | |
| 44 } | |
| 45 | |
| 46 WorkspaceController::~WorkspaceController() { | |
| 47 if (!viewport_) | |
| 48 return; | |
| 49 | |
| 50 viewport_->aura_window()->RemoveObserver(this); | |
| 51 viewport_->SetLayoutManager(nullptr); | |
| 52 } | |
| 53 | |
| 54 wm::WorkspaceWindowState WorkspaceController::GetWindowState() const { | |
| 55 if (!viewport_ || !viewport_->GetRootWindowController()->HasShelf()) | |
| 56 return wm::WORKSPACE_WINDOW_STATE_DEFAULT; | |
| 57 | |
| 58 const WmWindow* fullscreen = wm::GetWindowForFullscreenMode(viewport_); | |
| 59 if (fullscreen && !fullscreen->GetWindowState()->ignored_by_shelf()) | |
| 60 return wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN; | |
| 61 | |
| 62 // These are the container ids of containers which may contain windows that | |
| 63 // may overlap the launcher shelf and affect its transparency. | |
| 64 const int kWindowContainerIds[] = { | |
| 65 kShellWindowId_DefaultContainer, kShellWindowId_DockedContainer, | |
| 66 }; | |
| 67 const gfx::Rect shelf_bounds(WmShelf::ForWindow(viewport_)->GetIdealBounds()); | |
| 68 bool window_overlaps_launcher = false; | |
| 69 for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) { | |
| 70 WmWindow* container = viewport_->GetRootWindow()->GetChildByShellWindowId( | |
| 71 kWindowContainerIds[i]); | |
| 72 for (WmWindow* window : container->GetChildren()) { | |
| 73 wm::WindowState* window_state = window->GetWindowState(); | |
| 74 if (window_state->ignored_by_shelf() || | |
| 75 (window->GetLayer() && !window->GetLayer()->GetTargetVisibility())) { | |
| 76 continue; | |
| 77 } | |
| 78 if (window_state->IsMaximized()) | |
| 79 return wm::WORKSPACE_WINDOW_STATE_MAXIMIZED; | |
| 80 window_overlaps_launcher |= window->GetBounds().Intersects(shelf_bounds); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 // Check if there are visible docked windows in the same display. | |
| 85 DockedWindowLayoutManager* dock = DockedWindowLayoutManager::Get(viewport_); | |
| 86 const bool docked_area_visible = dock && !dock->docked_bounds().IsEmpty(); | |
| 87 return (window_overlaps_launcher || docked_area_visible) | |
| 88 ? wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF | |
| 89 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; | |
| 90 } | |
| 91 | |
| 92 void WorkspaceController::DoInitialAnimation() { | |
| 93 viewport_->Show(); | |
| 94 | |
| 95 ui::Layer* layer = viewport_->GetLayer(); | |
| 96 layer->SetOpacity(0.0f); | |
| 97 SetTransformForScaleAnimation(layer, LAYER_SCALE_ANIMATION_ABOVE); | |
| 98 | |
| 99 // In order for pause to work we need to stop animations. | |
| 100 layer->GetAnimator()->StopAnimating(); | |
| 101 | |
| 102 { | |
| 103 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | |
| 104 | |
| 105 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
| 106 layer->GetAnimator()->SchedulePauseForProperties( | |
| 107 base::TimeDelta::FromMilliseconds(kInitialPauseTimeMS), | |
| 108 ui::LayerAnimationElement::TRANSFORM | | |
| 109 ui::LayerAnimationElement::OPACITY | | |
| 110 ui::LayerAnimationElement::BRIGHTNESS | | |
| 111 ui::LayerAnimationElement::VISIBILITY); | |
| 112 settings.SetTweenType(gfx::Tween::EASE_OUT); | |
| 113 settings.SetTransitionDuration( | |
| 114 base::TimeDelta::FromMilliseconds(kInitialAnimationDurationMS)); | |
| 115 layer->SetTransform(gfx::Transform()); | |
| 116 layer->SetOpacity(1.0f); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 void WorkspaceController::SetMaximizeBackdropDelegate( | |
| 121 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | |
| 122 layout_manager_->SetMaximizeBackdropDelegate(std::move(delegate)); | |
| 123 } | |
| 124 | |
| 125 void WorkspaceController::OnWindowDestroying(aura::Window* window) { | |
| 126 DCHECK_EQ(WmWindow::Get(window), viewport_); | |
| 127 viewport_->aura_window()->RemoveObserver(this); | |
| 128 viewport_ = nullptr; | |
| 129 // Destroy |event_handler_| too as it depends upon |window|. | |
| 130 event_handler_.reset(); | |
| 131 layout_manager_ = nullptr; | |
| 132 } | |
| 133 | |
| 134 } // namespace ash | |
| OLD | NEW |