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

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

Issue 9733003: Adjust window timings to match Cole's video. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ash/ash.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/window_animations.h" 5 #include "ash/wm/window_animations.h"
6 6
7 #include "ash/animation_timings.h"
7 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
8 #include "ash/launcher/launcher.h" 9 #include "ash/launcher/launcher.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/message_loop.h" 14 #include "base/message_loop.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/time.h" 16 #include "base/time.h"
16 #include "ui/aura/client/aura_constants.h" 17 #include "ui/aura/client/aura_constants.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 WindowVisibilityAnimationTransition prop = window->GetProperty( 66 WindowVisibilityAnimationTransition prop = window->GetProperty(
66 internal::kWindowVisibilityAnimationTransitionKey); 67 internal::kWindowVisibilityAnimationTransitionKey);
67 return (prop & transition) != 0; 68 return (prop & transition) != 0;
68 } 69 }
69 70
70 namespace internal { 71 namespace internal {
71 namespace { 72 namespace {
72 73
73 const float kWindowAnimation_HideOpacity = 0.f; 74 const float kWindowAnimation_HideOpacity = 0.f;
74 const float kWindowAnimation_ShowOpacity = 1.f; 75 const float kWindowAnimation_ShowOpacity = 1.f;
75 const float kWindowAnimation_TranslateFactor = -0.025f; 76 const float kWindowAnimation_TranslateX = 3.f;
76 const float kWindowAnimation_ScaleFactor = 1.05f; 77 const float kWindowAnimation_TranslateY = -12.f;
78 const float kWindowAnimation_ScaleFactor = .95f;
77 const float kWindowAnimation_MinimizeRotate = -5.f; 79 const float kWindowAnimation_MinimizeRotate = -5.f;
78
79 const float kWindowAnimation_Vertical_TranslateY = 15.f; 80 const float kWindowAnimation_Vertical_TranslateY = 15.f;
80 81
81 // Amount windows are scaled during workspace animations. 82 // Amount windows are scaled during workspace animations.
82 const float kWorkspaceScale = .95f; 83 const float kWorkspaceScale = .95f;
83 84
84 // Gets/sets the WindowVisibilityAnimationType associated with a window. 85 // Gets/sets the WindowVisibilityAnimationType associated with a window.
85 WindowVisibilityAnimationType GetWindowVisibilityAnimationType( 86 WindowVisibilityAnimationType GetWindowVisibilityAnimationType(
86 aura::Window* window) { 87 aura::Window* window) {
87 WindowVisibilityAnimationType type = 88 WindowVisibilityAnimationType type =
88 window->GetProperty(kWindowVisibilityAnimationTypeKey); 89 window->GetProperty(kWindowVisibilityAnimationTypeKey);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // Restore the correct visibility value (overridden for the duration of the 177 // Restore the correct visibility value (overridden for the duration of the
177 // animation in AnimateHideWindow()). 178 // animation in AnimateHideWindow()).
178 layer_->SetVisible(false); 179 layer_->SetVisible(false);
179 } 180 }
180 181
181 ui::Layer* layer_; 182 ui::Layer* layer_;
182 183
183 DISALLOW_COPY_AND_ASSIGN(WorkspaceHidingWindowAnimationObserver); 184 DISALLOW_COPY_AND_ASSIGN(WorkspaceHidingWindowAnimationObserver);
184 }; 185 };
185 186
187 base::TimeDelta GetAnimationDurationForWindow(aura::Window* window) {
188 int duration =
189 window->GetProperty(internal::kWindowVisibilityAnimationDurationKey);
190 if (duration > 0)
191 return TimeDelta::FromInternalValue(duration);
192 return TimeDelta::FromMilliseconds(kStandardTransitionDuration);
193 }
194
186 // Shows a window using an animation, animating its opacity from 0.f to 1.f, and 195 // Shows a window using an animation, animating its opacity from 0.f to 1.f, and
187 // its transform from |start_transform| to |end_transform|. 196 // its transform from |start_transform| to |end_transform|.
188 void AnimateShowWindowCommon(aura::Window* window, 197 void AnimateShowWindowCommon(aura::Window* window,
189 const ui::Transform& start_transform, 198 const ui::Transform& start_transform,
190 const ui::Transform& end_transform) { 199 const ui::Transform& end_transform) {
191 window->layer()->set_delegate(window); 200 window->layer()->set_delegate(window);
192 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 201 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
193 window->layer()->SetTransform(start_transform); 202 window->layer()->SetTransform(start_transform);
194 203
195 { 204 {
196 // Property sets within this scope will be implicitly animated. 205 // Property sets within this scope will be implicitly animated.
197 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 206 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
198 int duration = 207 settings.SetTransitionDuration(GetAnimationDurationForWindow(window));
199 window->GetProperty(internal::kWindowVisibilityAnimationDurationKey);
200 if (duration > 0)
201 settings.SetTransitionDuration(TimeDelta::FromInternalValue(duration));
202
203 window->layer()->SetTransform(end_transform); 208 window->layer()->SetTransform(end_transform);
204 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); 209 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
205 } 210 }
206 } 211 }
207 212
208 // Hides a window using an animation, animating its opacity from 1.f to 0.f, and 213 // Hides a window using an animation, animating its opacity from 1.f to 0.f, and
209 // its transform to |end_transform|. 214 // its transform to |end_transform|.
210 void AnimateHideWindowCommon(aura::Window* window, 215 void AnimateHideWindowCommon(aura::Window* window,
211 const ui::Transform& end_transform) { 216 const ui::Transform& end_transform) {
212 window->layer()->set_delegate(NULL); 217 window->layer()->set_delegate(NULL);
213 218
214 // Property sets within this scope will be implicitly animated. 219 // Property sets within this scope will be implicitly animated.
215 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 220 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
216 settings.AddObserver(new HidingWindowAnimationObserver(window)); 221 settings.AddObserver(new HidingWindowAnimationObserver(window));
217 222
218 int duration = 223 settings.SetTransitionDuration(GetAnimationDurationForWindow(window));
219 window->GetProperty(internal::kWindowVisibilityAnimationDurationKey);
220 if (duration > 0)
221 settings.SetTransitionDuration(TimeDelta::FromInternalValue(duration));
222
223 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 224 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
224 window->layer()->SetTransform(end_transform); 225 window->layer()->SetTransform(end_transform);
225 } 226 }
226 227
227 // Show/Hide windows using a shrink animation. 228 // Show/Hide windows using a shrink animation.
228 void AnimateShowWindow_Drop(aura::Window* window) { 229 void AnimateShowWindow_Drop(aura::Window* window) {
229 ui::Transform transform; 230 ui::Transform transform;
230 transform.ConcatScale(kWindowAnimation_ScaleFactor, 231 transform.ConcatScale(kWindowAnimation_ScaleFactor,
231 kWindowAnimation_ScaleFactor); 232 kWindowAnimation_ScaleFactor);
232 transform.ConcatTranslate( 233 transform.ConcatTranslate(kWindowAnimation_TranslateX,
233 kWindowAnimation_TranslateFactor * window->bounds().width(), 234 kWindowAnimation_TranslateY);
234 kWindowAnimation_TranslateFactor * window->bounds().height());
235 AnimateShowWindowCommon(window, transform, ui::Transform()); 235 AnimateShowWindowCommon(window, transform, ui::Transform());
236 } 236 }
237 237
238 void AnimateHideWindow_Drop(aura::Window* window) { 238 void AnimateHideWindow_Drop(aura::Window* window) {
239 ui::Transform transform; 239 ui::Transform transform;
240 transform.ConcatScale(kWindowAnimation_ScaleFactor, 240 transform.ConcatScale(kWindowAnimation_ScaleFactor,
241 kWindowAnimation_ScaleFactor); 241 kWindowAnimation_ScaleFactor);
242 transform.ConcatTranslate( 242 // Window keeps dropping vertically when hidden (i.e. doesn't reverse
243 kWindowAnimation_TranslateFactor * window->bounds().width(), 243 // direction)
244 kWindowAnimation_TranslateFactor * window->bounds().height()); 244 transform.ConcatTranslate(kWindowAnimation_TranslateX,
245 -kWindowAnimation_TranslateY);
245 AnimateHideWindowCommon(window, transform); 246 AnimateHideWindowCommon(window, transform);
246 } 247 }
247 248
248 // Show/Hide windows using a vertical Glenimation. 249 // Show/Hide windows using a vertical Glenimation.
249 void AnimateShowWindow_Vertical(aura::Window* window) { 250 void AnimateShowWindow_Vertical(aura::Window* window) {
250 ui::Transform transform; 251 ui::Transform transform;
251 transform.ConcatTranslate(0, kWindowAnimation_Vertical_TranslateY); 252 transform.ConcatTranslate(0, kWindowAnimation_Vertical_TranslateY);
252 AnimateShowWindowCommon(window, transform, ui::Transform()); 253 AnimateShowWindowCommon(window, transform, ui::Transform());
253 } 254 }
254 255
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 293
293 void AnimateShowWindow_Workspace(aura::Window* window) { 294 void AnimateShowWindow_Workspace(aura::Window* window) {
294 ui::Transform transform(BuildWorkspaceSwitchTransform(window)); 295 ui::Transform transform(BuildWorkspaceSwitchTransform(window));
295 window->layer()->SetVisible(true); 296 window->layer()->SetVisible(true);
296 window->layer()->SetOpacity(0.0f); 297 window->layer()->SetOpacity(0.0f);
297 window->layer()->SetTransform(transform); 298 window->layer()->SetTransform(transform);
298 299
299 { 300 {
300 // Property sets within this scope will be implicitly animated. 301 // Property sets within this scope will be implicitly animated.
301 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 302 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
303 settings.SetTransitionDuration(
304 TimeDelta::FromMilliseconds(kSlowTransitionDuration));
302 305
303 window->layer()->SetTransform(ui::Transform()); 306 window->layer()->SetTransform(ui::Transform());
304 // Opacity animates only during the first half of the animation. 307 // Opacity animates only during the first half of the animation.
305 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2); 308 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2);
306 window->layer()->SetOpacity(1.0f); 309 window->layer()->SetOpacity(1.0f);
307 } 310 }
308 } 311 }
309 312
310 void AnimateHideWindow_Workspace(aura::Window* window) { 313 void AnimateHideWindow_Workspace(aura::Window* window) {
311 ui::Transform transform(BuildWorkspaceSwitchTransform(window)); 314 ui::Transform transform(BuildWorkspaceSwitchTransform(window));
312 window->layer()->SetOpacity(1.0f); 315 window->layer()->SetOpacity(1.0f);
313 window->layer()->SetTransform(ui::Transform()); 316 window->layer()->SetTransform(ui::Transform());
314 317
315 // Opacity animates from 1 to 0 only over the second half of the animation. To 318 // Opacity animates from 1 to 0 only over the second half of the animation. To
316 // get this functionality two animations are schedule for opacity, the first 319 // get this functionality two animations are schedule for opacity, the first
317 // from 1 to 1 (which effectively does nothing) the second from 1 to 0. 320 // from 1 to 1 (which effectively does nothing) the second from 1 to 0.
318 // Because we're scheduling two animations of the same property we need to 321 // Because we're scheduling two animations of the same property we need to
319 // change the preemption strategy. 322 // change the preemption strategy.
320 ui::LayerAnimator* animator = window->layer()->GetAnimator(); 323 ui::LayerAnimator* animator = window->layer()->GetAnimator();
321 animator->set_preemption_strategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); 324 animator->set_preemption_strategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
322 { 325 {
323 // Property sets within this scope will be implicitly animated. 326 // Property sets within this scope will be implicitly animated.
324 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 327 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
328 settings.SetTransitionDuration(
329 TimeDelta::FromMilliseconds(kSlowTransitionDuration));
325 // Add an observer that sets visibility of the layer to false once animation 330 // Add an observer that sets visibility of the layer to false once animation
326 // completes. 331 // completes.
327 settings.AddObserver(new WorkspaceHidingWindowAnimationObserver(window)); 332 settings.AddObserver(new WorkspaceHidingWindowAnimationObserver(window));
328 window->layer()->SetTransform(transform); 333 window->layer()->SetTransform(transform);
329 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2); 334 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2);
330 window->layer()->SetOpacity(1.0f); 335 window->layer()->SetOpacity(1.0f);
331 window->layer()->SetOpacity(0.0f); 336 window->layer()->SetOpacity(0.0f);
332 } 337 }
333 animator->set_preemption_strategy( 338 animator->set_preemption_strategy(
334 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); 339 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 return AnimateShowWindow(window); 488 return AnimateShowWindow(window);
484 } else { 489 } else {
485 // Don't start hiding the window again if it's already being hidden. 490 // Don't start hiding the window again if it's already being hidden.
486 return window->layer()->GetTargetOpacity() != 0.0f && 491 return window->layer()->GetTargetOpacity() != 0.0f &&
487 AnimateHideWindow(window); 492 AnimateHideWindow(window);
488 } 493 }
489 } 494 }
490 495
491 } // namespace internal 496 } // namespace internal
492 } // namespace ash 497 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698