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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// 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/workspace_animations.h"
#include "ash/ash_switches.h"
#include "base/command_line.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
namespace ash {
namespace internal {
const int kWorkspaceSwitchTimeMS = 200;
namespace {
// Tween type used when showing/hiding workspaces.
const ui::Tween::Type kWorkspaceTweenType = ui::Tween::EASE_OUT;
// Scales for workspaces above/below current workspace.
const float kWorkspaceScaleAbove = 1.1f;
const float kWorkspaceScaleBelow = .9f;
enum WorkspaceScaleType {
WORKSPACE_SCALE_ABOVE,
WORKSPACE_SCALE_BELOW,
};
// Applies the specified WorkspaceScaleType.
void ApplyWorkspaceScale(ui::Layer* layer, WorkspaceScaleType type) {
const float scale = type == WORKSPACE_SCALE_ABOVE ? kWorkspaceScaleAbove :
kWorkspaceScaleBelow;
gfx::Transform transform;
transform.ConcatScale(scale, scale);
transform.ConcatTranslate(
-layer->bounds().width() * (scale - 1.0f) / 2,
-layer->bounds().height() * (scale - 1.0f) / 2);
layer->SetTransform(transform);
}
// If |details.duration| is not-empty it is returned, otherwise
// |kWorkspaceSwitchTimeMS| is returned.
base::TimeDelta DurationForWorkspaceShowOrHide(
const WorkspaceAnimationDetails& details) {
return details.duration == base::TimeDelta() ?
base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS) :
details.duration;
}
} // namespace
WorkspaceAnimationDetails::WorkspaceAnimationDetails()
: direction(WORKSPACE_ANIMATE_UP),
animate(false),
animate_opacity(false),
animate_scale(false),
pause_time_ms(0) {
}
WorkspaceAnimationDetails::~WorkspaceAnimationDetails() {
}
void ShowWorkspace(aura::Window* window,
const WorkspaceAnimationDetails& details) {
window->Show();
if (!details.animate || CommandLine::ForCurrentProcess()->HasSwitch(
ash::switches::kAshWindowAnimationsDisabled)) {
window->layer()->SetOpacity(1.0f);
window->layer()->SetTransform(gfx::Transform());
return;
}
window->layer()->SetOpacity(details.animate_opacity ? 0.0f : 1.0f);
if (details.animate_scale) {
ApplyWorkspaceScale(window->layer(),
details.direction == WORKSPACE_ANIMATE_UP ?
WORKSPACE_SCALE_BELOW : WORKSPACE_SCALE_ABOVE);
} else {
window->layer()->SetTransform(gfx::Transform());
}
// In order for pause to work we need to stop animations.
window->layer()->GetAnimator()->StopAnimating();
{
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
if (details.pause_time_ms > 0) {
settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
window->layer()->GetAnimator()->SchedulePauseForProperties(
base::TimeDelta::FromMilliseconds(details.pause_time_ms),
ui::LayerAnimationElement::TRANSFORM,
ui::LayerAnimationElement::OPACITY,
ui::LayerAnimationElement::BRIGHTNESS,
ui::LayerAnimationElement::VISIBILITY,
-1);
}
settings.SetTweenType(kWorkspaceTweenType);
settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details));
window->layer()->SetTransform(gfx::Transform());
window->layer()->SetOpacity(1.0f);
}
}
void HideWorkspace(aura::Window* window,
const WorkspaceAnimationDetails& details) {
window->layer()->SetTransform(gfx::Transform());
window->layer()->SetOpacity(1.0f);
window->layer()->GetAnimator()->StopAnimating();
if (!details.animate || CommandLine::ForCurrentProcess()->HasSwitch(
ash::switches::kAshWindowAnimationsDisabled)) {
window->Hide();
return;
}
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
if (details.pause_time_ms > 0) {
settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
window->layer()->GetAnimator()->SchedulePauseForProperties(
base::TimeDelta::FromMilliseconds(details.pause_time_ms),
ui::LayerAnimationElement::TRANSFORM,
ui::LayerAnimationElement::OPACITY,
ui::LayerAnimationElement::BRIGHTNESS,
ui::LayerAnimationElement::VISIBILITY,
-1);
}
settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details));
settings.SetTweenType(kWorkspaceTweenType);
if (details.animate_scale) {
ApplyWorkspaceScale(window->layer(),
details.direction == WORKSPACE_ANIMATE_UP ?
WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW);
} else {
window->layer()->SetTransform(gfx::Transform());
}
// NOTE: Hide() must be before SetOpacity(), else
// VisibilityController::UpdateLayerVisibility doesn't pass the false to the
// layer so that the layer and window end up out of sync and confused.
window->Hide();
if (details.animate_opacity)
window->layer()->SetOpacity(0.0f);
// After the animation completes snap the transform back to the identity,
// otherwise any one that asks for screen bounds gets a slightly scaled
// version.
settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
settings.SetTransitionDuration(base::TimeDelta());
window->layer()->SetTransform(gfx::Transform());
}
} // namespace internal
} // namespace ash
|