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