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

Side by Side Diff: ui/views/corewm/window_animations.cc

Issue 105673008: Remove unneeded ScopedLayerAnimationSettings::LockTransitionDuration() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 "ui/views/corewm/window_animations.h" 5 #include "ui/views/corewm/window_animations.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 namespace views { 50 namespace views {
51 namespace corewm { 51 namespace corewm {
52 namespace { 52 namespace {
53 const float kWindowAnimation_Vertical_TranslateY = 15.f; 53 const float kWindowAnimation_Vertical_TranslateY = 15.f;
54 } // namespace 54 } // namespace
55 55
56 DEFINE_WINDOW_PROPERTY_KEY(int, 56 DEFINE_WINDOW_PROPERTY_KEY(int,
57 kWindowVisibilityAnimationTypeKey, 57 kWindowVisibilityAnimationTypeKey,
58 WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); 58 WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT);
59 DEFINE_WINDOW_PROPERTY_KEY(int, kWindowVisibilityAnimationDurationKey, 0); 59 DEFINE_WINDOW_PROPERTY_KEY(int, kWindowShowAnimationDurationKey, 0);
60 DEFINE_WINDOW_PROPERTY_KEY(int, kWindowHideAnimationDurationKey, 0);
60 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition, 61 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition,
61 kWindowVisibilityAnimationTransitionKey, 62 kWindowVisibilityAnimationTransitionKey,
62 ANIMATE_BOTH); 63 ANIMATE_BOTH);
63 DEFINE_WINDOW_PROPERTY_KEY(float, 64 DEFINE_WINDOW_PROPERTY_KEY(float,
64 kWindowVisibilityAnimationVerticalPositionKey, 65 kWindowVisibilityAnimationVerticalPositionKey,
65 kWindowAnimation_Vertical_TranslateY); 66 kWindowAnimation_Vertical_TranslateY);
66 67
67 namespace { 68 namespace {
68 69
70 const int kDefaultAnimationDurationMS = 200;
69 const int kDefaultAnimationDurationForMenuMS = 150; 71 const int kDefaultAnimationDurationForMenuMS = 150;
70 72
71 const float kWindowAnimation_HideOpacity = 0.f; 73 const float kWindowAnimation_HideOpacity = 0.f;
72 const float kWindowAnimation_ShowOpacity = 1.f; 74 const float kWindowAnimation_ShowOpacity = 1.f;
73 const float kWindowAnimation_TranslateFactor = 0.5f; 75 const float kWindowAnimation_TranslateFactor = 0.5f;
74 const float kWindowAnimation_ScaleFactor = .95f; 76 const float kWindowAnimation_ScaleFactor = .95f;
75 77
76 const int kWindowAnimation_Rotate_DurationMS = 180; 78 const int kWindowAnimation_Rotate_DurationMS = 180;
77 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90; 79 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90;
78 const float kWindowAnimation_Rotate_TranslateY = -20.f; 80 const float kWindowAnimation_Rotate_TranslateY = -20.f;
79 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f; 81 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f;
80 const float kWindowAnimation_Rotate_DegreesX = 5.f; 82 const float kWindowAnimation_Rotate_DegreesX = 5.f;
81 const float kWindowAnimation_Rotate_ScaleFactor = .99f; 83 const float kWindowAnimation_Rotate_ScaleFactor = .99f;
82 84
83 const float kWindowAnimation_Bounce_Scale = 1.02f; 85 const float kWindowAnimation_Bounce_Scale = 1.02f;
84 const int kWindowAnimation_Bounce_DurationMS = 180; 86 const int kWindowAnimation_Bounce_DurationMS = 180;
85 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40; 87 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40;
86 88
87 base::TimeDelta GetWindowVisibilityAnimationDuration(aura::Window* window) { 89 base::TimeDelta GetDefaultWindowVisibilityAnimationDuration(
88 int duration = 90 aura::Window* window) {
89 window->GetProperty(kWindowVisibilityAnimationDurationKey); 91 int duration_ms = (window->type() == ui::wm::WINDOW_TYPE_MENU) ?
90 if (duration == 0 && window->type() == ui::wm::WINDOW_TYPE_MENU) { 92 kDefaultAnimationDurationForMenuMS : kDefaultAnimationDurationMS;
91 return base::TimeDelta::FromMilliseconds( 93 return base::TimeDelta::FromMilliseconds(duration_ms);
92 kDefaultAnimationDurationForMenuMS);
93 }
94 return TimeDelta::FromInternalValue(duration);
95 } 94 }
96 95
97 // Gets/sets the WindowVisibilityAnimationType associated with a window. 96 // Gets/sets the WindowVisibilityAnimationType associated with a window.
98 // TODO(beng): redundant/fold into method on public api? 97 // TODO(beng): redundant/fold into method on public api?
99 int GetWindowVisibilityAnimationType(aura::Window* window) { 98 int GetWindowVisibilityAnimationType(aura::Window* window) {
100 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey); 99 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey);
101 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) { 100 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) {
102 return (window->type() == ui::wm::WINDOW_TYPE_MENU || 101 return (window->type() == ui::wm::WINDOW_TYPE_MENU ||
103 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP) 102 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP)
104 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE 103 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 247
249 AugmentWindowSize(window, end_transform); 248 AugmentWindowSize(window, end_transform);
250 249
251 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 250 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
252 window->layer()->SetTransform(start_transform); 251 window->layer()->SetTransform(start_transform);
253 window->layer()->SetVisible(true); 252 window->layer()->SetVisible(true);
254 253
255 { 254 {
256 // Property sets within this scope will be implicitly animated. 255 // Property sets within this scope will be implicitly animated.
257 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 256 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
258 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); 257 base::TimeDelta duration = GetWindowShowAnimationDuration(window,
259 if (duration.ToInternalValue() > 0) 258 GetDefaultWindowVisibilityAnimationDuration(window));
260 settings.SetTransitionDuration(duration); 259 settings.SetTransitionDuration(duration);
261 260
262 window->layer()->SetTransform(end_transform); 261 window->layer()->SetTransform(end_transform);
263 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); 262 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
264 } 263 }
265 } 264 }
266 265
267 // Hides a window using an animation, animating its opacity from 1.f to 0.f, 266 // Hides a window using an animation, animating its opacity from 1.f to 0.f,
268 // its visibility to false, and its transform to |end_transform|. 267 // its visibility to false, and its transform to |end_transform|.
269 void AnimateHideWindowCommon(aura::Window* window, 268 void AnimateHideWindowCommon(aura::Window* window,
270 const gfx::Transform& end_transform) { 269 const gfx::Transform& end_transform) {
271 AugmentWindowSize(window, end_transform); 270 AugmentWindowSize(window, end_transform);
272 window->layer()->set_delegate(NULL); 271 window->layer()->set_delegate(NULL);
273 272
274 // Property sets within this scope will be implicitly animated. 273 // Property sets within this scope will be implicitly animated.
275 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 274 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
276 settings.AddObserver(new HidingWindowAnimationObserver(window)); 275 settings.AddObserver(new HidingWindowAnimationObserver(window));
277 276 base::TimeDelta duration = GetWindowHideAnimationDuration(window,
278 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); 277 GetDefaultWindowVisibilityAnimationDuration(window));
279 if (duration.ToInternalValue() > 0) 278 settings.SetTransitionDuration(duration);
280 settings.SetTransitionDuration(duration);
281 279
282 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 280 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
283 window->layer()->SetTransform(end_transform); 281 window->layer()->SetTransform(end_transform);
284 window->layer()->SetVisible(false); 282 window->layer()->SetVisible(false);
285 } 283 }
286 284
287 static gfx::Transform GetScaleForWindow(aura::Window* window) { 285 static gfx::Transform GetScaleForWindow(aura::Window* window) {
288 gfx::Rect bounds = window->bounds(); 286 gfx::Rect bounds = window->bounds();
289 gfx::Transform scale = gfx::GetScaleTransform( 287 gfx::Transform scale = gfx::GetScaleTransform(
290 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(), 288 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 base::TimeDelta::FromMilliseconds( 363 base::TimeDelta::FromMilliseconds(
366 kWindowAnimation_Bounce_DurationMS * 364 kWindowAnimation_Bounce_DurationMS *
367 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / 365 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) /
368 100))); 366 100)));
369 sequence->AddElement(CreateGrowShrinkElement(window, false)); 367 sequence->AddElement(CreateGrowShrinkElement(window, false));
370 window->layer()->GetAnimator()->StartAnimation(sequence.release()); 368 window->layer()->GetAnimator()->StartAnimation(sequence.release());
371 } 369 }
372 370
373 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { 371 void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
374 window->layer()->set_delegate(window); 372 window->layer()->set_delegate(window);
375 if (show) 373 if (show) {
374 window->layer()->SetVisible(true);
376 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 375 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
376 }
377 377
378 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( 378 base::TimeDelta default_duration = base::TimeDelta::FromMilliseconds(
379 kWindowAnimation_Rotate_DurationMS); 379 kWindowAnimation_Rotate_DurationMS);
380 base::TimeDelta duration = show ?
381 GetWindowShowAnimationDuration(window, default_duration) :
382 GetWindowHideAnimationDuration(window, default_duration);
383
384 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
385 settings.SetTransitionDuration(duration);
380 386
381 if (!show) { 387 if (!show) {
pkotwicz 2013/12/23 01:12:06 Previously, we were leaking memory here.
varkha 2014/01/02 20:24:26 Why wasn't the hiding observer deleting itself upo
pkotwicz 2014/01/02 20:30:00 We were never setting the HidingWindowAnimationObs
varkha 2014/01/02 21:35:27 I see. Don't you want to use views::corewm::Create
382 new HidingWindowAnimationObserver(window); 388 settings.AddObserver(new HidingWindowAnimationObserver(window));
383 window->layer()->GetAnimator()->SchedulePauseForProperties( 389 window->layer()->GetAnimator()->SchedulePauseForProperties(
384 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, 390 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100,
385 ui::LayerAnimationElement::OPACITY, 391 ui::LayerAnimationElement::OPACITY,
386 -1); 392 -1);
393 window->layer()->SetVisible(false);
387 } 394 }
388 scoped_ptr<ui::LayerAnimationElement> opacity( 395 scoped_ptr<ui::LayerAnimationElement> opacity(
389 ui::LayerAnimationElement::CreateOpacityElement( 396 ui::LayerAnimationElement::CreateOpacityElement(
390 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, 397 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity,
391 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); 398 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100));
392 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); 399 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT);
393 window->layer()->GetAnimator()->ScheduleAnimation( 400 window->layer()->GetAnimator()->ScheduleAnimation(
394 new ui::LayerAnimationSequence(opacity.release())); 401 new ui::LayerAnimationSequence(opacity.release()));
395 402
396 float xcenter = window->bounds().width() * 0.5; 403 float xcenter = window->bounds().width() * 0.5;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 525 }
519 526
520 bool HasWindowVisibilityAnimationTransition( 527 bool HasWindowVisibilityAnimationTransition(
521 aura::Window* window, 528 aura::Window* window,
522 WindowVisibilityAnimationTransition transition) { 529 WindowVisibilityAnimationTransition transition) {
523 WindowVisibilityAnimationTransition prop = window->GetProperty( 530 WindowVisibilityAnimationTransition prop = window->GetProperty(
524 kWindowVisibilityAnimationTransitionKey); 531 kWindowVisibilityAnimationTransitionKey);
525 return (prop & transition) != 0; 532 return (prop & transition) != 0;
526 } 533 }
527 534
528 void SetWindowVisibilityAnimationDuration(aura::Window* window, 535 void SetWindowShowAnimationDuration(aura::Window* window,
529 const TimeDelta& duration) { 536 const base::TimeDelta& duration) {
530 window->SetProperty(kWindowVisibilityAnimationDurationKey, 537 window->SetProperty(kWindowShowAnimationDurationKey,
531 static_cast<int>(duration.ToInternalValue())); 538 static_cast<int>(duration.ToInternalValue()));
532 } 539 }
533 540
541 void SetWindowHideAnimationDuration(aura::Window* window,
542 const base::TimeDelta& duration) {
543 window->SetProperty(kWindowHideAnimationDurationKey,
544 static_cast<int>(duration.ToInternalValue()));
545 }
546
547 base::TimeDelta GetWindowShowAnimationDuration(
548 aura::Window* window,
549 const base::TimeDelta& default_duration) {
550 int duration = window->GetProperty(kWindowShowAnimationDurationKey);
551 return (duration == 0) ?
552 default_duration : base::TimeDelta::FromInternalValue(duration);
553 }
554
555 base::TimeDelta GetWindowHideAnimationDuration(
556 aura::Window* window,
557 const base::TimeDelta& default_duration) {
558 int duration = window->GetProperty(kWindowHideAnimationDurationKey);
559 return (duration == 0) ?
560 default_duration : base::TimeDelta::FromInternalValue(duration);
561 }
562
534 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, 563 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window,
535 float position) { 564 float position) {
536 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); 565 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position);
537 } 566 }
538 567
539 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver( 568 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver(
540 aura::Window* window) { 569 aura::Window* window) {
541 return new HidingWindowAnimationObserver(window); 570 return new HidingWindowAnimationObserver(window);
542 } 571 }
543 572
(...skipping 20 matching lines...) Expand all
564 593
565 bool WindowAnimationsDisabled(aura::Window* window) { 594 bool WindowAnimationsDisabled(aura::Window* window) {
566 return (window && 595 return (window &&
567 window->GetProperty(aura::client::kAnimationsDisabledKey)) || 596 window->GetProperty(aura::client::kAnimationsDisabledKey)) ||
568 CommandLine::ForCurrentProcess()->HasSwitch( 597 CommandLine::ForCurrentProcess()->HasSwitch(
569 switches::kWindowAnimationsDisabled); 598 switches::kWindowAnimationsDisabled);
570 } 599 }
571 600
572 } // namespace corewm 601 } // namespace corewm
573 } // namespace views 602 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698