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/window_animations.h" | 5 #include "ash/wm/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const float kLayerScaleBelowSize = .9f; | 64 const float kLayerScaleBelowSize = .9f; |
65 | 65 |
66 int64 Round64(float f) { | 66 int64 Round64(float f) { |
67 return static_cast<int64>(f + 0.5f); | 67 return static_cast<int64>(f + 0.5f); |
68 } | 68 } |
69 | 69 |
70 } // namespace | 70 } // namespace |
71 | 71 |
72 const int kCrossFadeDurationMS = 200; | 72 const int kCrossFadeDurationMS = 200; |
73 | 73 |
74 void AddLayerAnimationsForMinimize(aura::Window* window, | 74 void AddLayerAnimationsForMinimize(aura::Window* window, bool show) { |
75 const base::TimeDelta& duration, | |
76 bool show) { | |
77 // Recalculate the transform at restore time since the launcher item may have | 75 // Recalculate the transform at restore time since the launcher item may have |
78 // moved while the window was minimized. | 76 // moved while the window was minimized. |
79 gfx::Rect bounds = window->bounds(); | 77 gfx::Rect bounds = window->bounds(); |
80 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); | 78 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); |
81 target_bounds = | 79 target_bounds = |
82 ScreenUtil::ConvertRectFromScreen(window->parent(), target_bounds); | 80 ScreenUtil::ConvertRectFromScreen(window->parent(), target_bounds); |
83 | 81 |
84 float scale_x = static_cast<float>(target_bounds.width()) / bounds.width(); | 82 float scale_x = static_cast<float>(target_bounds.width()) / bounds.width(); |
85 float scale_y = static_cast<float>(target_bounds.height()) / bounds.height(); | 83 float scale_y = static_cast<float>(target_bounds.height()) / bounds.height(); |
86 | 84 |
(...skipping 13 matching lines...) Expand all Loading... |
100 scoped_ptr<ui::InterpolatedTransform> rotation_about_pivot( | 98 scoped_ptr<ui::InterpolatedTransform> rotation_about_pivot( |
101 new ui::InterpolatedTransformAboutPivot( | 99 new ui::InterpolatedTransformAboutPivot( |
102 gfx::Point(bounds.width() * 0.5, bounds.height() * 0.5), | 100 gfx::Point(bounds.width() * 0.5, bounds.height() * 0.5), |
103 rotation.release())); | 101 rotation.release())); |
104 | 102 |
105 scale->SetChild(translation.release()); | 103 scale->SetChild(translation.release()); |
106 rotation_about_pivot->SetChild(scale.release()); | 104 rotation_about_pivot->SetChild(scale.release()); |
107 | 105 |
108 rotation_about_pivot->SetReversed(show); | 106 rotation_about_pivot->SetReversed(show); |
109 | 107 |
| 108 base::TimeDelta duration = window->layer()->GetAnimator()-> |
| 109 GetTransitionDuration(); |
| 110 |
110 scoped_ptr<ui::LayerAnimationElement> transition( | 111 scoped_ptr<ui::LayerAnimationElement> transition( |
111 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 112 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
112 rotation_about_pivot.release(), duration)); | 113 rotation_about_pivot.release(), duration)); |
113 | 114 |
114 transition->set_tween_type( | 115 transition->set_tween_type( |
115 show ? gfx::Tween::EASE_IN : gfx::Tween::EASE_IN_OUT); | 116 show ? gfx::Tween::EASE_IN : gfx::Tween::EASE_IN_OUT); |
116 | 117 |
117 window->layer()->GetAnimator()->ScheduleAnimation( | 118 window->layer()->GetAnimator()->ScheduleAnimation( |
118 new ui::LayerAnimationSequence(transition.release())); | 119 new ui::LayerAnimationSequence(transition.release())); |
119 | 120 |
120 // When hiding a window, turn off blending until the animation is 3 / 4 done | 121 // When hiding a window, turn off blending until the animation is 3 / 4 done |
121 // to save bandwidth and reduce jank. | 122 // to save bandwidth and reduce jank. |
122 if (!show) { | 123 if (!show) { |
123 window->layer()->GetAnimator()->SchedulePauseForProperties( | 124 window->layer()->GetAnimator()->SchedulePauseForProperties( |
124 (duration * 3) / 4, ui::LayerAnimationElement::OPACITY); | 125 (duration * 3) / 4, ui::LayerAnimationElement::OPACITY); |
125 } | 126 } |
126 | 127 |
127 // Fade in and out quickly when the window is small to reduce jank. | 128 // Fade in and out quickly when the window is small to reduce jank. |
128 float opacity = show ? 1.0f : 0.0f; | 129 float opacity = show ? 1.0f : 0.0f; |
129 window->layer()->GetAnimator()->ScheduleAnimation( | 130 window->layer()->GetAnimator()->ScheduleAnimation( |
130 new ui::LayerAnimationSequence( | 131 new ui::LayerAnimationSequence( |
131 ui::LayerAnimationElement::CreateOpacityElement( | 132 ui::LayerAnimationElement::CreateOpacityElement( |
132 opacity, duration / 4))); | 133 opacity, duration / 4))); |
133 } | 134 } |
134 | 135 |
135 void AnimateShowWindow_Minimize(aura::Window* window) { | 136 void AnimateShowWindow_Minimize(aura::Window* window) { |
136 window->layer()->set_delegate(window); | 137 window->layer()->set_delegate(window); |
137 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 138 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
138 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 139 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
139 base::TimeDelta duration = views::corewm::GetWindowShowAnimationDuration( | 140 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( |
140 window, | 141 kLayerAnimationsForMinimizeDurationMS); |
141 base::TimeDelta::FromMilliseconds(kLayerAnimationsForMinimizeDurationMS)); | |
142 settings.SetTransitionDuration(duration); | 142 settings.SetTransitionDuration(duration); |
143 AddLayerAnimationsForMinimize(window, duration, true); | 143 AddLayerAnimationsForMinimize(window, true); |
144 | 144 |
145 // Now that the window has been restored, we need to clear its animation style | 145 // Now that the window has been restored, we need to clear its animation style |
146 // to default so that normal animation applies. | 146 // to default so that normal animation applies. |
147 views::corewm::SetWindowVisibilityAnimationType( | 147 views::corewm::SetWindowVisibilityAnimationType( |
148 window, views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); | 148 window, views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); |
149 } | 149 } |
150 | 150 |
151 void AnimateHideWindow_Minimize(aura::Window* window) { | 151 void AnimateHideWindow_Minimize(aura::Window* window) { |
152 window->layer()->set_delegate(NULL); | 152 window->layer()->set_delegate(NULL); |
153 | 153 |
154 // Property sets within this scope will be implicitly animated. | 154 // Property sets within this scope will be implicitly animated. |
155 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 155 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
156 base::TimeDelta duration = views::corewm::GetWindowHideAnimationDuration( | 156 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( |
157 window, | 157 kLayerAnimationsForMinimizeDurationMS); |
158 base::TimeDelta::FromMilliseconds(kLayerAnimationsForMinimizeDurationMS)); | |
159 settings.SetTransitionDuration(duration); | 158 settings.SetTransitionDuration(duration); |
160 settings.AddObserver( | 159 settings.AddObserver( |
161 views::corewm::CreateHidingWindowAnimationObserver(window)); | 160 views::corewm::CreateHidingWindowAnimationObserver(window)); |
162 window->layer()->SetVisible(false); | 161 window->layer()->SetVisible(false); |
163 | 162 |
164 AddLayerAnimationsForMinimize(window, duration, false); | 163 AddLayerAnimationsForMinimize(window, false); |
165 } | 164 } |
166 | 165 |
167 void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window, | 166 void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window, |
168 bool show) { | 167 bool show) { |
169 window->layer()->set_delegate(window); | 168 window->layer()->set_delegate(window); |
170 | 169 |
171 float start_value, end_value; | 170 float start_value, end_value; |
172 if (show) { | 171 if (show) { |
173 start_value = kWindowAnimation_HideBrightnessGrayscale; | 172 start_value = kWindowAnimation_HideBrightnessGrayscale; |
174 end_value = kWindowAnimation_ShowBrightnessGrayscale; | 173 end_value = kWindowAnimation_ShowBrightnessGrayscale; |
175 } else { | 174 } else { |
176 start_value = kWindowAnimation_ShowBrightnessGrayscale; | 175 start_value = kWindowAnimation_ShowBrightnessGrayscale; |
177 end_value = kWindowAnimation_HideBrightnessGrayscale; | 176 end_value = kWindowAnimation_HideBrightnessGrayscale; |
178 } | 177 } |
179 | 178 |
180 window->layer()->SetLayerBrightness(start_value); | 179 window->layer()->SetLayerBrightness(start_value); |
181 window->layer()->SetLayerGrayscale(start_value); | 180 window->layer()->SetLayerGrayscale(start_value); |
182 if (show) { | 181 if (show) { |
183 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); | 182 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); |
184 window->layer()->SetVisible(true); | 183 window->layer()->SetVisible(true); |
185 } | 184 } |
186 | 185 |
187 base::TimeDelta default_duration = | 186 base::TimeDelta duration = |
188 base::TimeDelta::FromMilliseconds(kBrightnessGrayscaleFadeDurationMs); | 187 base::TimeDelta::FromMilliseconds(kBrightnessGrayscaleFadeDurationMs); |
189 base::TimeDelta duration = show ? | |
190 views::corewm::GetWindowShowAnimationDuration(window, default_duration) : | |
191 views::corewm::GetWindowHideAnimationDuration(window, default_duration); | |
192 | 188 |
193 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 189 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
194 settings.SetTransitionDuration(duration); | 190 settings.SetTransitionDuration(duration); |
195 if (!show) { | 191 if (!show) { |
196 settings.AddObserver( | 192 settings.AddObserver( |
197 views::corewm::CreateHidingWindowAnimationObserver(window)); | 193 views::corewm::CreateHidingWindowAnimationObserver(window)); |
198 } | 194 } |
199 | 195 |
200 window->layer()->GetAnimator()-> | 196 window->layer()->GetAnimator()-> |
201 ScheduleTogether( | 197 ScheduleTogether( |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 541 } |
546 | 542 |
547 // Assume the shelf is overflowed, zoom off to the bottom right of the | 543 // Assume the shelf is overflowed, zoom off to the bottom right of the |
548 // work area. | 544 // work area. |
549 gfx::Rect work_area = | 545 gfx::Rect work_area = |
550 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); | 546 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
551 return gfx::Rect(work_area.right(), work_area.bottom(), 0, 0); | 547 return gfx::Rect(work_area.right(), work_area.bottom(), 0, 0); |
552 } | 548 } |
553 | 549 |
554 } // namespace ash | 550 } // namespace ash |
OLD | NEW |