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

Side by Side Diff: ash/wm/workspace/workspace_animations.cc

Issue 11280188: Fix focus loss on partial lock. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review fixes Created 8 years 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
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/workspace_animations.h" 5 #include "ash/wm/workspace/workspace_animations.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "base/bind.h"
9 #include "base/callback.h"
8 #include "base/command_line.h" 10 #include "base/command_line.h"
9 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h" 12 #include "ui/compositor/layer.h"
11 #include "ui/compositor/scoped_layer_animation_settings.h" 13 #include "ui/compositor/scoped_layer_animation_settings.h"
12 14
13 namespace ash { 15 namespace ash {
14 namespace internal { 16 namespace internal {
15 17
16 const int kWorkspaceSwitchTimeMS = 200; 18 const int kWorkspaceSwitchTimeMS = 200;
17 19
(...skipping 24 matching lines...) Expand all
42 44
43 // If |details.duration| is not-empty it is returned, otherwise 45 // If |details.duration| is not-empty it is returned, otherwise
44 // |kWorkspaceSwitchTimeMS| is returned. 46 // |kWorkspaceSwitchTimeMS| is returned.
45 base::TimeDelta DurationForWorkspaceShowOrHide( 47 base::TimeDelta DurationForWorkspaceShowOrHide(
46 const WorkspaceAnimationDetails& details) { 48 const WorkspaceAnimationDetails& details) {
47 return details.duration == base::TimeDelta() ? 49 return details.duration == base::TimeDelta() ?
48 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS) : 50 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS) :
49 details.duration; 51 details.duration;
50 } 52 }
51 53
54 void HideWindow(aura::Window* window) {
55 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
56 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
57 settings.SetTransitionDuration(base::TimeDelta());
58 window->Hide();
59 }
60
52 } // namespace 61 } // namespace
53 62
54 WorkspaceAnimationDetails::WorkspaceAnimationDetails() 63 WorkspaceAnimationDetails::WorkspaceAnimationDetails()
55 : direction(WORKSPACE_ANIMATE_UP), 64 : direction(WORKSPACE_ANIMATE_UP),
56 animate(false), 65 animate(false),
57 animate_opacity(false), 66 animate_opacity(false),
58 animate_scale(false), 67 animate_scale(false),
68 can_be_cancelled(false),
59 pause_time_ms(0) { 69 pause_time_ms(0) {
60 } 70 }
61 71
62 WorkspaceAnimationDetails::~WorkspaceAnimationDetails() { 72 WorkspaceAnimationDetails::~WorkspaceAnimationDetails() {
63 } 73 }
64 74
65 void ShowWorkspace(aura::Window* window, 75 void ShowWorkspace(aura::Window* window,
66 const WorkspaceAnimationDetails& details) { 76 const WorkspaceAnimationDetails& details) {
67 window->Show(); 77 window->Show();
68 78
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); 143 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details));
134 settings.SetTweenType(kWorkspaceTweenType); 144 settings.SetTweenType(kWorkspaceTweenType);
135 if (details.animate_scale) { 145 if (details.animate_scale) {
136 ApplyWorkspaceScale(window->layer(), 146 ApplyWorkspaceScale(window->layer(),
137 details.direction == WORKSPACE_ANIMATE_UP ? 147 details.direction == WORKSPACE_ANIMATE_UP ?
138 WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW); 148 WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW);
139 } else { 149 } else {
140 window->layer()->SetTransform(gfx::Transform()); 150 window->layer()->SetTransform(gfx::Transform());
141 } 151 }
142 152
143 // NOTE: Hide() must be before SetOpacity(), else 153 if (details.can_be_cancelled) {
144 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the 154 // Window should be hidden only upon animation completion, so that focus
145 // layer so that the layer and window end up out of sync and confused. 155 // is not lost if animation is cancelled.
146 window->Hide(); 156 window->layer()->SetVisible(false);
157 } else {
158 // NOTE: Hide() must be before SetOpacity(), else
159 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the
160 // layer so that the layer and window end up out of sync and confused.
161 window->Hide();
162 }
147 163
148 if (details.animate_opacity) 164 if (details.animate_opacity)
149 window->layer()->SetOpacity(0.0f); 165 window->layer()->SetOpacity(0.0f);
150 166
167 if (details.can_be_cancelled) {
168 // We need window-Hide() to be called to handle focus loss and other stuff
169 // correctly. However, this animation can be aborted in some cases
170 // (e.g. during lock), and window should only be hidden if animation
171 // completes.
172 base::Closure hide_window_callback = base::Bind(&HideWindow, window);
173 window->layer()->GetAnimator()->SetCompletionCallbackForProperties(
174 hide_window_callback,
175 ui::LayerAnimationElement::VISIBILITY,
176 -1);
177 }
151 // After the animation completes snap the transform back to the identity, 178 // After the animation completes snap the transform back to the identity,
152 // otherwise any one that asks for screen bounds gets a slightly scaled 179 // otherwise any one that asks for screen bounds gets a slightly scaled
153 // version. 180 // version.
154 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); 181 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
155 settings.SetTransitionDuration(base::TimeDelta()); 182 settings.SetTransitionDuration(base::TimeDelta());
156 window->layer()->SetTransform(gfx::Transform()); 183 window->layer()->SetTransform(gfx::Transform());
157 } 184 }
158 185
159 } // namespace internal 186 } // namespace internal
160 } // namespace ash 187 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698