summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/wm/window_animations.cc24
-rw-r--r--ash/wm/window_animations.h4
-rw-r--r--ash/wm/window_animations_unittest.cc30
3 files changed, 31 insertions, 27 deletions
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc
index d5d11e5..1b222a2 100644
--- a/ash/wm/window_animations.cc
+++ b/ash/wm/window_animations.cc
@@ -649,8 +649,6 @@ ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver(
return new internal::HidingWindowAnimationObserver(window);
}
-namespace internal {
-
void CrossFadeToBounds(aura::Window* window, const gfx::Rect& new_bounds) {
DCHECK(window->TargetVisibility());
gfx::Rect old_bounds = window->bounds();
@@ -658,7 +656,7 @@ void CrossFadeToBounds(aura::Window* window, const gfx::Rect& new_bounds) {
// Create fresh layers for the window and all its children to paint into.
// Takes ownership of the old layer and all its children, which will be
// cleaned up after the animation completes.
- ui::Layer* old_layer = RecreateWindowLayers(window);
+ ui::Layer* old_layer = internal::RecreateWindowLayers(window);
ui::Layer* new_layer = window->layer();
// Ensure the higher-resolution layer is on top.
@@ -672,12 +670,12 @@ void CrossFadeToBounds(aura::Window* window, const gfx::Rect& new_bounds) {
// aligned during the animation.
const ui::Tween::Type kTransformTween = ui::Tween::EASE_OUT;
// Shorten the animation if there's not much visual movement.
- TimeDelta duration = GetCrossFadeDuration(old_bounds, new_bounds);
+ TimeDelta duration = internal::GetCrossFadeDuration(old_bounds, new_bounds);
{
// Scale up the old layer while translating to new position.
ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator());
// Animation observer owns the old layer and deletes itself.
- settings.AddObserver(new CrossFadeObserver(window, old_layer));
+ settings.AddObserver(new internal::CrossFadeObserver(window, old_layer));
settings.SetTransitionDuration(duration);
settings.SetTweenType(kTransformTween);
ui::Transform out_transform;
@@ -730,20 +728,24 @@ void CrossFadeToBounds(aura::Window* window, const gfx::Rect& new_bounds) {
}
}
+namespace internal {
+
TimeDelta GetCrossFadeDuration(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
- int max_width = std::max(old_bounds.width(), new_bounds.width());
+ int old_area = old_bounds.width() * old_bounds.height();
+ int new_area = new_bounds.width() * new_bounds.height();
+ int max_area = std::max(old_area, new_area);
// Avoid divide by zero.
- if (max_width == 0)
+ if (max_area == 0)
return TimeDelta();
- int delta_width = std::abs(old_bounds.width() - new_bounds.width());
- // If the width didn't change, the animation is instantaneous.
- if (delta_width == 0)
+ int delta_area = std::abs(old_area - new_area);
+ // If the area didn't change, the animation is instantaneous.
+ if (delta_area == 0)
return TimeDelta();
float factor =
- static_cast<float>(delta_width) / static_cast<float>(max_width);
+ static_cast<float>(delta_area) / static_cast<float>(max_area);
const float kRange = kCrossFadeDurationMaxMs - kCrossFadeDurationMinMs;
return TimeDelta::FromMilliseconds(
Round64(kCrossFadeDurationMinMs + (factor * kRange)));
diff --git a/ash/wm/window_animations.h b/ash/wm/window_animations.h
index 1d1a9f7..0a7c0bc 100644
--- a/ash/wm/window_animations.h
+++ b/ash/wm/window_animations.h
@@ -74,12 +74,12 @@ ASH_EXPORT void SetWindowVisibilityAnimationVerticalPosition(
ASH_EXPORT ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver(
aura::Window* window);
-namespace internal {
-
// Animate a cross-fade of |window| from its current bounds to |new_bounds|.
ASH_EXPORT void CrossFadeToBounds(aura::Window* window,
const gfx::Rect& new_bounds);
+namespace internal {
+
// Returns the duration of the cross-fade animation based on the |old_bounds|
// and |new_bounds| of the window.
ASH_EXPORT base::TimeDelta GetCrossFadeDuration(const gfx::Rect& old_bounds,
diff --git a/ash/wm/window_animations_unittest.cc b/ash/wm/window_animations_unittest.cc
index bf51c1e..489a401 100644
--- a/ash/wm/window_animations_unittest.cc
+++ b/ash/wm/window_animations_unittest.cc
@@ -173,25 +173,27 @@ TEST_F(WindowAnimationsTest, GetCrossFadeDuration) {
EXPECT_EQ(0, GetCrossFadeDuration(screen, screen).InMilliseconds());
// Small changes are fast.
- gfx::Rect almost_screen(10, 10, 900, 400);
- EXPECT_EQ(220, GetCrossFadeDuration(almost_screen, screen).InMilliseconds());
- EXPECT_EQ(220, GetCrossFadeDuration(screen, almost_screen).InMilliseconds());
+ const int kMinimum = 100;
+ const int kRange = 300;
+ gfx::Rect almost_screen(10, 10, 1000, 450); // 90% of screen area
+ EXPECT_EQ(kMinimum + kRange / 10,
+ GetCrossFadeDuration(almost_screen, screen).InMilliseconds());
+ EXPECT_EQ(kMinimum + kRange / 10,
+ GetCrossFadeDuration(screen, almost_screen).InMilliseconds());
// Large changes are slow.
- gfx::Rect small(10, 10, 100, 100);
- EXPECT_EQ(380, GetCrossFadeDuration(small, screen).InMilliseconds());
- EXPECT_EQ(380, GetCrossFadeDuration(screen, small).InMilliseconds());
+ gfx::Rect small(10, 10, 100, 500); // 10% of screen area
+ EXPECT_EQ(kMinimum + kRange * 9 / 10,
+ GetCrossFadeDuration(small, screen).InMilliseconds());
+ EXPECT_EQ(kMinimum + kRange * 9 / 10,
+ GetCrossFadeDuration(screen, small).InMilliseconds());
// Medium changes take medium time.
gfx::Rect half_screen(10, 10, 500, 250);
- EXPECT_EQ(300, GetCrossFadeDuration(half_screen, screen).InMilliseconds());
- EXPECT_EQ(300, GetCrossFadeDuration(screen, half_screen).InMilliseconds());
-
- // Change is based on width.
- gfx::Rect narrow(10, 10, 100, 500);
- gfx::Rect wide(10, 10, 900, 500);
- EXPECT_EQ(380, GetCrossFadeDuration(narrow, screen).InMilliseconds());
- EXPECT_EQ(220, GetCrossFadeDuration(wide, screen).InMilliseconds());
+ EXPECT_EQ(kMinimum + kRange * 3 / 4,
+ GetCrossFadeDuration(half_screen, screen).InMilliseconds());
+ EXPECT_EQ(kMinimum + kRange * 3 / 4,
+ GetCrossFadeDuration(screen, half_screen).InMilliseconds());
}
} // namespace internal