1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/workspace_controller.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/base_layout_manager.h"
#include "ash/wm/window_animations.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/workspace_event_handler.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/views/corewm/visibility_controller.h"
#include "ui/views/corewm/window_animations.h"
namespace ash {
namespace internal {
namespace {
// Amount of time to pause before animating anything. Only used during initial
// animation (when logging in).
const int kInitialPauseTimeMS = 750;
} // namespace
WorkspaceController::WorkspaceController(aura::Window* viewport)
: viewport_(viewport),
shelf_(NULL),
event_handler_(new WorkspaceEventHandler(viewport_)) {
SetWindowVisibilityAnimationTransition(
viewport_, views::corewm::ANIMATE_NONE);
// The layout-manager cannot be created in the initializer list since it
// depends on the window to have been initialized.
layout_manager_ = new WorkspaceLayoutManager(viewport_);
viewport_->SetLayoutManager(layout_manager_);
viewport_->Show();
}
WorkspaceController::~WorkspaceController() {
viewport_->SetLayoutManager(NULL);
viewport_->SetEventFilter(NULL);
viewport_->RemovePreTargetHandler(event_handler_.get());
viewport_->RemovePostTargetHandler(event_handler_.get());
}
WorkspaceWindowState WorkspaceController::GetWindowState() const {
if (!shelf_)
return WORKSPACE_WINDOW_STATE_DEFAULT;
// These are the container ids of containers which may contain windows that
// may overlap the launcher shelf and affect its transparency.
const int kWindowContainerIds[] = {
internal::kShellWindowId_DefaultContainer,
internal::kShellWindowId_DockedContainer,
};
const gfx::Rect shelf_bounds(shelf_->GetIdealBounds());
bool window_overlaps_launcher = false;
bool has_maximized_window = false;
for (size_t idx = 0; idx < arraysize(kWindowContainerIds); idx++) {
const aura::Window* container = Shell::GetContainer(
viewport_->GetRootWindow(), kWindowContainerIds[idx]);
const aura::Window::Windows& windows(container->children());
for (aura::Window::Windows::const_iterator i = windows.begin();
i != windows.end(); ++i) {
wm::WindowState* window_state = wm::GetWindowState(*i);
if (window_state->ignored_by_shelf())
continue;
ui::Layer* layer = (*i)->layer();
if (!layer->GetTargetVisibility() || layer->GetTargetOpacity() == 0.0f)
continue;
if (window_state->IsMaximized()) {
// An untracked window may still be fullscreen so we keep iterating when
// we hit a maximized window.
has_maximized_window = true;
} else if (window_state->IsFullscreen()) {
return WORKSPACE_WINDOW_STATE_FULL_SCREEN;
}
if (!window_overlaps_launcher && (*i)->bounds().Intersects(shelf_bounds))
window_overlaps_launcher = true;
}
}
if (has_maximized_window)
return WORKSPACE_WINDOW_STATE_MAXIMIZED;
return window_overlaps_launcher ?
WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF :
WORKSPACE_WINDOW_STATE_DEFAULT;
}
void WorkspaceController::SetShelf(ShelfLayoutManager* shelf) {
shelf_ = shelf;
layout_manager_->SetShelf(shelf);
}
void WorkspaceController::DoInitialAnimation() {
viewport_->Show();
viewport_->layer()->SetOpacity(0.0f);
SetTransformForScaleAnimation(
viewport_->layer(), LAYER_SCALE_ANIMATION_ABOVE);
// In order for pause to work we need to stop animations.
viewport_->layer()->GetAnimator()->StopAnimating();
{
ui::ScopedLayerAnimationSettings settings(
viewport_->layer()->GetAnimator());
settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
viewport_->layer()->GetAnimator()->SchedulePauseForProperties(
base::TimeDelta::FromMilliseconds(kInitialPauseTimeMS),
ui::LayerAnimationElement::TRANSFORM,
ui::LayerAnimationElement::OPACITY,
ui::LayerAnimationElement::BRIGHTNESS,
ui::LayerAnimationElement::VISIBILITY,
-1);
settings.SetTweenType(gfx::Tween::EASE_OUT);
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS));
viewport_->layer()->SetTransform(gfx::Transform());
viewport_->layer()->SetOpacity(1.0f);
}
}
} // namespace internal
} // namespace ash
|