diff options
author | ajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-13 04:08:36 +0000 |
---|---|---|
committer | ajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-13 04:08:36 +0000 |
commit | dd31fa84c82dfac344099bfa80d774fbe9399022 (patch) | |
tree | 2745d908ab5586f774d99eece99a871dfba7ab71 | |
parent | 7539285b1aa7d67f5c78d402c3de6c884a2478b3 (diff) | |
download | chromium_src-dd31fa84c82dfac344099bfa80d774fbe9399022.zip chromium_src-dd31fa84c82dfac344099bfa80d774fbe9399022.tar.gz chromium_src-dd31fa84c82dfac344099bfa80d774fbe9399022.tar.bz2 |
Add duration_scale_mode to ui::LayerAnimator
This allows animations to be sped up or slowed down for testing
or debugging. This replaces LayerAnimator::slow_animation_mode
and LayerAnimator::disable_animations_for_tests.
BUG=129683
Review URL: https://chromiumcodereview.appspot.com/12465005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187765 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 204 insertions, 121 deletions
diff --git a/ash/desktop_background/desktop_background_controller_unittest.cc b/ash/desktop_background/desktop_background_controller_unittest.cc index 7b23cc5..201f7ac 100644 --- a/ash/desktop_background/desktop_background_controller_unittest.cc +++ b/ash/desktop_background/desktop_background_controller_unittest.cc @@ -11,6 +11,7 @@ #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" #include "ui/aura/root_window.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/test/layer_animator_test_controller.h" #include "ui/gfx/image/image_skia_rep.h" @@ -36,7 +37,8 @@ int ChildCountForContainer(int container_id) { // enabled. void RunAnimationForWidget(views::Widget* widget) { // Animations must be enabled for stepping to work. - DCHECK(!ui::LayerAnimator::disable_animations_for_test()); + ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); ui::Layer* layer = widget->GetNativeView()->layer(); ui::LayerAnimatorTestController controller(layer->GetAnimator()); @@ -126,7 +128,8 @@ TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { TEST_F(DesktopBackgroundControllerTest, ControllerOwnership) { // We cannot short-circuit animations for this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); // Create wallpaper and background view. DesktopBackgroundController* controller = @@ -144,9 +147,10 @@ TEST_F(DesktopBackgroundControllerTest, ControllerOwnership) { EXPECT_FALSE(root->GetProperty(kDesktopController)); // Force the widget's layer animation to play to completion. - RunAnimationForWidget( - root->GetProperty(kAnimatingDesktopController)->GetController(false)-> - widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + root->GetProperty(kAnimatingDesktopController)->GetController(false)-> + widget())); // Ownership has moved from kAnimatingDesktopController to kDesktopController. EXPECT_FALSE( @@ -158,7 +162,8 @@ TEST_F(DesktopBackgroundControllerTest, ControllerOwnership) { // move all desktop views if there are more than one. TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { // We cannot short-circuit animations for this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); // Reset wallpaper state, see ControllerOwnership above. DesktopBackgroundController* controller = @@ -167,9 +172,10 @@ TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { // Run wallpaper show animation to completion. RootWindow* root = Shell::GetPrimaryRootWindow(); - RunAnimationForWidget( - root->GetProperty(kAnimatingDesktopController)->GetController(false)-> - widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + root->GetProperty(kAnimatingDesktopController)->GetController(false)-> + widget())); // User locks the screen, which moves the background forward. controller->MoveDesktopToLockedContainer(); @@ -195,9 +201,10 @@ TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); // Finish the new desktop background animation. - RunAnimationForWidget( - root->GetProperty(kAnimatingDesktopController)->GetController(false)-> - widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + root->GetProperty(kAnimatingDesktopController)->GetController(false)-> + widget())); // Now there is one desktop background, in the back. EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); @@ -208,7 +215,8 @@ TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { // animation and replace current wallpaper before next animation starts. TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { // We cannot short-circuit animations for this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); // Reset wallpaper state, see ControllerOwnership above. DesktopBackgroundController* controller = @@ -217,9 +225,10 @@ TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { // Run wallpaper show animation to completion. RootWindow* root = Shell::GetPrimaryRootWindow(); - RunAnimationForWidget( - root->GetProperty(kAnimatingDesktopController)->GetController(false)-> - widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + root->GetProperty(kAnimatingDesktopController)->GetController(false)-> + widget())); // Change to a new wallpaper. controller->CreateEmptyWallpaper(); @@ -240,9 +249,10 @@ TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { root->GetProperty(kAnimatingDesktopController)->GetController(false); // Run wallpaper show animation to completion. - RunAnimationForWidget( - root->GetProperty(kAnimatingDesktopController)->GetController(false)-> - widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + root->GetProperty(kAnimatingDesktopController)->GetController(false)-> + widget())); EXPECT_TRUE(root->GetProperty(kDesktopController)); EXPECT_FALSE( @@ -260,7 +270,8 @@ TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { TEST_F(DesktopBackgroundControllerTest, MAYBE_ResizeToFitScreens) { // We cannot short-circuit animations for this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); // Keeps in sync with WallpaperLayout enum. WallpaperLayout layouts[4] = { @@ -281,9 +292,10 @@ TEST_F(DesktopBackgroundControllerTest, MAYBE_ResizeToFitScreens) { // Run wallpaper show animation to completion. RootWindow* root = Shell::GetPrimaryRootWindow(); - RunAnimationForWidget( - root->GetProperty(kAnimatingDesktopController)->GetController(false)-> - widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + root->GetProperty(kAnimatingDesktopController)-> + GetController(false)->widget())); // Resize is not needed. EXPECT_EQ(10, controller->GetWallpaper().width()); @@ -294,9 +306,10 @@ TEST_F(DesktopBackgroundControllerTest, MAYBE_ResizeToFitScreens) { controller->SetCustomWallpaper(large, layout); AddWallpaperResizerObserver(); - RunAnimationForWidget( - root->GetProperty(kAnimatingDesktopController)->GetController(false)-> - widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + root->GetProperty(kAnimatingDesktopController)-> + GetController(false)->widget())); WaitForResize(); RemoveWallpaperResizerObserver(); EXPECT_EQ(800, controller->GetWallpaper().width()); @@ -308,9 +321,10 @@ TEST_F(DesktopBackgroundControllerTest, MAYBE_ResizeToFitScreens) { Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); for (Shell::RootWindowList::iterator iter = root_windows.begin(); iter != root_windows.end(); ++iter) { - RunAnimationForWidget( - (*iter)->GetProperty(kAnimatingDesktopController)-> - GetController(false)->widget()); + ASSERT_NO_FATAL_FAILURE( + RunAnimationForWidget( + (*iter)->GetProperty(kAnimatingDesktopController)-> + GetController(false)->widget())); } WaitForResize(); RemoveWallpaperResizerObserver(); diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc index 635617b..9c91137 100644 --- a/ash/launcher/launcher_view.cc +++ b/ash/launcher/launcher_view.cc @@ -31,6 +31,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/canvas.h" #include "ui/views/animation/bounds_animator.h" #include "ui/views/border.h" @@ -80,20 +81,6 @@ const int kMaximumAppMenuItemLength = 250; namespace { -// An object which turns slow animations on during its lifetime. -class ScopedAnimationSetter { - public: - explicit ScopedAnimationSetter() { - ui::LayerAnimator::set_slow_animation_mode(true); - } - ~ScopedAnimationSetter() { - ui::LayerAnimator::set_slow_animation_mode(false); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedAnimationSetter); -}; - // The MenuModelAdapter gets slightly changed to adapt the menu appearance to // our requirements. class LauncherMenuModelAdapter @@ -1277,9 +1264,11 @@ void LauncherView::ButtonPressed(views::Button* sender, { // Slow down activation animations if shift key is pressed. - scoped_ptr<ScopedAnimationSetter> slowing_animations; - if (event.IsShiftDown()) - slowing_animations.reset(new ScopedAnimationSetter()); + scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; + if (event.IsShiftDown()) { + slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); + } // Collect usage statistics before we decide what to do with the click. switch (model_->items()[view_index].type) { diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index 0082da2..2e2dd3e 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -27,6 +27,7 @@ #include "ui/aura/window_delegate.h" #include "ui/base/ime/text_input_test_support.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/display.h" #include "ui/gfx/screen.h" @@ -95,7 +96,8 @@ void AshTestBase::SetUp() { aura::test::SetUsePopupAsRootWindowForTest(true); #endif // Disable animations during tests. - ui::LayerAnimator::set_disable_animations_for_test(true); + zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); ui::TextInputTestSupport::Initialize(); // Creates Shell and hook with Desktop. diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index 3b4bd1d..5b0438c 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -28,6 +28,10 @@ class EventGenerator; } // namespace test } // namespace aura +namespace ui { +class ScopedAnimationDurationScaleMode; +} // namespace ui + namespace ash { namespace internal { class DisplayManager; @@ -110,6 +114,8 @@ class AshTestBase : public testing::Test { scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; #endif + scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; + DISALLOW_COPY_AND_ASSIGN(AshTestBase); }; diff --git a/ash/wm/custom_frame_view_ash.cc b/ash/wm/custom_frame_view_ash.cc index 6163324..6350e9a 100644 --- a/ash/wm/custom_frame_view_ash.cc +++ b/ash/wm/custom_frame_view_ash.cc @@ -11,6 +11,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image.h" @@ -164,8 +165,11 @@ gfx::Size CustomFrameViewAsh::GetMaximumSize() { // views::ButtonListener overrides: void CustomFrameViewAsh::ButtonPressed(views::Button* sender, const ui::Event& event) { - if (event.IsShiftDown()) - ui::LayerAnimator::set_slow_animation_mode(true); + scoped_ptr<ui::ScopedAnimationDurationScaleMode> slow_duration_mode; + if (event.IsShiftDown()) { + slow_duration_mode.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); + } if (sender == maximize_button_) { // The maximize button may move out from under the cursor. ResetWindowControls(); @@ -177,8 +181,6 @@ void CustomFrameViewAsh::ButtonPressed(views::Button* sender, } else if (sender == close_button_) { frame_->Close(); } - if (event.IsShiftDown()) - ui::LayerAnimator::set_slow_animation_mode(false); } //////////////////////////////////////////////////////////////////////////////// diff --git a/ash/wm/power_button_controller_unittest.cc b/ash/wm/power_button_controller_unittest.cc index 4ecb17a..a989644 100644 --- a/ash/wm/power_button_controller_unittest.cc +++ b/ash/wm/power_button_controller_unittest.cc @@ -17,6 +17,7 @@ #include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/aura/test/event_generator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" @@ -388,7 +389,8 @@ TEST_F(PowerButtonControllerTest, CancelLockToShutdown) { // Test that we handle the case where lock requests are ignored. TEST_F(PowerButtonControllerTest, LockFail) { // We require animations to have a duration for this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); controller_->set_has_legacy_power_button_for_test(false); state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); diff --git a/ash/wm/session_state_controller_impl2_unittest.cc b/ash/wm/session_state_controller_impl2_unittest.cc index ec2f998..08032e6 100644 --- a/ash/wm/session_state_controller_impl2_unittest.cc +++ b/ash/wm/session_state_controller_impl2_unittest.cc @@ -19,6 +19,7 @@ #include "ui/aura/root_window.h" #include "ui/aura/test/event_generator.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/test/compositor_test_support.h" #include "ui/gfx/rect.h" @@ -112,13 +113,15 @@ class SessionStateControllerImpl2Test : public AshTestBase { AshTestBase::SetUp(); // We would control animations in a fine way: - ui::LayerAnimator::set_disable_animations_for_test(false); + animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION)); // TODO(antrim) : restore // animator_helper_ = ui::test::CreateLayerAnimatorHelperForTest(); // Temporary disable animations so that observer is always called, and // no leaks happen during tests. - ui::LayerAnimator::set_disable_animations_for_test(true); + animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); // TODO(antrim): once there is a way to mock time and run animations, make // sure that animations are finished even in simple tests. @@ -397,6 +400,7 @@ class SessionStateControllerImpl2Test : public AshTestBase { TestSessionStateControllerDelegate* delegate_; // not owned TestShellDelegate* shell_delegate_; // not owned + scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration_mode_; scoped_ptr<SessionStateControllerImpl2::TestApi> test_api_; scoped_ptr<SessionStateAnimator::TestApi> animator_api_; // TODO(antrim) : restore @@ -719,7 +723,8 @@ TEST_F(SessionStateControllerImpl2Test, CancelLockToShutdown) { // TODO(antrim): Reenable this: http://crbug.com/167048 TEST_F(SessionStateControllerImpl2Test, DISABLED_Lock) { // We require animations to have a duration for this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); Initialize(false, user::LOGGED_IN_USER); diff --git a/ash/wm/window_animations_unittest.cc b/ash/wm/window_animations_unittest.cc index 2f9d95c..a8646b6 100644 --- a/ash/wm/window_animations_unittest.cc +++ b/ash/wm/window_animations_unittest.cc @@ -13,6 +13,7 @@ #include "ui/base/animation/animation_container_element.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" using aura::Window; using ui::Layer; @@ -25,7 +26,6 @@ class WindowAnimationsTest : public ash::test::AshTestBase { WindowAnimationsTest() {} virtual void TearDown() OVERRIDE { - ui::LayerAnimator::set_disable_animations_for_test(true); AshTestBase::TearDown(); } @@ -80,7 +80,8 @@ TEST_F(WindowAnimationsTest, LayerTargetVisibility) { } TEST_F(WindowAnimationsTest, CrossFadeToBounds) { - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_ptr<Window> window(CreateTestWindowInShellWithId(0)); window->SetBounds(gfx::Rect(5, 10, 320, 240)); diff --git a/ash/wm/workspace/workspace_manager.cc b/ash/wm/workspace/workspace_manager.cc index 951adf5..9bc17a7 100644 --- a/ash/wm/workspace/workspace_manager.cc +++ b/ash/wm/workspace/workspace_manager.cc @@ -35,6 +35,7 @@ #include "ui/base/ui_base_types.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/views/widget/widget.h" @@ -509,7 +510,8 @@ void WorkspaceManager::SetUnminimizingWorkspace(Workspace* workspace) { void WorkspaceManager::FadeDesktop(aura::Window* window, base::TimeDelta duration) { if (views::corewm::WindowAnimationsDisabled(NULL) || - ui::LayerAnimator::disable_animations_for_test()) + ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) return; base::AutoReset<bool> reseter(&creating_fade_, true); diff --git a/ash/wm/workspace/workspace_manager_unittest.cc b/ash/wm/workspace/workspace_manager_unittest.cc index d15bde4..b4d9f7a 100644 --- a/ash/wm/workspace/workspace_manager_unittest.cc +++ b/ash/wm/workspace/workspace_manager_unittest.cc @@ -30,6 +30,7 @@ #include "ui/aura/window.h" #include "ui/base/ui_base_types.h" #include "ui/compositor/layer.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" @@ -1411,7 +1412,8 @@ TEST_F(WorkspaceManagerTest, NormToMaxToNormRepositionsRemaining) { // Test that animations are triggered. TEST_F(WorkspaceManagerTest, AnimatedNormToMaxToNormRepositionsRemaining) { - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); window1->Hide(); window1->SetBounds(gfx::Rect(16, 32, 640, 320)); diff --git a/chrome/browser/chromeos/login/screen_locker_browsertest.cc b/chrome/browser/chromeos/login/screen_locker_browsertest.cc index 6e00485..456f437 100644 --- a/chrome/browser/chromeos/login/screen_locker_browsertest.cc +++ b/chrome/browser/chromeos/login/screen_locker_browsertest.cc @@ -26,6 +26,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/views/widget/widget.h" using testing::_; @@ -136,13 +137,16 @@ class ScreenLockerTest : public CrosInProcessBrowserTest { .Times(AnyNumber()); EXPECT_CALL(*mock_network_library, LoadOncNetworks(_, _, _, _)) .WillRepeatedly(Return(true)); - ui::LayerAnimator::set_disable_animations_for_test(true); + zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); } virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); } + scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; + DISALLOW_COPY_AND_ASSIGN(ScreenLockerTest); }; diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc index a06fbc7..9b3f598 100644 --- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc +++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc @@ -27,6 +27,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/base/theme_provider.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/image_skia.h" #include "ui/views/controls/button/image_button.h" @@ -292,8 +293,11 @@ void BrowserNonClientFrameViewAsh::ButtonPressed(views::Button* sender, // When shift-clicking slow down animations for visual debugging. // We used to do this via an event filter that looked for the shift key being // pressed but this interfered with several normal keyboard shortcuts. - if (event.IsShiftDown()) - ui::LayerAnimator::set_slow_animation_mode(true); + scoped_ptr<ui::ScopedAnimationDurationScaleMode> slow_duration_mode; + if (event.IsShiftDown()) { + slow_duration_mode.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); + } if (sender == size_button_) { // The maximize button may move out from under the cursor. @@ -310,9 +314,6 @@ void BrowserNonClientFrameViewAsh::ButtonPressed(views::Button* sender, } else if (sender == close_button_) { frame()->Close(); } - - if (event.IsShiftDown()) - ui::LayerAnimator::set_slow_animation_mode(false); } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/ui/views/immersive_mode_controller_browsertest.cc b/chrome/browser/ui/views/immersive_mode_controller_browsertest.cc index 808b646e..e53bed3 100644 --- a/chrome/browser/ui/views/immersive_mode_controller_browsertest.cc +++ b/chrome/browser/ui/views/immersive_mode_controller_browsertest.cc @@ -11,6 +11,7 @@ #include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/test/base/in_process_browser_test.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/rect.h" #include "ui/views/view.h" @@ -37,7 +38,8 @@ typedef InProcessBrowserTest ImmersiveModeControllerTest; // it to other Aura platforms (win_aura, linux_aura). http://crbug.com/163931 #if defined(OS_CHROMEOS) IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerTest, ImmersiveMode) { - ui::LayerAnimator::set_disable_animations_for_test(true); + ui::ScopedAnimationDurationScaleMode zero_duration_mode( + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); ASSERT_TRUE(ImmersiveModeController::UseImmersiveFullscreen()); BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); @@ -201,7 +203,8 @@ IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerTest, ImmersiveMode) { // Shelf-specific immersive mode tests. IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerTest, ImmersiveShelf) { - ui::LayerAnimator::set_disable_animations_for_test(true); + ui::ScopedAnimationDurationScaleMode zero_duration_mode( + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); ImmersiveModeController* immersive_controller = diff --git a/ui/aura/test/aura_test_helper.cc b/ui/aura/test/aura_test_helper.cc index a4400bf..7d01d2d 100644 --- a/ui/aura/test/aura_test_helper.cc +++ b/ui/aura/test/aura_test_helper.cc @@ -17,6 +17,7 @@ #include "ui/aura/test/test_stacking_client.h" #include "ui/base/test/dummy_input_method.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/screen.h" namespace aura { @@ -29,7 +30,8 @@ AuraTestHelper::AuraTestHelper(MessageLoopForUI* message_loop) DCHECK(message_loop); message_loop_ = message_loop; // Disable animations during tests. - ui::LayerAnimator::set_disable_animations_for_test(true); + zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); } AuraTestHelper::~AuraTestHelper() { diff --git a/ui/aura/test/aura_test_helper.h b/ui/aura/test/aura_test_helper.h index 958e1bc..6a44592 100644 --- a/ui/aura/test/aura_test_helper.h +++ b/ui/aura/test/aura_test_helper.h @@ -12,6 +12,7 @@ class MessageLoopForUI; namespace ui { class InputMethod; +class ScopedAnimationDurationScaleMode; } namespace aura { @@ -59,6 +60,7 @@ class AuraTestHelper { scoped_ptr<ui::InputMethod> test_input_method_; scoped_ptr<client::FocusClient> focus_client_; scoped_ptr<TestScreen> test_screen_; + scoped_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; DISALLOW_COPY_AND_ASSIGN(AuraTestHelper); }; diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 731dfc0..8b31582 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -33,6 +33,7 @@ #include "ui/base/hit_test.h" #include "ui/base/keycodes/keyboard_codes.h" #include "ui/compositor/layer.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/gfx/canvas.h" #include "ui/gfx/screen.h" @@ -1613,7 +1614,8 @@ TEST_F(WindowTest, OwnedProperty) { TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { // We cannot short-circuit animations in this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_ptr<Window> w1( CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); @@ -2509,7 +2511,8 @@ TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { BoundsChangeDelegate delegate; // We cannot short-circuit animations in this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_ptr<Window> window( CreateTestWindowWithDelegate(&delegate, 1, @@ -2543,7 +2546,8 @@ TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { BoundsChangeDelegate delegate; // We cannot short-circuit animations in this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_ptr<Window> window( CreateTestWindowWithDelegate(&delegate, 1, diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp index 63143fc..2275503 100644 --- a/ui/compositor/compositor.gyp +++ b/ui/compositor/compositor.gyp @@ -52,6 +52,8 @@ 'layer_owner.cc', 'layer_owner.h', 'layer_type.h', + 'scoped_animation_duration_scale_mode.cc', + 'scoped_animation_duration_scale_mode.h', 'scoped_layer_animation_settings.cc', 'scoped_layer_animation_settings.h', # UI tests need TestWebGraphicsContext3D, so we always build it. diff --git a/ui/compositor/layer_animation_element.cc b/ui/compositor/layer_animation_element.cc index 4952583..015e3f7 100644 --- a/ui/compositor/layer_animation_element.cc +++ b/ui/compositor/layer_animation_element.cc @@ -11,12 +11,19 @@ #include "ui/compositor/float_animation_curve_adapter.h" #include "ui/compositor/layer_animation_delegate.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/interpolated_transform.h" namespace ui { namespace { +// The factor by which duration is scaled up or down when +// ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or +// FAST_DURATION. +const int kSlowDurationScaleFactor = 4; +const int kFastDurationScaleFactor = 4; + // Pause ----------------------------------------------------------------------- class Pause : public LayerAnimationElement { public: @@ -628,13 +635,19 @@ LayerAnimationElement::ToAnimatableProperty( // static base::TimeDelta LayerAnimationElement::GetEffectiveDuration( const base::TimeDelta& duration) { - if (LayerAnimator::disable_animations_for_test()) - return base::TimeDelta(); - - if (LayerAnimator::slow_animation_mode()) - return duration * LayerAnimator::slow_animation_scale_factor(); - - return duration; + switch (ScopedAnimationDurationScaleMode::duration_scale_mode()) { + case ScopedAnimationDurationScaleMode::NORMAL_DURATION: + return duration; + case ScopedAnimationDurationScaleMode::FAST_DURATION: + return duration / kFastDurationScaleFactor; + case ScopedAnimationDurationScaleMode::SLOW_DURATION: + return duration * kSlowDurationScaleFactor; + case ScopedAnimationDurationScaleMode::ZERO_DURATION: + return base::TimeDelta(); + default: + NOTREACHED(); + return base::TimeDelta(); + } } // static diff --git a/ui/compositor/layer_animator.cc b/ui/compositor/layer_animator.cc index 2324434..52d6805 100644 --- a/ui/compositor/layer_animator.cc +++ b/ui/compositor/layer_animator.cc @@ -48,13 +48,6 @@ ui::AnimationContainer* GetAnimationContainer() { } // namespace -// static -bool LayerAnimator::disable_animations_for_test_ = false; -// static -bool LayerAnimator::slow_animation_mode_ = false; -// static -int LayerAnimator::slow_animation_scale_factor_ = 4; - // LayerAnimator public -------------------------------------------------------- LayerAnimator::LayerAnimator(base::TimeDelta transition_duration) diff --git a/ui/compositor/layer_animator.h b/ui/compositor/layer_animator.h index 27cb9db..d71a936 100644 --- a/ui/compositor/layer_animator.h +++ b/ui/compositor/layer_animator.h @@ -184,29 +184,6 @@ class COMPOSITOR_EXPORT LayerAnimator } base::TimeTicks last_step_time() const { return last_step_time_; } - // When set all animations play slowly for visual debugging. - static void set_slow_animation_mode(bool slow) { - slow_animation_mode_ = slow; - } - static bool slow_animation_mode() { return slow_animation_mode_; } - - // When in slow animation mode, animation durations are scaled by this value. - static void set_slow_animation_scale_factor(int factor) { - slow_animation_scale_factor_ = factor; - } - static int slow_animation_scale_factor() { - return slow_animation_scale_factor_; - } - - // When set to true, all animations complete immediately. - static void set_disable_animations_for_test(bool disable_animations) { - disable_animations_for_test_ = disable_animations; - } - - static bool disable_animations_for_test() { - return disable_animations_for_test_; - } - protected: virtual ~LayerAnimator(); @@ -359,15 +336,6 @@ class COMPOSITOR_EXPORT LayerAnimator // with preemption strategies that discard previous animations. bool adding_animations_; - // This causes all animations to complete immediately. - static bool disable_animations_for_test_; - - // Slows down all animations for visual debugging. - static bool slow_animation_mode_; - - // Amount to slow animations for debugging. - static int slow_animation_scale_factor_; - // Observers are notified when layer animations end, are scheduled or are // aborted. ObserverList<LayerAnimationObserver> observers_; diff --git a/ui/compositor/layer_animator_unittest.cc b/ui/compositor/layer_animator_unittest.cc index b27a3be..9a3df2d 100644 --- a/ui/compositor/layer_animator_unittest.cc +++ b/ui/compositor/layer_animator_unittest.cc @@ -13,6 +13,7 @@ #include "ui/compositor/layer_animation_delegate.h" #include "ui/compositor/layer_animation_element.h" #include "ui/compositor/layer_animation_sequence.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/test/layer_animator_test_controller.h" #include "ui/compositor/test/test_layer_animation_delegate.h" @@ -1787,7 +1788,8 @@ TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { // causes the second to be deleted, we should not attempt to animate the second // animation. TEST(LayerAnimatorTest, ObserverDeletesAnimations) { - LayerAnimator::set_disable_animations_for_test(false); + ScopedAnimationDurationScaleMode normal_duration_mode( + ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); AnimationContainerElement* element = animator.get(); animator->set_disable_timer_for_test(true); diff --git a/ui/compositor/scoped_animation_duration_scale_mode.cc b/ui/compositor/scoped_animation_duration_scale_mode.cc new file mode 100644 index 0000000..5d146f1 --- /dev/null +++ b/ui/compositor/scoped_animation_duration_scale_mode.cc @@ -0,0 +1,14 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/compositor/scoped_animation_duration_scale_mode.h" + +namespace ui { + +// static +ScopedAnimationDurationScaleMode::DurationScaleMode + ScopedAnimationDurationScaleMode::duration_scale_mode_ = + ScopedAnimationDurationScaleMode::NORMAL_DURATION; + +} // namespace ui diff --git a/ui/compositor/scoped_animation_duration_scale_mode.h b/ui/compositor/scoped_animation_duration_scale_mode.h new file mode 100644 index 0000000..a0ac5d3 --- /dev/null +++ b/ui/compositor/scoped_animation_duration_scale_mode.h @@ -0,0 +1,47 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_COMPOSITOR_SCOPED_ANIMATION_DURATION_SCALE_MODE_H_ +#define UI_COMPOSITOR_SCOPED_ANIMATION_DURATION_SCALE_MODE_H_ + +#include "base/basictypes.h" +#include "ui/compositor/compositor_export.h" + +namespace ui { + +// Speed up or slow down animations for testing or debugging. +class COMPOSITOR_EXPORT ScopedAnimationDurationScaleMode { + public: + enum DurationScaleMode { + NORMAL_DURATION, + FAST_DURATION, + SLOW_DURATION, + ZERO_DURATION + }; + + explicit ScopedAnimationDurationScaleMode( + DurationScaleMode scoped_duration_scale_mode) + : old_duration_scale_mode_(duration_scale_mode_) { + duration_scale_mode_ = scoped_duration_scale_mode; + } + + ~ScopedAnimationDurationScaleMode() { + duration_scale_mode_ = old_duration_scale_mode_; + } + + static DurationScaleMode duration_scale_mode() { + return duration_scale_mode_; + } + + private: + DurationScaleMode old_duration_scale_mode_; + + static DurationScaleMode duration_scale_mode_; + + DISALLOW_COPY_AND_ASSIGN(ScopedAnimationDurationScaleMode); +}; + +} // namespace ui + +#endif // UI_COMPOSITOR_SCOPED_ANIMATION_DURATION_SCALE_MODE_H diff --git a/ui/views/corewm/visibility_controller_unittest.cc b/ui/views/corewm/visibility_controller_unittest.cc index 0ce1b02..222d7af 100644 --- a/ui/views/corewm/visibility_controller_unittest.cc +++ b/ui/views/corewm/visibility_controller_unittest.cc @@ -11,6 +11,7 @@ #include "ui/aura/window.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" namespace views { namespace corewm { @@ -21,7 +22,8 @@ typedef aura::test::AuraTestBase VisibilityControllerTest; // immediately. TEST_F(VisibilityControllerTest, AnimateHideDoesntHideWindowLayer) { // We cannot disable animations for this test. - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); VisibilityController controller; aura::client::SetVisibilityClient(root_window(), &controller); diff --git a/ui/views/corewm/window_animations_unittest.cc b/ui/views/corewm/window_animations_unittest.cc index 66704f0..1664747 100644 --- a/ui/views/corewm/window_animations_unittest.cc +++ b/ui/views/corewm/window_animations_unittest.cc @@ -11,6 +11,7 @@ #include "ui/base/animation/animation_container_element.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_animator.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" using aura::Window; using ui::Layer; @@ -23,7 +24,6 @@ class WindowAnimationsTest : public aura::test::AuraTestBase { WindowAnimationsTest() {} virtual void TearDown() OVERRIDE { - ui::LayerAnimator::set_disable_animations_for_test(true); AuraTestBase::TearDown(); } @@ -80,7 +80,8 @@ TEST_F(WindowAnimationsTest, LayerTargetVisibility) { } TEST_F(WindowAnimationsTest, CrossFadeToBounds) { - ui::LayerAnimator::set_disable_animations_for_test(false); + ui::ScopedAnimationDurationScaleMode normal_duration_mode( + ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); scoped_ptr<Window> window( aura::test::CreateTestWindowWithId(0, NULL)); |