| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // |pause_duration| is the duration to pause at the current bounds before | 317 // |pause_duration| is the duration to pause at the current bounds before |
| 318 // animating. Returns the duration of the fade. | 318 // animating. Returns the duration of the fade. |
| 319 base::TimeDelta CrossFadeImpl(aura::Window* window, | 319 base::TimeDelta CrossFadeImpl(aura::Window* window, |
| 320 ui::Layer* old_layer, | 320 ui::Layer* old_layer, |
| 321 gfx::Tween::Type tween_type) { | 321 gfx::Tween::Type tween_type) { |
| 322 const gfx::Rect old_bounds(old_layer->bounds()); | 322 const gfx::Rect old_bounds(old_layer->bounds()); |
| 323 const gfx::Rect new_bounds(window->bounds()); | 323 const gfx::Rect new_bounds(window->bounds()); |
| 324 const bool old_on_top = (old_bounds.width() > new_bounds.width()); | 324 const bool old_on_top = (old_bounds.width() > new_bounds.width()); |
| 325 | 325 |
| 326 // Shorten the animation if there's not much visual movement. | 326 // Shorten the animation if there's not much visual movement. |
| 327 const base::TimeDelta duration = GetCrossFadeDuration(old_bounds, new_bounds); | 327 const base::TimeDelta duration = GetCrossFadeDuration(window, |
| 328 old_bounds, new_bounds); |
| 328 | 329 |
| 329 // Scale up the old layer while translating to new position. | 330 // Scale up the old layer while translating to new position. |
| 330 { | 331 { |
| 331 old_layer->GetAnimator()->StopAnimating(); | 332 old_layer->GetAnimator()->StopAnimating(); |
| 332 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator()); | 333 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator()); |
| 333 | 334 |
| 334 // Animation observer owns the old layer and deletes itself. | 335 // Animation observer owns the old layer and deletes itself. |
| 335 settings.AddObserver(new CrossFadeObserver(window, old_layer)); | 336 settings.AddObserver(new CrossFadeObserver(window, old_layer)); |
| 336 settings.SetTransitionDuration(duration); | 337 settings.SetTransitionDuration(duration); |
| 337 settings.SetTweenType(tween_type); | 338 settings.SetTweenType(tween_type); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 layer_parent->Add(old_layer); | 424 layer_parent->Add(old_layer); |
| 424 const bool restoring = old_layer->bounds().width() > window->bounds().width(); | 425 const bool restoring = old_layer->bounds().width() > window->bounds().width(); |
| 425 if (restoring) | 426 if (restoring) |
| 426 layer_parent->StackAbove(old_layer, new_workspace->layer()); | 427 layer_parent->StackAbove(old_layer, new_workspace->layer()); |
| 427 else | 428 else |
| 428 layer_parent->StackBelow(old_layer, new_workspace->layer()); | 429 layer_parent->StackBelow(old_layer, new_workspace->layer()); |
| 429 | 430 |
| 430 CrossFadeImpl(window, old_layer, kCrossFadeTweenType); | 431 CrossFadeImpl(window, old_layer, kCrossFadeTweenType); |
| 431 } | 432 } |
| 432 | 433 |
| 433 base::TimeDelta GetCrossFadeDuration(const gfx::Rect& old_bounds, | 434 base::TimeDelta GetCrossFadeDuration(aura::Window* window, |
| 435 const gfx::Rect& old_bounds, |
| 434 const gfx::Rect& new_bounds) { | 436 const gfx::Rect& new_bounds) { |
| 435 if (views::corewm::WindowAnimationsDisabled(NULL)) | 437 if (views::corewm::WindowAnimationsDisabled(window)) |
| 436 return base::TimeDelta(); | 438 return base::TimeDelta(); |
| 437 | 439 |
| 438 int old_area = old_bounds.width() * old_bounds.height(); | 440 int old_area = old_bounds.width() * old_bounds.height(); |
| 439 int new_area = new_bounds.width() * new_bounds.height(); | 441 int new_area = new_bounds.width() * new_bounds.height(); |
| 440 int max_area = std::max(old_area, new_area); | 442 int max_area = std::max(old_area, new_area); |
| 441 // Avoid divide by zero. | 443 // Avoid divide by zero. |
| 442 if (max_area == 0) | 444 if (max_area == 0) |
| 443 return base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS); | 445 return base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS); |
| 444 | 446 |
| 445 int delta_area = std::abs(old_area - new_area); | 447 int delta_area = std::abs(old_area - new_area); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 555 } |
| 554 | 556 |
| 555 // Assume the launcher is overflowed, zoom off to the bottom right of the | 557 // Assume the launcher is overflowed, zoom off to the bottom right of the |
| 556 // work area. | 558 // work area. |
| 557 gfx::Rect work_area = | 559 gfx::Rect work_area = |
| 558 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); | 560 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
| 559 return gfx::Rect(work_area.right(), work_area.bottom(), 0, 0); | 561 return gfx::Rect(work_area.right(), work_area.bottom(), 0, 0); |
| 560 } | 562 } |
| 561 | 563 |
| 562 } // namespace ash | 564 } // namespace ash |
| OLD | NEW |