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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // Recalculate the transform at restore time since the launcher item may have | 98 // Recalculate the transform at restore time since the launcher item may have |
99 // moved while the window was minimized. | 99 // moved while the window was minimized. |
100 gfx::Rect bounds = window->bounds(); | 100 gfx::Rect bounds = window->bounds(); |
101 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); | 101 gfx::Rect target_bounds = GetMinimizeAnimationTargetBoundsInScreen(window); |
102 target_bounds = | 102 target_bounds = |
103 ScreenUtil::ConvertRectFromScreen(window->parent(), target_bounds); | 103 ScreenUtil::ConvertRectFromScreen(window->parent(), target_bounds); |
104 | 104 |
105 float scale_x = static_cast<float>(target_bounds.width()) / bounds.width(); | 105 float scale_x = static_cast<float>(target_bounds.width()) / bounds.width(); |
106 float scale_y = static_cast<float>(target_bounds.height()) / bounds.height(); | 106 float scale_y = static_cast<float>(target_bounds.height()) / bounds.height(); |
107 | 107 |
108 scoped_ptr<ui::InterpolatedTransform> scale( | 108 std::unique_ptr<ui::InterpolatedTransform> scale(new ui::InterpolatedScale( |
109 new ui::InterpolatedScale(gfx::Point3F(1, 1, 1), | 109 gfx::Point3F(1, 1, 1), gfx::Point3F(scale_x, scale_y, 1))); |
110 gfx::Point3F(scale_x, scale_y, 1))); | |
111 | 110 |
112 scoped_ptr<ui::InterpolatedTransform> translation( | 111 std::unique_ptr<ui::InterpolatedTransform> translation( |
113 new ui::InterpolatedTranslation( | 112 new ui::InterpolatedTranslation( |
114 gfx::PointF(), gfx::PointF(target_bounds.x() - bounds.x(), | 113 gfx::PointF(), gfx::PointF(target_bounds.x() - bounds.x(), |
115 target_bounds.y() - bounds.y()))); | 114 target_bounds.y() - bounds.y()))); |
116 | 115 |
117 scale->SetChild(translation.release()); | 116 scale->SetChild(translation.release()); |
118 scale->SetReversed(show); | 117 scale->SetReversed(show); |
119 | 118 |
120 base::TimeDelta duration = window->layer()->GetAnimator()-> | 119 base::TimeDelta duration = window->layer()->GetAnimator()-> |
121 GetTransitionDuration(); | 120 GetTransitionDuration(); |
122 | 121 |
123 scoped_ptr<ui::LayerAnimationElement> transition( | 122 std::unique_ptr<ui::LayerAnimationElement> transition( |
124 ui::LayerAnimationElement::CreateInterpolatedTransformElement( | 123 ui::LayerAnimationElement::CreateInterpolatedTransformElement( |
125 scale.release(), duration)); | 124 scale.release(), duration)); |
126 | 125 |
127 transition->set_tween_type( | 126 transition->set_tween_type( |
128 show ? gfx::Tween::EASE_IN : gfx::Tween::EASE_IN_OUT); | 127 show ? gfx::Tween::EASE_IN : gfx::Tween::EASE_IN_OUT); |
129 | 128 |
130 window->layer()->GetAnimator()->ScheduleAnimation( | 129 window->layer()->GetAnimator()->ScheduleAnimation( |
131 new ui::LayerAnimationSequence(transition.release())); | 130 new ui::LayerAnimationSequence(transition.release())); |
132 | 131 |
133 // When hiding a window, turn off blending until the animation is 3 / 4 done | 132 // When hiding a window, turn off blending until the animation is 3 / 4 done |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 // Observer for a window cross-fade animation. If either the window closes or | 261 // Observer for a window cross-fade animation. If either the window closes or |
263 // the layer's animation completes or compositing is aborted due to GPU crash, | 262 // the layer's animation completes or compositing is aborted due to GPU crash, |
264 // it deletes the layer and removes itself as an observer. | 263 // it deletes the layer and removes itself as an observer. |
265 class CrossFadeObserver : public ui::CompositorObserver, | 264 class CrossFadeObserver : public ui::CompositorObserver, |
266 public aura::WindowObserver, | 265 public aura::WindowObserver, |
267 public ui::ImplicitAnimationObserver { | 266 public ui::ImplicitAnimationObserver { |
268 public: | 267 public: |
269 // Observes |window| for destruction, but does not take ownership. | 268 // Observes |window| for destruction, but does not take ownership. |
270 // Takes ownership of |layer| and its child layers. | 269 // Takes ownership of |layer| and its child layers. |
271 CrossFadeObserver(aura::Window* window, | 270 CrossFadeObserver(aura::Window* window, |
272 scoped_ptr<ui::LayerTreeOwner> layer_owner) | 271 std::unique_ptr<ui::LayerTreeOwner> layer_owner) |
273 : window_(window), layer_owner_(std::move(layer_owner)) { | 272 : window_(window), layer_owner_(std::move(layer_owner)) { |
274 window_->AddObserver(this); | 273 window_->AddObserver(this); |
275 layer_owner_->root()->GetCompositor()->AddObserver(this); | 274 layer_owner_->root()->GetCompositor()->AddObserver(this); |
276 } | 275 } |
277 ~CrossFadeObserver() override { | 276 ~CrossFadeObserver() override { |
278 window_->RemoveObserver(this); | 277 window_->RemoveObserver(this); |
279 window_ = NULL; | 278 window_ = NULL; |
280 layer_owner_->root()->GetCompositor()->RemoveObserver(this); | 279 layer_owner_->root()->GetCompositor()->RemoveObserver(this); |
281 } | 280 } |
282 | 281 |
(...skipping 17 matching lines...) Expand all Loading... |
300 void OnWindowRemovingFromRootWindow(aura::Window* window, | 299 void OnWindowRemovingFromRootWindow(aura::Window* window, |
301 aura::Window* new_root) override { | 300 aura::Window* new_root) override { |
302 layer_owner_->root()->GetAnimator()->StopAnimating(); | 301 layer_owner_->root()->GetAnimator()->StopAnimating(); |
303 } | 302 } |
304 | 303 |
305 // ui::ImplicitAnimationObserver overrides: | 304 // ui::ImplicitAnimationObserver overrides: |
306 void OnImplicitAnimationsCompleted() override { delete this; } | 305 void OnImplicitAnimationsCompleted() override { delete this; } |
307 | 306 |
308 private: | 307 private: |
309 aura::Window* window_; // not owned | 308 aura::Window* window_; // not owned |
310 scoped_ptr<ui::LayerTreeOwner> layer_owner_; | 309 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; |
311 | 310 |
312 DISALLOW_COPY_AND_ASSIGN(CrossFadeObserver); | 311 DISALLOW_COPY_AND_ASSIGN(CrossFadeObserver); |
313 }; | 312 }; |
314 | 313 |
315 base::TimeDelta CrossFadeAnimation( | 314 base::TimeDelta CrossFadeAnimation( |
316 aura::Window* window, | 315 aura::Window* window, |
317 scoped_ptr<ui::LayerTreeOwner> old_layer_owner, | 316 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner, |
318 gfx::Tween::Type tween_type) { | 317 gfx::Tween::Type tween_type) { |
319 DCHECK(old_layer_owner->root()); | 318 DCHECK(old_layer_owner->root()); |
320 const gfx::Rect old_bounds(old_layer_owner->root()->bounds()); | 319 const gfx::Rect old_bounds(old_layer_owner->root()->bounds()); |
321 gfx::RectF old_transformed_bounds(old_bounds); | 320 gfx::RectF old_transformed_bounds(old_bounds); |
322 gfx::Transform old_transform(old_layer_owner->root()->transform()); | 321 gfx::Transform old_transform(old_layer_owner->root()->transform()); |
323 gfx::Transform old_transform_in_root; | 322 gfx::Transform old_transform_in_root; |
324 old_transform_in_root.Translate(old_bounds.x(), old_bounds.y()); | 323 old_transform_in_root.Translate(old_bounds.x(), old_bounds.y()); |
325 old_transform_in_root.PreconcatTransform(old_transform); | 324 old_transform_in_root.PreconcatTransform(old_transform); |
326 old_transform_in_root.Translate(-old_bounds.x(), -old_bounds.y()); | 325 old_transform_in_root.Translate(-old_bounds.x(), -old_bounds.y()); |
327 old_transform_in_root.TransformRect(&old_transformed_bounds); | 326 old_transform_in_root.TransformRect(&old_transformed_bounds); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 return AnimateShowWindow(window); | 405 return AnimateShowWindow(window); |
407 // Don't start hiding the window again if it's already being hidden. | 406 // Don't start hiding the window again if it's already being hidden. |
408 return window->layer()->GetTargetOpacity() != 0.0f && | 407 return window->layer()->GetTargetOpacity() != 0.0f && |
409 AnimateHideWindow(window); | 408 AnimateHideWindow(window); |
410 } | 409 } |
411 | 410 |
412 std::vector<ui::LayerAnimationSequence*> | 411 std::vector<ui::LayerAnimationSequence*> |
413 CreateBrightnessGrayscaleAnimationSequence(float target_value, | 412 CreateBrightnessGrayscaleAnimationSequence(float target_value, |
414 base::TimeDelta duration) { | 413 base::TimeDelta duration) { |
415 gfx::Tween::Type animation_type = gfx::Tween::EASE_OUT; | 414 gfx::Tween::Type animation_type = gfx::Tween::EASE_OUT; |
416 scoped_ptr<ui::LayerAnimationSequence> brightness_sequence( | 415 std::unique_ptr<ui::LayerAnimationSequence> brightness_sequence( |
417 new ui::LayerAnimationSequence()); | 416 new ui::LayerAnimationSequence()); |
418 scoped_ptr<ui::LayerAnimationSequence> grayscale_sequence( | 417 std::unique_ptr<ui::LayerAnimationSequence> grayscale_sequence( |
419 new ui::LayerAnimationSequence()); | 418 new ui::LayerAnimationSequence()); |
420 | 419 |
421 scoped_ptr<ui::LayerAnimationElement> brightness_element( | 420 std::unique_ptr<ui::LayerAnimationElement> brightness_element( |
422 ui::LayerAnimationElement::CreateBrightnessElement( | 421 ui::LayerAnimationElement::CreateBrightnessElement(target_value, |
423 target_value, duration)); | 422 duration)); |
424 brightness_element->set_tween_type(animation_type); | 423 brightness_element->set_tween_type(animation_type); |
425 brightness_sequence->AddElement(brightness_element.release()); | 424 brightness_sequence->AddElement(brightness_element.release()); |
426 | 425 |
427 scoped_ptr<ui::LayerAnimationElement> grayscale_element( | 426 std::unique_ptr<ui::LayerAnimationElement> grayscale_element( |
428 ui::LayerAnimationElement::CreateGrayscaleElement( | 427 ui::LayerAnimationElement::CreateGrayscaleElement(target_value, |
429 target_value, duration)); | 428 duration)); |
430 grayscale_element->set_tween_type(animation_type); | 429 grayscale_element->set_tween_type(animation_type); |
431 grayscale_sequence->AddElement(grayscale_element.release()); | 430 grayscale_sequence->AddElement(grayscale_element.release()); |
432 | 431 |
433 std::vector<ui::LayerAnimationSequence*> animations; | 432 std::vector<ui::LayerAnimationSequence*> animations; |
434 animations.push_back(brightness_sequence.release()); | 433 animations.push_back(brightness_sequence.release()); |
435 animations.push_back(grayscale_sequence.release()); | 434 animations.push_back(grayscale_sequence.release()); |
436 | 435 |
437 return animations; | 436 return animations; |
438 } | 437 } |
439 | 438 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 gfx::Rect work_area = | 489 gfx::Rect work_area = |
491 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area(); | 490 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
492 int ltr_adjusted_x = base::i18n::IsRTL() ? work_area.right() : work_area.x(); | 491 int ltr_adjusted_x = base::i18n::IsRTL() ? work_area.right() : work_area.x(); |
493 return shelf->SelectValueForShelfAlignment( | 492 return shelf->SelectValueForShelfAlignment( |
494 gfx::Rect(ltr_adjusted_x, work_area.bottom(), 0, 0), | 493 gfx::Rect(ltr_adjusted_x, work_area.bottom(), 0, 0), |
495 gfx::Rect(work_area.x(), work_area.y(), 0, 0), | 494 gfx::Rect(work_area.x(), work_area.y(), 0, 0), |
496 gfx::Rect(work_area.right(), work_area.y(), 0, 0)); | 495 gfx::Rect(work_area.right(), work_area.y(), 0, 0)); |
497 } | 496 } |
498 | 497 |
499 } // namespace ash | 498 } // namespace ash |
OLD | NEW |