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

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

Issue 139013006: Revert 245031 "This CL" (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1795/src/
Patch Set: Created 6 years, 11 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 | « ui/views/corewm/window_animations.h ('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 "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, kWindowShowAnimationDurationKey, 0); 59 DEFINE_WINDOW_PROPERTY_KEY(int, kWindowVisibilityAnimationDurationKey, 0);
60 DEFINE_WINDOW_PROPERTY_KEY(int, kWindowHideAnimationDurationKey, 0);
61 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition, 60 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition,
62 kWindowVisibilityAnimationTransitionKey, 61 kWindowVisibilityAnimationTransitionKey,
63 ANIMATE_BOTH); 62 ANIMATE_BOTH);
64 DEFINE_WINDOW_PROPERTY_KEY(float, 63 DEFINE_WINDOW_PROPERTY_KEY(float,
65 kWindowVisibilityAnimationVerticalPositionKey, 64 kWindowVisibilityAnimationVerticalPositionKey,
66 kWindowAnimation_Vertical_TranslateY); 65 kWindowAnimation_Vertical_TranslateY);
67 66
68 namespace { 67 namespace {
69 68
70 const int kDefaultAnimationDurationMS = 200;
71 const int kDefaultAnimationDurationForMenuMS = 150; 69 const int kDefaultAnimationDurationForMenuMS = 150;
72 70
73 const float kWindowAnimation_HideOpacity = 0.f; 71 const float kWindowAnimation_HideOpacity = 0.f;
74 const float kWindowAnimation_ShowOpacity = 1.f; 72 const float kWindowAnimation_ShowOpacity = 1.f;
75 const float kWindowAnimation_TranslateFactor = 0.5f; 73 const float kWindowAnimation_TranslateFactor = 0.5f;
76 const float kWindowAnimation_ScaleFactor = .95f; 74 const float kWindowAnimation_ScaleFactor = .95f;
77 75
78 const int kWindowAnimation_Rotate_DurationMS = 180; 76 const int kWindowAnimation_Rotate_DurationMS = 180;
79 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90; 77 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90;
80 const float kWindowAnimation_Rotate_TranslateY = -20.f; 78 const float kWindowAnimation_Rotate_TranslateY = -20.f;
81 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f; 79 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f;
82 const float kWindowAnimation_Rotate_DegreesX = 5.f; 80 const float kWindowAnimation_Rotate_DegreesX = 5.f;
83 const float kWindowAnimation_Rotate_ScaleFactor = .99f; 81 const float kWindowAnimation_Rotate_ScaleFactor = .99f;
84 82
85 const float kWindowAnimation_Bounce_Scale = 1.02f; 83 const float kWindowAnimation_Bounce_Scale = 1.02f;
86 const int kWindowAnimation_Bounce_DurationMS = 180; 84 const int kWindowAnimation_Bounce_DurationMS = 180;
87 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40; 85 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40;
88 86
89 base::TimeDelta GetDefaultWindowVisibilityAnimationDuration( 87 base::TimeDelta GetWindowVisibilityAnimationDuration(aura::Window* window) {
90 aura::Window* window) { 88 int duration =
91 int duration_ms = (window->type() == ui::wm::WINDOW_TYPE_MENU) ? 89 window->GetProperty(kWindowVisibilityAnimationDurationKey);
92 kDefaultAnimationDurationForMenuMS : kDefaultAnimationDurationMS; 90 if (duration == 0 && window->type() == ui::wm::WINDOW_TYPE_MENU) {
93 return base::TimeDelta::FromMilliseconds(duration_ms); 91 return base::TimeDelta::FromMilliseconds(
92 kDefaultAnimationDurationForMenuMS);
93 }
94 return TimeDelta::FromInternalValue(duration);
94 } 95 }
95 96
96 // Gets/sets the WindowVisibilityAnimationType associated with a window. 97 // Gets/sets the WindowVisibilityAnimationType associated with a window.
97 // TODO(beng): redundant/fold into method on public api? 98 // TODO(beng): redundant/fold into method on public api?
98 int GetWindowVisibilityAnimationType(aura::Window* window) { 99 int GetWindowVisibilityAnimationType(aura::Window* window) {
99 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey); 100 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey);
100 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) { 101 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) {
101 return (window->type() == ui::wm::WINDOW_TYPE_MENU || 102 return (window->type() == ui::wm::WINDOW_TYPE_MENU ||
102 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP) 103 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP)
103 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE 104 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 248
248 AugmentWindowSize(window, end_transform); 249 AugmentWindowSize(window, end_transform);
249 250
250 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 251 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
251 window->layer()->SetTransform(start_transform); 252 window->layer()->SetTransform(start_transform);
252 window->layer()->SetVisible(true); 253 window->layer()->SetVisible(true);
253 254
254 { 255 {
255 // Property sets within this scope will be implicitly animated. 256 // Property sets within this scope will be implicitly animated.
256 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 257 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
257 base::TimeDelta duration = GetWindowShowAnimationDuration(window, 258 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window);
258 GetDefaultWindowVisibilityAnimationDuration(window)); 259 if (duration.ToInternalValue() > 0)
259 settings.SetTransitionDuration(duration); 260 settings.SetTransitionDuration(duration);
260 261
261 window->layer()->SetTransform(end_transform); 262 window->layer()->SetTransform(end_transform);
262 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); 263 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
263 } 264 }
264 } 265 }
265 266
266 // Hides a window using an animation, animating its opacity from 1.f to 0.f, 267 // Hides a window using an animation, animating its opacity from 1.f to 0.f,
267 // its visibility to false, and its transform to |end_transform|. 268 // its visibility to false, and its transform to |end_transform|.
268 void AnimateHideWindowCommon(aura::Window* window, 269 void AnimateHideWindowCommon(aura::Window* window,
269 const gfx::Transform& end_transform) { 270 const gfx::Transform& end_transform) {
270 AugmentWindowSize(window, end_transform); 271 AugmentWindowSize(window, end_transform);
271 window->layer()->set_delegate(NULL); 272 window->layer()->set_delegate(NULL);
272 273
273 // Property sets within this scope will be implicitly animated. 274 // Property sets within this scope will be implicitly animated.
274 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 275 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
275 settings.AddObserver(CreateHidingWindowAnimationObserver(window)); 276 settings.AddObserver(new HidingWindowAnimationObserver(window));
276 base::TimeDelta duration = GetWindowHideAnimationDuration(window, 277
277 GetDefaultWindowVisibilityAnimationDuration(window)); 278 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window);
278 settings.SetTransitionDuration(duration); 279 if (duration.ToInternalValue() > 0)
280 settings.SetTransitionDuration(duration);
279 281
280 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 282 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
281 window->layer()->SetTransform(end_transform); 283 window->layer()->SetTransform(end_transform);
282 window->layer()->SetVisible(false); 284 window->layer()->SetVisible(false);
283 } 285 }
284 286
285 static gfx::Transform GetScaleForWindow(aura::Window* window) { 287 static gfx::Transform GetScaleForWindow(aura::Window* window) {
286 gfx::Rect bounds = window->bounds(); 288 gfx::Rect bounds = window->bounds();
287 gfx::Transform scale = gfx::GetScaleTransform( 289 gfx::Transform scale = gfx::GetScaleTransform(
288 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(), 290 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 base::TimeDelta::FromMilliseconds( 363 base::TimeDelta::FromMilliseconds(
362 kWindowAnimation_Bounce_DurationMS * 364 kWindowAnimation_Bounce_DurationMS *
363 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) / 365 (100 - 2 * kWindowAnimation_Bounce_GrowShrinkDurationPercent) /
364 100))); 366 100)));
365 sequence->AddElement(CreateGrowShrinkElement(window, false)); 367 sequence->AddElement(CreateGrowShrinkElement(window, false));
366 window->layer()->GetAnimator()->StartAnimation(sequence.release()); 368 window->layer()->GetAnimator()->StartAnimation(sequence.release());
367 } 369 }
368 370
369 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { 371 void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
370 window->layer()->set_delegate(window); 372 window->layer()->set_delegate(window);
371 if (show) { 373 if (show)
372 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 374 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
373 window->layer()->SetVisible(true);
374 }
375 375
376 base::TimeDelta default_duration = base::TimeDelta::FromMilliseconds( 376 base::TimeDelta 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);
384 378
385 if (!show) { 379 if (!show) {
386 settings.AddObserver(CreateHidingWindowAnimationObserver(window)); 380 new HidingWindowAnimationObserver(window);
387 window->layer()->GetAnimator()->SchedulePauseForProperties( 381 window->layer()->GetAnimator()->SchedulePauseForProperties(
388 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, 382 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100,
389 ui::LayerAnimationElement::OPACITY); 383 ui::LayerAnimationElement::OPACITY);
390 window->layer()->SetVisible(false);
391 } 384 }
392 scoped_ptr<ui::LayerAnimationElement> opacity( 385 scoped_ptr<ui::LayerAnimationElement> opacity(
393 ui::LayerAnimationElement::CreateOpacityElement( 386 ui::LayerAnimationElement::CreateOpacityElement(
394 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, 387 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity,
395 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); 388 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100));
396 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); 389 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT);
397 window->layer()->GetAnimator()->ScheduleAnimation( 390 window->layer()->GetAnimator()->ScheduleAnimation(
398 new ui::LayerAnimationSequence(opacity.release())); 391 new ui::LayerAnimationSequence(opacity.release()));
399 392
400 float xcenter = window->bounds().width() * 0.5; 393 float xcenter = window->bounds().width() * 0.5;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 515 }
523 516
524 bool HasWindowVisibilityAnimationTransition( 517 bool HasWindowVisibilityAnimationTransition(
525 aura::Window* window, 518 aura::Window* window,
526 WindowVisibilityAnimationTransition transition) { 519 WindowVisibilityAnimationTransition transition) {
527 WindowVisibilityAnimationTransition prop = window->GetProperty( 520 WindowVisibilityAnimationTransition prop = window->GetProperty(
528 kWindowVisibilityAnimationTransitionKey); 521 kWindowVisibilityAnimationTransitionKey);
529 return (prop & transition) != 0; 522 return (prop & transition) != 0;
530 } 523 }
531 524
532 void SetWindowShowAnimationDuration(aura::Window* window, 525 void SetWindowVisibilityAnimationDuration(aura::Window* window,
533 const base::TimeDelta& duration) { 526 const TimeDelta& duration) {
534 window->SetProperty(kWindowShowAnimationDurationKey, 527 window->SetProperty(kWindowVisibilityAnimationDurationKey,
535 static_cast<int>(duration.ToInternalValue())); 528 static_cast<int>(duration.ToInternalValue()));
536 } 529 }
537 530
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
560 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, 531 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window,
561 float position) { 532 float position) {
562 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); 533 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position);
563 } 534 }
564 535
565 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver( 536 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver(
566 aura::Window* window) { 537 aura::Window* window) {
567 return new HidingWindowAnimationObserver(window); 538 return new HidingWindowAnimationObserver(window);
568 } 539 }
569 540
(...skipping 20 matching lines...) Expand all
590 561
591 bool WindowAnimationsDisabled(aura::Window* window) { 562 bool WindowAnimationsDisabled(aura::Window* window) {
592 return (window && 563 return (window &&
593 window->GetProperty(aura::client::kAnimationsDisabledKey)) || 564 window->GetProperty(aura::client::kAnimationsDisabledKey)) ||
594 CommandLine::ForCurrentProcess()->HasSwitch( 565 CommandLine::ForCurrentProcess()->HasSwitch(
595 switches::kWindowAnimationsDisabled); 566 switches::kWindowAnimationsDisabled);
596 } 567 }
597 568
598 } // namespace corewm 569 } // namespace corewm
599 } // namespace views 570 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/window_animations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698