| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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(CreateHidingWindowAnimationObserver(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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 base::TimeDelta::FromMilliseconds( | 361 base::TimeDelta::FromMilliseconds( |
| 364 kWindowAnimation_Bounce_DurationMS * | 362 kWindowAnimation_Bounce_DurationMS * |
| 365 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / | 363 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / |
| 366 100))); | 364 100))); |
| 367 sequence->AddElement(CreateGrowShrinkElement(window, false)); | 365 sequence->AddElement(CreateGrowShrinkElement(window, false)); |
| 368 window->layer()->GetAnimator()->StartAnimation(sequence.release()); | 366 window->layer()->GetAnimator()->StartAnimation(sequence.release()); |
| 369 } | 367 } |
| 370 | 368 |
| 371 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { | 369 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { |
| 372 window->layer()->set_delegate(window); | 370 window->layer()->set_delegate(window); |
| 373 if (show) | 371 if (show) { |
| 374 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 372 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
| 373 window->layer()->SetVisible(true); |
| 374 } |
| 375 | 375 |
| 376 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( | 376 base::TimeDelta default_duration = base::TimeDelta::FromMilliseconds( |
| 377 kWindowAnimation_Rotate_DurationMS); | 377 kWindowAnimation_Rotate_DurationMS); |
| 378 base::TimeDelta duration = show ? |
| 379 GetWindowShowAnimationDuration(window, default_duration) : |
| 380 GetWindowHideAnimationDuration(window, default_duration); |
| 381 |
| 382 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 383 settings.SetTransitionDuration(duration); |
| 378 | 384 |
| 379 if (!show) { | 385 if (!show) { |
| 380 new HidingWindowAnimationObserver(window); | 386 settings.AddObserver(CreateHidingWindowAnimationObserver(window)); |
| 381 window->layer()->GetAnimator()->SchedulePauseForProperties( | 387 window->layer()->GetAnimator()->SchedulePauseForProperties( |
| 382 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, | 388 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, |
| 383 ui::LayerAnimationElement::OPACITY); | 389 ui::LayerAnimationElement::OPACITY); |
| 390 window->layer()->SetVisible(false); |
| 384 } | 391 } |
| 385 scoped_ptr<ui::LayerAnimationElement> opacity( | 392 scoped_ptr<ui::LayerAnimationElement> opacity( |
| 386 ui::LayerAnimationElement::CreateOpacityElement( | 393 ui::LayerAnimationElement::CreateOpacityElement( |
| 387 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, | 394 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, |
| 388 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); | 395 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); |
| 389 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); | 396 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); |
| 390 window->layer()->GetAnimator()->ScheduleAnimation( | 397 window->layer()->GetAnimator()->ScheduleAnimation( |
| 391 new ui::LayerAnimationSequence(opacity.release())); | 398 new ui::LayerAnimationSequence(opacity.release())); |
| 392 | 399 |
| 393 float xcenter = window->bounds().width() * 0.5; | 400 float xcenter = window->bounds().width() * 0.5; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 522 } |
| 516 | 523 |
| 517 bool HasWindowVisibilityAnimationTransition( | 524 bool HasWindowVisibilityAnimationTransition( |
| 518 aura::Window* window, | 525 aura::Window* window, |
| 519 WindowVisibilityAnimationTransition transition) { | 526 WindowVisibilityAnimationTransition transition) { |
| 520 WindowVisibilityAnimationTransition prop = window->GetProperty( | 527 WindowVisibilityAnimationTransition prop = window->GetProperty( |
| 521 kWindowVisibilityAnimationTransitionKey); | 528 kWindowVisibilityAnimationTransitionKey); |
| 522 return (prop & transition) != 0; | 529 return (prop & transition) != 0; |
| 523 } | 530 } |
| 524 | 531 |
| 525 void SetWindowVisibilityAnimationDuration(aura::Window* window, | 532 void SetWindowShowAnimationDuration(aura::Window* window, |
| 526 const TimeDelta& duration) { | 533 const base::TimeDelta& duration) { |
| 527 window->SetProperty(kWindowVisibilityAnimationDurationKey, | 534 window->SetProperty(kWindowShowAnimationDurationKey, |
| 528 static_cast<int>(duration.ToInternalValue())); | 535 static_cast<int>(duration.ToInternalValue())); |
| 529 } | 536 } |
| 530 | 537 |
| 538 void SetWindowHideAnimationDuration(aura::Window* window, |
| 539 const base::TimeDelta& duration) { |
| 540 window->SetProperty(kWindowHideAnimationDurationKey, |
| 541 static_cast<int>(duration.ToInternalValue())); |
| 542 } |
| 543 |
| 544 base::TimeDelta GetWindowShowAnimationDuration( |
| 545 aura::Window* window, |
| 546 const base::TimeDelta& default_duration) { |
| 547 int duration = window->GetProperty(kWindowShowAnimationDurationKey); |
| 548 return (duration == 0) ? |
| 549 default_duration : base::TimeDelta::FromInternalValue(duration); |
| 550 } |
| 551 |
| 552 base::TimeDelta GetWindowHideAnimationDuration( |
| 553 aura::Window* window, |
| 554 const base::TimeDelta& default_duration) { |
| 555 int duration = window->GetProperty(kWindowHideAnimationDurationKey); |
| 556 return (duration == 0) ? |
| 557 default_duration : base::TimeDelta::FromInternalValue(duration); |
| 558 } |
| 559 |
| 531 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, | 560 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, |
| 532 float position) { | 561 float position) { |
| 533 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); | 562 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); |
| 534 } | 563 } |
| 535 | 564 |
| 536 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver( | 565 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver( |
| 537 aura::Window* window) { | 566 aura::Window* window) { |
| 538 return new HidingWindowAnimationObserver(window); | 567 return new HidingWindowAnimationObserver(window); |
| 539 } | 568 } |
| 540 | 569 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 561 | 590 |
| 562 bool WindowAnimationsDisabled(aura::Window* window) { | 591 bool WindowAnimationsDisabled(aura::Window* window) { |
| 563 return (window && | 592 return (window && |
| 564 window->GetProperty(aura::client::kAnimationsDisabledKey)) || | 593 window->GetProperty(aura::client::kAnimationsDisabledKey)) || |
| 565 CommandLine::ForCurrentProcess()->HasSwitch( | 594 CommandLine::ForCurrentProcess()->HasSwitch( |
| 566 switches::kWindowAnimationsDisabled); | 595 switches::kWindowAnimationsDisabled); |
| 567 } | 596 } |
| 568 | 597 |
| 569 } // namespace corewm | 598 } // namespace corewm |
| 570 } // namespace views | 599 } // namespace views |
| OLD | NEW |