OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm/overview/scoped_overview_animation_settings_aura.h" | |
6 | |
7 #include "base/lazy_instance.h" | |
8 #include "base/metrics/histogram_macros.h" | |
9 #include "base/time/time.h" | |
10 #include "ui/aura/window.h" | |
11 #include "ui/compositor/layer.h" | |
12 #include "ui/compositor/layer_animation_observer.h" | |
13 #include "ui/compositor/scoped_layer_animation_settings.h" | |
14 #include "ui/gfx/animation/tween.h" | |
15 | |
16 namespace ash { | |
17 | |
18 namespace { | |
19 | |
20 // The time duration for transformation animations. | |
21 const int kTransitionMilliseconds = 300; | |
22 | |
23 // The time duration for fading out when closing an item. | |
24 const int kCloseFadeOutMilliseconds = 50; | |
25 | |
26 // The time duration for scaling down when an item is closed. | |
27 const int kCloseScaleMilliseconds = 100; | |
28 | |
29 // The time duration for widgets to fade in. | |
30 const int kFadeInMilliseconds = 60; | |
31 | |
32 // The time duration for widgets to fade out. | |
33 const int kFadeOutDelayMilliseconds = kTransitionMilliseconds * 1 / 5; | |
34 const int kFadeOutMilliseconds = kTransitionMilliseconds * 3 / 5; | |
35 | |
36 base::TimeDelta GetAnimationDuration(OverviewAnimationType animation_type) { | |
37 switch (animation_type) { | |
38 case OVERVIEW_ANIMATION_NONE: | |
39 return base::TimeDelta(); | |
40 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN: | |
41 return base::TimeDelta::FromMilliseconds(kFadeInMilliseconds); | |
42 case OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT: | |
43 return base::TimeDelta::FromMilliseconds(kFadeOutMilliseconds); | |
44 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS: | |
45 case OVERVIEW_ANIMATION_RESTORE_WINDOW: | |
46 return base::TimeDelta::FromMilliseconds(kTransitionMilliseconds); | |
47 case OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM: | |
48 return base::TimeDelta::FromMilliseconds(kCloseScaleMilliseconds); | |
49 case OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM: | |
50 return base::TimeDelta::FromMilliseconds(kCloseFadeOutMilliseconds); | |
51 } | |
52 NOTREACHED(); | |
53 return base::TimeDelta(); | |
54 } | |
55 | |
56 class OverviewEnterMetricsReporter : public ui::AnimationMetricsReporter { | |
57 public: | |
58 OverviewEnterMetricsReporter() = default; | |
59 ~OverviewEnterMetricsReporter() override = default; | |
60 | |
61 void Report(int value) override { | |
62 UMA_HISTOGRAM_PERCENTAGE("Ash.WindowSelector.AnimationSmoothness.Enter", | |
63 value); | |
64 } | |
65 | |
66 private: | |
67 DISALLOW_COPY_AND_ASSIGN(OverviewEnterMetricsReporter); | |
68 }; | |
69 | |
70 class OverviewExitMetricsReporter : public ui::AnimationMetricsReporter { | |
71 public: | |
72 OverviewExitMetricsReporter() = default; | |
73 ~OverviewExitMetricsReporter() override = default; | |
74 | |
75 void Report(int value) override { | |
76 UMA_HISTOGRAM_PERCENTAGE("Ash.WindowSelector.AnimationSmoothness.Exit", | |
77 value); | |
78 } | |
79 | |
80 private: | |
81 DISALLOW_COPY_AND_ASSIGN(OverviewExitMetricsReporter); | |
82 }; | |
83 | |
84 class OverviewCloseMetricsReporter : public ui::AnimationMetricsReporter { | |
85 public: | |
86 OverviewCloseMetricsReporter() = default; | |
87 ~OverviewCloseMetricsReporter() override = default; | |
88 | |
89 void Report(int value) override { | |
90 UMA_HISTOGRAM_PERCENTAGE("Ash.WindowSelector.AnimationSmoothness.Close", | |
91 value); | |
92 } | |
93 | |
94 private: | |
95 DISALLOW_COPY_AND_ASSIGN(OverviewCloseMetricsReporter); | |
96 }; | |
97 | |
98 base::LazyInstance<OverviewEnterMetricsReporter>::Leaky g_reporter_enter = | |
99 LAZY_INSTANCE_INITIALIZER; | |
100 base::LazyInstance<OverviewExitMetricsReporter>::Leaky g_reporter_exit = | |
101 LAZY_INSTANCE_INITIALIZER; | |
102 base::LazyInstance<OverviewCloseMetricsReporter>::Leaky g_reporter_close = | |
103 LAZY_INSTANCE_INITIALIZER; | |
104 | |
105 ui::AnimationMetricsReporter* GetMetricsReporter( | |
106 OverviewAnimationType animation_type) { | |
107 switch (animation_type) { | |
108 case OVERVIEW_ANIMATION_NONE: | |
109 return nullptr; | |
110 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN: | |
111 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS: | |
112 return g_reporter_enter.Pointer(); | |
113 case OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT: | |
114 case OVERVIEW_ANIMATION_RESTORE_WINDOW: | |
115 return g_reporter_exit.Pointer(); | |
116 case OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM: | |
117 case OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM: | |
118 return g_reporter_close.Pointer(); | |
119 } | |
120 NOTREACHED(); | |
121 return nullptr; | |
122 } | |
123 | |
124 } // namespace | |
125 | |
126 ScopedOverviewAnimationSettingsAura::ScopedOverviewAnimationSettingsAura( | |
127 OverviewAnimationType animation_type, | |
128 aura::Window* window) | |
129 : animation_settings_(new ui::ScopedLayerAnimationSettings( | |
130 window->layer()->GetAnimator())) { | |
131 switch (animation_type) { | |
132 case OVERVIEW_ANIMATION_NONE: | |
133 animation_settings_->SetPreemptionStrategy( | |
134 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | |
135 break; | |
136 case OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN: | |
137 animation_settings_->SetTweenType(gfx::Tween::EASE_IN); | |
138 animation_settings_->SetPreemptionStrategy( | |
139 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | |
140 break; | |
141 case OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT: | |
142 window->layer()->GetAnimator()->SchedulePauseForProperties( | |
143 base::TimeDelta::FromMilliseconds(kFadeOutDelayMilliseconds), | |
144 ui::LayerAnimationElement::OPACITY); | |
145 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); | |
146 animation_settings_->SetPreemptionStrategy( | |
147 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | |
148 break; | |
149 case OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS: | |
150 case OVERVIEW_ANIMATION_RESTORE_WINDOW: | |
151 animation_settings_->SetPreemptionStrategy( | |
152 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
153 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); | |
154 break; | |
155 case OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM: | |
156 case OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM: | |
157 animation_settings_->SetPreemptionStrategy( | |
158 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
159 animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); | |
160 break; | |
161 } | |
162 animation_settings_->SetTransitionDuration( | |
163 GetAnimationDuration(animation_type)); | |
164 animation_settings_->SetAnimationMetricsReporter( | |
165 GetMetricsReporter(animation_type)); | |
166 } | |
167 | |
168 ScopedOverviewAnimationSettingsAura::~ScopedOverviewAnimationSettingsAura() {} | |
169 | |
170 void ScopedOverviewAnimationSettingsAura::AddObserver( | |
171 ui::ImplicitAnimationObserver* observer) { | |
172 animation_settings_->AddObserver(observer); | |
173 } | |
174 | |
175 } // namespace ash | |
OLD | NEW |