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