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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90; | 77 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90; |
78 const float kWindowAnimation_Rotate_TranslateY = -20.f; | 78 const float kWindowAnimation_Rotate_TranslateY = -20.f; |
79 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f; | 79 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f; |
80 const float kWindowAnimation_Rotate_DegreesX = 5.f; | 80 const float kWindowAnimation_Rotate_DegreesX = 5.f; |
81 const float kWindowAnimation_Rotate_ScaleFactor = .99f; | 81 const float kWindowAnimation_Rotate_ScaleFactor = .99f; |
82 | 82 |
83 const float kWindowAnimation_Bounce_Scale = 1.02f; | 83 const float kWindowAnimation_Bounce_Scale = 1.02f; |
84 const int kWindowAnimation_Bounce_DurationMS = 180; | 84 const int kWindowAnimation_Bounce_DurationMS = 180; |
85 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40; | 85 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40; |
86 | 86 |
87 base::TimeDelta GetWindowVisibilityAnimationDuration(aura::Window* window) { | 87 base::TimeDelta GetWindowVisibilityAnimationDuration( |
| 88 const aura::Window& window) { |
88 int duration = | 89 int duration = |
89 window->GetProperty(kWindowVisibilityAnimationDurationKey); | 90 window.GetProperty(kWindowVisibilityAnimationDurationKey); |
90 if (duration == 0 && window->type() == ui::wm::WINDOW_TYPE_MENU) { | 91 if (duration == 0 && window.type() == ui::wm::WINDOW_TYPE_MENU) { |
91 return base::TimeDelta::FromMilliseconds( | 92 return base::TimeDelta::FromMilliseconds( |
92 kDefaultAnimationDurationForMenuMS); | 93 kDefaultAnimationDurationForMenuMS); |
93 } | 94 } |
94 return TimeDelta::FromInternalValue(duration); | 95 return TimeDelta::FromInternalValue(duration); |
95 } | 96 } |
96 | 97 |
97 // Gets/sets the WindowVisibilityAnimationType associated with a window. | 98 // Gets/sets the WindowVisibilityAnimationType associated with a window. |
98 // TODO(beng): redundant/fold into method on public api? | 99 // TODO(beng): redundant/fold into method on public api? |
99 int GetWindowVisibilityAnimationType(aura::Window* window) { | 100 int GetWindowVisibilityAnimationType(aura::Window* window) { |
100 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey); | 101 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 249 |
249 AugmentWindowSize(window, end_transform); | 250 AugmentWindowSize(window, end_transform); |
250 | 251 |
251 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 252 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
252 window->layer()->SetTransform(start_transform); | 253 window->layer()->SetTransform(start_transform); |
253 window->layer()->SetVisible(true); | 254 window->layer()->SetVisible(true); |
254 | 255 |
255 { | 256 { |
256 // Property sets within this scope will be implicitly animated. | 257 // Property sets within this scope will be implicitly animated. |
257 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 258 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
258 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); | 259 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(*window); |
259 if (duration.ToInternalValue() > 0) | 260 if (duration.ToInternalValue() > 0) |
260 settings.SetTransitionDuration(duration); | 261 settings.SetTransitionDuration(duration); |
261 | 262 |
262 window->layer()->SetTransform(end_transform); | 263 window->layer()->SetTransform(end_transform); |
263 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); | 264 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); |
264 } | 265 } |
265 } | 266 } |
266 | 267 |
267 // Hides a window using an animation, animating its opacity from 1.f to 0.f, | 268 // 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|. | 269 // its visibility to false, and its transform to |end_transform|. |
269 void AnimateHideWindowCommon(aura::Window* window, | 270 void AnimateHideWindowCommon(aura::Window* window, |
270 const gfx::Transform& end_transform) { | 271 const gfx::Transform& end_transform) { |
271 AugmentWindowSize(window, end_transform); | 272 AugmentWindowSize(window, end_transform); |
272 window->layer()->set_delegate(NULL); | 273 window->layer()->set_delegate(NULL); |
273 | 274 |
274 // Property sets within this scope will be implicitly animated. | 275 // Property sets within this scope will be implicitly animated. |
275 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 276 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
276 settings.AddObserver(new HidingWindowAnimationObserver(window)); | 277 settings.AddObserver(new HidingWindowAnimationObserver(window)); |
277 | 278 |
278 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); | 279 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(*window); |
279 if (duration.ToInternalValue() > 0) | 280 if (duration.ToInternalValue() > 0) |
280 settings.SetTransitionDuration(duration); | 281 settings.SetTransitionDuration(duration); |
281 | 282 |
282 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 283 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
283 window->layer()->SetTransform(end_transform); | 284 window->layer()->SetTransform(end_transform); |
284 window->layer()->SetVisible(false); | 285 window->layer()->SetVisible(false); |
285 } | 286 } |
286 | 287 |
287 static gfx::Transform GetScaleForWindow(aura::Window* window) { | 288 static gfx::Transform GetScaleForWindow(aura::Window* window) { |
288 gfx::Rect bounds = window->bounds(); | 289 gfx::Rect bounds = window->bounds(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 kWindowVisibilityAnimationTransitionKey); | 522 kWindowVisibilityAnimationTransitionKey); |
522 return (prop & transition) != 0; | 523 return (prop & transition) != 0; |
523 } | 524 } |
524 | 525 |
525 void SetWindowVisibilityAnimationDuration(aura::Window* window, | 526 void SetWindowVisibilityAnimationDuration(aura::Window* window, |
526 const TimeDelta& duration) { | 527 const TimeDelta& duration) { |
527 window->SetProperty(kWindowVisibilityAnimationDurationKey, | 528 window->SetProperty(kWindowVisibilityAnimationDurationKey, |
528 static_cast<int>(duration.ToInternalValue())); | 529 static_cast<int>(duration.ToInternalValue())); |
529 } | 530 } |
530 | 531 |
| 532 base::TimeDelta GetWindowVisibilityAnimationDuration( |
| 533 const aura::Window& window) { |
| 534 return base::TimeDelta::FromInternalValue( |
| 535 window.GetProperty(kWindowVisibilityAnimationDurationKey)); |
| 536 } |
| 537 |
531 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, | 538 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, |
532 float position) { | 539 float position) { |
533 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); | 540 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); |
534 } | 541 } |
535 | 542 |
536 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver( | 543 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver( |
537 aura::Window* window) { | 544 aura::Window* window) { |
538 return new HidingWindowAnimationObserver(window); | 545 return new HidingWindowAnimationObserver(window); |
539 } | 546 } |
540 | 547 |
(...skipping 20 matching lines...) Expand all Loading... |
561 | 568 |
562 bool WindowAnimationsDisabled(aura::Window* window) { | 569 bool WindowAnimationsDisabled(aura::Window* window) { |
563 return (window && | 570 return (window && |
564 window->GetProperty(aura::client::kAnimationsDisabledKey)) || | 571 window->GetProperty(aura::client::kAnimationsDisabledKey)) || |
565 CommandLine::ForCurrentProcess()->HasSwitch( | 572 CommandLine::ForCurrentProcess()->HasSwitch( |
566 switches::kWindowAnimationsDisabled); | 573 switches::kWindowAnimationsDisabled); |
567 } | 574 } |
568 | 575 |
569 } // namespace corewm | 576 } // namespace corewm |
570 } // namespace views | 577 } // namespace views |
OLD | NEW |