Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: ash/wm/workspace_controller.cc

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

Powered by Google App Engine
This is Rietveld 408576698