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 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Recalculate the transform at restore time since the launcher item may have | 91 // Recalculate the transform at restore time since the launcher item may have |
92 // moved while the window was minimized. | 92 // moved while the window was minimized. |
93 gfx::Rect bounds = window->bounds(); | 93 gfx::Rect bounds = window->bounds(); |
94 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); | 94 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); |
95 target_bounds = | 95 target_bounds = |
96 ScreenUtil::ConvertRectFromScreen(window->parent(), target_bounds); | 96 ScreenUtil::ConvertRectFromScreen(window->parent(), target_bounds); |
97 | 97 |
98 float scale_x = static_cast<float>(target_bounds.width()) / bounds.width(); | 98 float scale_x = static_cast<float>(target_bounds.width()) / bounds.width(); |
99 float scale_y = static_cast<float>(target_bounds.height()) / bounds.height(); | 99 float scale_y = static_cast<float>(target_bounds.height()) / bounds.height(); |
100 | 100 |
101 std::unique_ptr<ui::InterpolatedTransform> scale(new ui::InterpolatedScale( | 101 std::unique_ptr<ui::InterpolatedTransform> scale = |
102 gfx::Point3F(1, 1, 1), gfx::Point3F(scale_x, scale_y, 1))); | 102 base::MakeUnique<ui::InterpolatedScale>( |
| 103 gfx::Point3F(1, 1, 1), gfx::Point3F(scale_x, scale_y, 1)); |
103 | 104 |
104 std::unique_ptr<ui::InterpolatedTransform> translation( | 105 std::unique_ptr<ui::InterpolatedTransform> translation = |
105 new ui::InterpolatedTranslation( | 106 base::MakeUnique<ui::InterpolatedTranslation>( |
106 gfx::PointF(), gfx::PointF(target_bounds.x() - bounds.x(), | 107 gfx::PointF(), gfx::PointF(target_bounds.x() - bounds.x(), |
107 target_bounds.y() - bounds.y()))); | 108 target_bounds.y() - bounds.y())); |
108 | 109 |
109 scale->SetChild(translation.release()); | 110 scale->SetChild(std::move(translation)); |
110 scale->SetReversed(show); | 111 scale->SetReversed(show); |
111 | 112 |
112 base::TimeDelta duration = | 113 base::TimeDelta duration = |
113 window->layer()->GetAnimator()->GetTransitionDuration(); | 114 window->layer()->GetAnimator()->GetTransitionDuration(); |
114 | 115 |
115 std::unique_ptr<ui::LayerAnimationElement> transition( | 116 std::unique_ptr<ui::LayerAnimationElement> transition = |
116 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 117 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
117 scale.release(), duration)); | 118 std::move(scale), duration); |
118 | 119 |
119 transition->set_tween_type(show ? gfx::Tween::EASE_IN | 120 transition->set_tween_type(show ? gfx::Tween::EASE_IN |
120 : gfx::Tween::EASE_IN_OUT); | 121 : gfx::Tween::EASE_IN_OUT); |
121 | 122 |
122 window->layer()->GetAnimator()->ScheduleAnimation( | 123 window->layer()->GetAnimator()->ScheduleAnimation( |
123 new ui::LayerAnimationSequence(transition.release())); | 124 new ui::LayerAnimationSequence(std::move(transition))); |
124 | 125 |
125 // When hiding a window, turn off blending until the animation is 3 / 4 done | 126 // When hiding a window, turn off blending until the animation is 3 / 4 done |
126 // to save bandwidth and reduce jank. | 127 // to save bandwidth and reduce jank. |
127 if (!show) { | 128 if (!show) { |
128 window->layer()->GetAnimator()->SchedulePauseForProperties( | 129 window->layer()->GetAnimator()->SchedulePauseForProperties( |
129 (duration * 3) / 4, ui::LayerAnimationElement::OPACITY); | 130 (duration * 3) / 4, ui::LayerAnimationElement::OPACITY); |
130 } | 131 } |
131 | 132 |
132 // Fade in and out quickly when the window is small to reduce jank. | 133 // Fade in and out quickly when the window is small to reduce jank. |
133 float opacity = show ? 1.0f : 0.0f; | 134 float opacity = show ? 1.0f : 0.0f; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 return AnimateShowWindow(window); | 381 return AnimateShowWindow(window); |
381 // Don't start hiding the window again if it's already being hidden. | 382 // Don't start hiding the window again if it's already being hidden. |
382 return window->layer()->GetTargetOpacity() != 0.0f && | 383 return window->layer()->GetTargetOpacity() != 0.0f && |
383 AnimateHideWindow(window); | 384 AnimateHideWindow(window); |
384 } | 385 } |
385 | 386 |
386 std::vector<ui::LayerAnimationSequence*> | 387 std::vector<ui::LayerAnimationSequence*> |
387 CreateBrightnessGrayscaleAnimationSequence(float target_value, | 388 CreateBrightnessGrayscaleAnimationSequence(float target_value, |
388 base::TimeDelta duration) { | 389 base::TimeDelta duration) { |
389 gfx::Tween::Type animation_type = gfx::Tween::EASE_OUT; | 390 gfx::Tween::Type animation_type = gfx::Tween::EASE_OUT; |
390 std::unique_ptr<ui::LayerAnimationSequence> brightness_sequence( | 391 std::unique_ptr<ui::LayerAnimationSequence> brightness_sequence = |
391 new ui::LayerAnimationSequence()); | 392 base::MakeUnique<ui::LayerAnimationSequence>(); |
392 std::unique_ptr<ui::LayerAnimationSequence> grayscale_sequence( | 393 std::unique_ptr<ui::LayerAnimationSequence> grayscale_sequence = |
393 new ui::LayerAnimationSequence()); | 394 base::MakeUnique<ui::LayerAnimationSequence>(); |
394 | 395 |
395 std::unique_ptr<ui::LayerAnimationElement> brightness_element( | 396 std::unique_ptr<ui::LayerAnimationElement> brightness_element = |
396 ui::LayerAnimationElement::CreateBrightnessElement(target_value, | 397 ui::LayerAnimationElement::CreateBrightnessElement(target_value, |
397 duration)); | 398 duration); |
398 brightness_element->set_tween_type(animation_type); | 399 brightness_element->set_tween_type(animation_type); |
399 brightness_sequence->AddElement(brightness_element.release()); | 400 brightness_sequence->AddElement(std::move(brightness_element)); |
400 | 401 |
401 std::unique_ptr<ui::LayerAnimationElement> grayscale_element( | 402 std::unique_ptr<ui::LayerAnimationElement> grayscale_element = |
402 ui::LayerAnimationElement::CreateGrayscaleElement(target_value, | 403 ui::LayerAnimationElement::CreateGrayscaleElement(target_value, duration); |
403 duration)); | |
404 grayscale_element->set_tween_type(animation_type); | 404 grayscale_element->set_tween_type(animation_type); |
405 grayscale_sequence->AddElement(grayscale_element.release()); | 405 grayscale_sequence->AddElement(std::move(grayscale_element)); |
406 | 406 |
407 std::vector<ui::LayerAnimationSequence*> animations; | 407 std::vector<ui::LayerAnimationSequence*> animations; |
408 animations.push_back(brightness_sequence.release()); | 408 animations.push_back(brightness_sequence.release()); |
409 animations.push_back(grayscale_sequence.release()); | 409 animations.push_back(grayscale_sequence.release()); |
410 | 410 |
411 return animations; | 411 return animations; |
412 } | 412 } |
413 | 413 |
414 gfx::Rect GetMinimizeAnimationTargetBoundsInScreen(aura::Window* window) { | 414 gfx::Rect GetMinimizeAnimationTargetBoundsInScreen(aura::Window* window) { |
415 WmWindow* wm_window = WmWindowAura::Get(window); | 415 WmWindow* wm_window = WmWindowAura::Get(window); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 case SHELF_ALIGNMENT_LEFT: | 451 case SHELF_ALIGNMENT_LEFT: |
452 return gfx::Rect(work_area.x(), work_area.y(), 0, 0); | 452 return gfx::Rect(work_area.x(), work_area.y(), 0, 0); |
453 case SHELF_ALIGNMENT_RIGHT: | 453 case SHELF_ALIGNMENT_RIGHT: |
454 return gfx::Rect(work_area.right(), work_area.y(), 0, 0); | 454 return gfx::Rect(work_area.right(), work_area.y(), 0, 0); |
455 } | 455 } |
456 NOTREACHED(); | 456 NOTREACHED(); |
457 return gfx::Rect(); | 457 return gfx::Rect(); |
458 } | 458 } |
459 | 459 |
460 } // namespace ash | 460 } // namespace ash |
OLD | NEW |