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 "ash/wm/session_state_animator.h" | 5 #include "ash/wm/session_state_animator.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ui/aura/root_window.h" | 9 #include "ui/aura/root_window.h" |
10 #include "ui/compositor/layer_animation_sequence.h" | 10 #include "ui/compositor/layer_animation_sequence.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Amount of time taken to make the lock window fade in when the screen is | 31 // Amount of time taken to make the lock window fade in when the screen is |
32 // locked. | 32 // locked. |
33 const int kLockFadeInAnimMs = 200; | 33 const int kLockFadeInAnimMs = 200; |
34 | 34 |
35 // Slightly-smaller size that we scale the screen down to for the pre-lock and | 35 // Slightly-smaller size that we scale the screen down to for the pre-lock and |
36 // pre-shutdown states. | 36 // pre-shutdown states. |
37 const float kSlowCloseSizeRatio = 0.95f; | 37 const float kSlowCloseSizeRatio = 0.95f; |
38 | 38 |
39 // Returns the transform that should be applied to containers for the slow-close | 39 // Returns the transform that should be applied to containers for the slow-close |
40 // animation. | 40 // animation. |
41 ui::Transform GetSlowCloseTransform() { | 41 gfx::Transform GetSlowCloseTransform() { |
42 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); | 42 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
43 ui::Transform transform; | 43 gfx::Transform transform; |
44 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); | 44 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); |
45 transform.ConcatTranslate( | 45 transform.ConcatTranslate( |
46 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), | 46 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), |
47 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); | 47 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); |
48 return transform; | 48 return transform; |
49 } | 49 } |
50 | 50 |
51 // Returns the transform that should be applied to containers for the fast-close | 51 // Returns the transform that should be applied to containers for the fast-close |
52 // animation. | 52 // animation. |
53 ui::Transform GetFastCloseTransform() { | 53 gfx::Transform GetFastCloseTransform() { |
54 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); | 54 gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
55 ui::Transform transform; | 55 gfx::Transform transform; |
56 transform.SetScale(0.0, 0.0); | 56 transform.SetScale(0.0, 0.0); |
57 transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5), | 57 transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5), |
58 floor(0.5 * root_size.height() + 0.5)); | 58 floor(0.5 * root_size.height() + 0.5)); |
59 return transform; | 59 return transform; |
60 } | 60 } |
61 | 61 |
62 // Slowly shrinks |window| to a slightly-smaller size. | 62 // Slowly shrinks |window| to a slightly-smaller size. |
63 void StartSlowCloseAnimationForWindow(aura::Window* window) { | 63 void StartSlowCloseAnimationForWindow(aura::Window* window) { |
64 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 64 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
65 animator->set_preemption_strategy( | 65 animator->set_preemption_strategy( |
66 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 66 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
67 animator->StartAnimation( | 67 animator->StartAnimation( |
68 new ui::LayerAnimationSequence( | 68 new ui::LayerAnimationSequence( |
69 ui::LayerAnimationElement::CreateTransformElement( | 69 ui::LayerAnimationElement::CreateTransformElement( |
70 GetSlowCloseTransform(), | 70 GetSlowCloseTransform(), |
71 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs)))); | 71 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs)))); |
72 } | 72 } |
73 | 73 |
74 // Quickly undoes the effects of the slow-close animation on |window|. | 74 // Quickly undoes the effects of the slow-close animation on |window|. |
75 void StartUndoSlowCloseAnimationForWindow(aura::Window* window) { | 75 void StartUndoSlowCloseAnimationForWindow(aura::Window* window) { |
76 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 76 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
77 animator->set_preemption_strategy( | 77 animator->set_preemption_strategy( |
78 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 78 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
79 animator->StartAnimation( | 79 animator->StartAnimation( |
80 new ui::LayerAnimationSequence( | 80 new ui::LayerAnimationSequence( |
81 ui::LayerAnimationElement::CreateTransformElement( | 81 ui::LayerAnimationElement::CreateTransformElement( |
82 ui::Transform(), | 82 gfx::Transform(), |
83 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs)))); | 83 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs)))); |
84 } | 84 } |
85 | 85 |
86 // Quickly shrinks |window| down to a point in the center of the screen and | 86 // Quickly shrinks |window| down to a point in the center of the screen and |
87 // fades it out to 0 opacity. | 87 // fades it out to 0 opacity. |
88 void StartFastCloseAnimationForWindow(aura::Window* window) { | 88 void StartFastCloseAnimationForWindow(aura::Window* window) { |
89 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 89 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
90 animator->set_preemption_strategy( | 90 animator->set_preemption_strategy( |
91 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 91 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
92 animator->StartAnimation( | 92 animator->StartAnimation( |
(...skipping 19 matching lines...) Expand all Loading... |
112 } | 112 } |
113 | 113 |
114 // Makes |window| fully transparent instantaneously. | 114 // Makes |window| fully transparent instantaneously. |
115 void HideWindow(aura::Window* window) { | 115 void HideWindow(aura::Window* window) { |
116 window->layer()->SetOpacity(0.0); | 116 window->layer()->SetOpacity(0.0); |
117 } | 117 } |
118 | 118 |
119 // Restores |window| to its original position and scale and full opacity | 119 // Restores |window| to its original position and scale and full opacity |
120 // instantaneously. | 120 // instantaneously. |
121 void RestoreWindow(aura::Window* window) { | 121 void RestoreWindow(aura::Window* window) { |
122 window->layer()->SetTransform(ui::Transform()); | 122 window->layer()->SetTransform(gfx::Transform()); |
123 window->layer()->SetOpacity(1.0); | 123 window->layer()->SetOpacity(1.0); |
124 } | 124 } |
125 | 125 |
126 } // namespace | 126 } // namespace |
127 | 127 |
128 void SessionStateAnimator::TestApi::TriggerHideBlackLayerTimeout() { | 128 void SessionStateAnimator::TestApi::TriggerHideBlackLayerTimeout() { |
129 animator_->DropBlackLayer(); | 129 animator_->DropBlackLayer(); |
130 animator_->hide_black_layer_timer_.Stop(); | 130 animator_->hide_black_layer_timer_.Stop(); |
131 } | 131 } |
132 | 132 |
133 bool SessionStateAnimator::TestApi::ContainersAreAnimated( | 133 bool SessionStateAnimator::TestApi::ContainersAreAnimated( |
134 int container_mask, AnimationType type) const { | 134 int container_mask, AnimationType type) const { |
135 aura::Window::Windows containers; | 135 aura::Window::Windows containers; |
136 animator_->GetContainers(container_mask, &containers); | 136 animator_->GetContainers(container_mask, &containers); |
137 for (aura::Window::Windows::const_iterator it = containers.begin(); | 137 for (aura::Window::Windows::const_iterator it = containers.begin(); |
138 it != containers.end(); ++it) { | 138 it != containers.end(); ++it) { |
139 aura::Window* window = *it; | 139 aura::Window* window = *it; |
140 ui::Layer* layer = window->layer(); | 140 ui::Layer* layer = window->layer(); |
141 | 141 |
142 switch (type) { | 142 switch (type) { |
143 case ANIMATION_SLOW_CLOSE: | 143 case ANIMATION_SLOW_CLOSE: |
144 if (layer->GetTargetTransform() != GetSlowCloseTransform()) | 144 if (layer->GetTargetTransform() != GetSlowCloseTransform()) |
145 return false; | 145 return false; |
146 break; | 146 break; |
147 case ANIMATION_UNDO_SLOW_CLOSE: | 147 case ANIMATION_UNDO_SLOW_CLOSE: |
148 if (layer->GetTargetTransform() != ui::Transform()) | 148 if (layer->GetTargetTransform() != gfx::Transform()) |
149 return false; | 149 return false; |
150 break; | 150 break; |
151 case ANIMATION_FAST_CLOSE: | 151 case ANIMATION_FAST_CLOSE: |
152 if (layer->GetTargetTransform() != GetFastCloseTransform() || | 152 if (layer->GetTargetTransform() != GetFastCloseTransform() || |
153 layer->GetTargetOpacity() > 0.0001) | 153 layer->GetTargetOpacity() > 0.0001) |
154 return false; | 154 return false; |
155 break; | 155 break; |
156 case ANIMATION_FADE_IN: | 156 case ANIMATION_FADE_IN: |
157 if (layer->GetTargetOpacity() < 0.9999) | 157 if (layer->GetTargetOpacity() < 0.9999) |
158 return false; | 158 return false; |
159 break; | 159 break; |
160 case ANIMATION_HIDE: | 160 case ANIMATION_HIDE: |
161 if (layer->GetTargetOpacity() > 0.0001) | 161 if (layer->GetTargetOpacity() > 0.0001) |
162 return false; | 162 return false; |
163 break; | 163 break; |
164 case ANIMATION_RESTORE: | 164 case ANIMATION_RESTORE: |
165 if (layer->opacity() < 0.9999 || layer->transform() != ui::Transform()) | 165 if (layer->opacity() < 0.9999 || layer->transform() != gfx::Transform()) |
166 return false; | 166 return false; |
167 break; | 167 break; |
168 default: | 168 default: |
169 NOTREACHED() << "Unhandled animation type " << type; | 169 NOTREACHED() << "Unhandled animation type " << type; |
170 return false; | 170 return false; |
171 } | 171 } |
172 } | 172 } |
173 return true; | 173 return true; |
174 } | 174 } |
175 | 175 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 void SessionStateAnimator::ScheduleDropBlackLayer() { | 314 void SessionStateAnimator::ScheduleDropBlackLayer() { |
315 hide_black_layer_timer_.Stop(); | 315 hide_black_layer_timer_.Stop(); |
316 hide_black_layer_timer_.Start( | 316 hide_black_layer_timer_.Start( |
317 FROM_HERE, | 317 FROM_HERE, |
318 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | 318 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
319 this, &SessionStateAnimator::DropBlackLayer); | 319 this, &SessionStateAnimator::DropBlackLayer); |
320 } | 320 } |
321 | 321 |
322 } // namespace internal | 322 } // namespace internal |
323 } // namespace ash | 323 } // namespace ash |
OLD | NEW |