summaryrefslogtreecommitdiffstats
path: root/ash/wm
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 19:31:01 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 19:31:01 +0000
commit20a0a72ecb2b0d34f5b18c8b5a020cb2208c996b (patch)
treeb0d7adf8cf1118c2e3c92182532847b5594aaad1 /ash/wm
parent9ff356b19a20d5d4a5689ac1ab45739861ac54de (diff)
downloadchromium_src-20a0a72ecb2b0d34f5b18c8b5a020cb2208c996b.zip
chromium_src-20a0a72ecb2b0d34f5b18c8b5a020cb2208c996b.tar.gz
chromium_src-20a0a72ecb2b0d34f5b18c8b5a020cb2208c996b.tar.bz2
Revert 142773 - ash: Make cross-fade duration based on area, not width
This better corresponds with the user's notion of the visual impact of the change, especially for animations where the width doesn't change much. BUG=none TEST=updated unit tests Review URL: https://chromiumcodereview.appspot.com/10561031 TBR=jamescook@chromium.org Review URL: https://chromiumcodereview.appspot.com/10563032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm')
-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, 27 insertions, 31 deletions
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc
index 1b222a2..d5d11e5 100644
--- a/ash/wm/window_animations.cc
+++ b/ash/wm/window_animations.cc
@@ -649,6 +649,8 @@ 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();
@@ -656,7 +658,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 = internal::RecreateWindowLayers(window);
+ ui::Layer* old_layer = RecreateWindowLayers(window);
ui::Layer* new_layer = window->layer();
// Ensure the higher-resolution layer is on top.
@@ -670,12 +672,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 = internal::GetCrossFadeDuration(old_bounds, new_bounds);
+ TimeDelta duration = 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 internal::CrossFadeObserver(window, old_layer));
+ settings.AddObserver(new CrossFadeObserver(window, old_layer));
settings.SetTransitionDuration(duration);
settings.SetTweenType(kTransformTween);
ui::Transform out_transform;
@@ -728,24 +730,20 @@ 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 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);
+ int max_width = std::max(old_bounds.width(), new_bounds.width());
// Avoid divide by zero.
- if (max_area == 0)
+ if (max_width == 0)
return TimeDelta();
- int delta_area = std::abs(old_area - new_area);
- // If the area didn't change, the animation is instantaneous.
- if (delta_area == 0)
+ 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)
return TimeDelta();
float factor =
- static_cast<float>(delta_area) / static_cast<float>(max_area);
+ static_cast<float>(delta_width) / static_cast<float>(max_width);
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 0a7c0bc..1d1a9f7 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 489a401..bf51c1e 100644
--- a/ash/wm/window_animations_unittest.cc
+++ b/ash/wm/window_animations_unittest.cc
@@ -173,27 +173,25 @@ TEST_F(WindowAnimationsTest, GetCrossFadeDuration) {
EXPECT_EQ(0, GetCrossFadeDuration(screen, screen).InMilliseconds());
// Small changes are fast.
- 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());
+ gfx::Rect almost_screen(10, 10, 900, 400);
+ EXPECT_EQ(220, GetCrossFadeDuration(almost_screen, screen).InMilliseconds());
+ EXPECT_EQ(220, GetCrossFadeDuration(screen, almost_screen).InMilliseconds());
// Large changes are slow.
- 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());
+ gfx::Rect small(10, 10, 100, 100);
+ EXPECT_EQ(380, GetCrossFadeDuration(small, screen).InMilliseconds());
+ EXPECT_EQ(380, GetCrossFadeDuration(screen, small).InMilliseconds());
// Medium changes take medium time.
gfx::Rect half_screen(10, 10, 500, 250);
- EXPECT_EQ(kMinimum + kRange * 3 / 4,
- GetCrossFadeDuration(half_screen, screen).InMilliseconds());
- EXPECT_EQ(kMinimum + kRange * 3 / 4,
- GetCrossFadeDuration(screen, half_screen).InMilliseconds());
+ 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());
}
} // namespace internal