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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // |pause_duration| is the duration to pause at the current bounds before | 314 // |pause_duration| is the duration to pause at the current bounds before |
315 // animating. Returns the duration of the fade. | 315 // animating. Returns the duration of the fade. |
316 base::TimeDelta CrossFadeImpl(aura::Window* window, | 316 base::TimeDelta CrossFadeImpl(aura::Window* window, |
317 ui::Layer* old_layer, | 317 ui::Layer* old_layer, |
318 gfx::Tween::Type tween_type) { | 318 gfx::Tween::Type tween_type) { |
319 const gfx::Rect old_bounds(old_layer->bounds()); | 319 const gfx::Rect old_bounds(old_layer->bounds()); |
320 const gfx::Rect new_bounds(window->bounds()); | 320 const gfx::Rect new_bounds(window->bounds()); |
321 const bool old_on_top = (old_bounds.width() > new_bounds.width()); | 321 const bool old_on_top = (old_bounds.width() > new_bounds.width()); |
322 | 322 |
323 // Shorten the animation if there's not much visual movement. | 323 // Shorten the animation if there's not much visual movement. |
324 const base::TimeDelta duration = GetCrossFadeDuration(old_bounds, new_bounds); | 324 const base::TimeDelta duration = GetCrossFadeDuration(window, |
| 325 old_bounds, new_bounds); |
325 | 326 |
326 // Scale up the old layer while translating to new position. | 327 // Scale up the old layer while translating to new position. |
327 { | 328 { |
328 old_layer->GetAnimator()->StopAnimating(); | 329 old_layer->GetAnimator()->StopAnimating(); |
329 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator()); | 330 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator()); |
330 | 331 |
331 // Animation observer owns the old layer and deletes itself. | 332 // Animation observer owns the old layer and deletes itself. |
332 settings.AddObserver(new CrossFadeObserver(window, old_layer)); | 333 settings.AddObserver(new CrossFadeObserver(window, old_layer)); |
333 settings.SetTransitionDuration(duration); | 334 settings.SetTransitionDuration(duration); |
334 settings.SetTweenType(tween_type); | 335 settings.SetTweenType(tween_type); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // Ensure the higher-resolution layer is on top. | 407 // Ensure the higher-resolution layer is on top. |
407 bool old_on_top = (old_bounds.width() > new_bounds.width()); | 408 bool old_on_top = (old_bounds.width() > new_bounds.width()); |
408 if (old_on_top) | 409 if (old_on_top) |
409 old_layer->parent()->StackBelow(new_layer, old_layer); | 410 old_layer->parent()->StackBelow(new_layer, old_layer); |
410 else | 411 else |
411 old_layer->parent()->StackAbove(new_layer, old_layer); | 412 old_layer->parent()->StackAbove(new_layer, old_layer); |
412 | 413 |
413 CrossFadeImpl(window, old_layer, gfx::Tween::EASE_OUT); | 414 CrossFadeImpl(window, old_layer, gfx::Tween::EASE_OUT); |
414 } | 415 } |
415 | 416 |
416 base::TimeDelta GetCrossFadeDuration(const gfx::Rect& old_bounds, | 417 base::TimeDelta GetCrossFadeDuration(aura::Window* window, |
| 418 const gfx::Rect& old_bounds, |
417 const gfx::Rect& new_bounds) { | 419 const gfx::Rect& new_bounds) { |
418 if (views::corewm::WindowAnimationsDisabled(NULL)) | 420 if (views::corewm::WindowAnimationsDisabled(window)) |
419 return base::TimeDelta(); | 421 return base::TimeDelta(); |
420 | 422 |
421 int old_area = old_bounds.width() * old_bounds.height(); | 423 int old_area = old_bounds.width() * old_bounds.height(); |
422 int new_area = new_bounds.width() * new_bounds.height(); | 424 int new_area = new_bounds.width() * new_bounds.height(); |
423 int max_area = std::max(old_area, new_area); | 425 int max_area = std::max(old_area, new_area); |
424 // Avoid divide by zero. | 426 // Avoid divide by zero. |
425 if (max_area == 0) | 427 if (max_area == 0) |
426 return base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS); | 428 return base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS); |
427 | 429 |
428 int delta_area = std::abs(old_area - new_area); | 430 int delta_area = std::abs(old_area - new_area); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 538 } |
537 | 539 |
538 // Assume the launcher is overflowed, zoom off to the bottom right of the | 540 // Assume the launcher is overflowed, zoom off to the bottom right of the |
539 // work area. | 541 // work area. |
540 gfx::Rect work_area = | 542 gfx::Rect work_area = |
541 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); | 543 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
542 return gfx::Rect(work_area.right(), work_area.bottom(), 0, 0); | 544 return gfx::Rect(work_area.right(), work_area.bottom(), 0, 0); |
543 } | 545 } |
544 | 546 |
545 } // namespace ash | 547 } // namespace ash |
OLD | NEW |