diff options
author | nkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-21 08:13:44 +0000 |
---|---|---|
committer | nkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-21 08:13:44 +0000 |
commit | 815d0c3879d20f1514ccde4797b45501bd51c682 (patch) | |
tree | b91e9128629dc9a5c0272de68240b7e4854504d5 /ash | |
parent | 013e78129818a9c2ccdae2a8d2a953357979f449 (diff) | |
download | chromium_src-815d0c3879d20f1514ccde4797b45501bd51c682.zip chromium_src-815d0c3879d20f1514ccde4797b45501bd51c682.tar.gz chromium_src-815d0c3879d20f1514ccde4797b45501bd51c682.tar.bz2 |
Add brightness/grayscale animations and use them for OOBE boot transition.
Add support for both boot up/boot down animations.
Checked, looks fine on x86-alex, stumpy.
BUG=133279
TEST=LayerAnimatorTest.[GetTargetBrightness|GetTargetGrayscale], LayerAnimationElementTest.[BrightnessElement|GrayscaleElement], WindowAnimationsTest.HideShowBrightnessGrayscaleAnimation
Review URL: https://chromiumcodereview.appspot.com/10800020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/desktop_background/desktop_background_controller.h | 4 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_view.cc | 16 | ||||
-rw-r--r-- | ash/shell.cc | 4 | ||||
-rw-r--r-- | ash/wm/window_animations.cc | 73 | ||||
-rw-r--r-- | ash/wm/window_animations.h | 2 | ||||
-rw-r--r-- | ash/wm/window_animations_unittest.cc | 41 |
6 files changed, 132 insertions, 8 deletions
diff --git a/ash/desktop_background/desktop_background_controller.h b/ash/desktop_background/desktop_background_controller.h index acdd7cf..b575654 100644 --- a/ash/desktop_background/desktop_background_controller.h +++ b/ash/desktop_background/desktop_background_controller.h @@ -7,6 +7,7 @@ #include "ash/ash_export.h" #include "ash/desktop_background/desktop_background_resources.h" +#include "ash/wm/window_animations.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" @@ -24,6 +25,9 @@ class UserWallpaperDelegate { public: virtual ~UserWallpaperDelegate() {} + // Returns type of window animation that should be used when showin wallpaper. + virtual ash::WindowVisibilityAnimationType GetAnimationType() = 0; + // Initialize wallpaper. virtual void InitializeWallpaper() = 0; diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc index 1448a215..e5f9665 100644 --- a/ash/desktop_background/desktop_background_view.cc +++ b/ash/desktop_background/desktop_background_view.cc @@ -152,15 +152,15 @@ void CreateDesktopBackground(aura::RootWindow* root_window) { ash::internal::kShellWindowId_DesktopBackgroundContainer); desktop_widget->Init(params); desktop_widget->SetContentsView(view); - ash::SetWindowVisibilityAnimationType( - desktop_widget->GetNativeView(), - ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); - ash::SetWindowVisibilityAnimationTransition( - desktop_widget->GetNativeView(), - ash::ANIMATE_SHOW); + ash::WindowVisibilityAnimationType animation_type = + ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); + ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), + animation_type); + ash::SetWindowVisibilityAnimationTransition(desktop_widget->GetNativeView(), + ash::ANIMATE_SHOW); desktop_widget->SetBounds(params.parent->bounds()); - ui::ScopedLayerAnimationSettings settings(desktop_widget->GetNativeView()-> - layer()->GetAnimator()); + ui::ScopedLayerAnimationSettings settings( + desktop_widget->GetNativeView()->layer()->GetAnimator()); settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, desktop_widget)); diff --git a/ash/shell.cc b/ash/shell.cc index 2faa90c..2590195 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -116,6 +116,10 @@ class DummyUserWallpaperDelegate : public UserWallpaperDelegate { virtual ~DummyUserWallpaperDelegate() {} + virtual ash::WindowVisibilityAnimationType GetAnimationType() OVERRIDE { + return WINDOW_VISIBILITY_ANIMATION_TYPE_FADE; + } + virtual void InitializeWallpaper() OVERRIDE { ash::Shell::GetInstance()->desktop_background_controller()-> CreateEmptyWallpaper(); diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc index 8faaef5..2c080ff 100644 --- a/ash/wm/window_animations.cc +++ b/ash/wm/window_animations.cc @@ -69,6 +69,13 @@ const int kDefaultAnimationDurationForMenuMS = 150; const float kCrossFadeDurationMinMs = 100.f; const float kCrossFadeDurationMaxMs = 400.f; +// Durations for the brightness/grayscale fade animation, in milliseconds. +const int kBrightnessGrayscaleFadeDurationMs = 2000; + +// Brightness/grayscale values for hide/show window animations. +const float kWindowAnimation_HideBrightnessGrayscale = 1.f; +const float kWindowAnimation_ShowBrightnessGrayscale = 0.f; + const float kWindowAnimation_HideOpacity = 0.f; const float kWindowAnimation_ShowOpacity = 1.f; const float kWindowAnimation_TranslateFactor = -0.025f; @@ -465,6 +472,66 @@ void AnimateHideWindow_Minimize(aura::Window* window) { AddLayerAnimationsForMinimize(window, false); } +void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window, + bool show) { + window->layer()->set_delegate(window); + + float start_value, end_value; + if (show) { + start_value = kWindowAnimation_HideBrightnessGrayscale; + end_value = kWindowAnimation_ShowBrightnessGrayscale; + } else { + start_value = kWindowAnimation_ShowBrightnessGrayscale; + end_value = kWindowAnimation_HideBrightnessGrayscale; + } + + window->layer()->SetLayerBrightness(start_value); + window->layer()->SetLayerGrayscale(start_value); + if (show) { + window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); + window->layer()->SetVisible(true); + } + + ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); + settings.SetTransitionDuration( + base::TimeDelta::FromMilliseconds(kBrightnessGrayscaleFadeDurationMs)); + if (!show) + settings.AddObserver(new HidingWindowAnimationObserver(window)); + + scoped_ptr<ui::LayerAnimationSequence> brightness_sequence( + new ui::LayerAnimationSequence()); + scoped_ptr<ui::LayerAnimationSequence> grayscale_sequence( + new ui::LayerAnimationSequence()); + + brightness_sequence->AddElement( + ui::LayerAnimationElement::CreateBrightnessElement( + end_value, + base::TimeDelta::FromMilliseconds( + kBrightnessGrayscaleFadeDurationMs))); + grayscale_sequence->AddElement( + ui::LayerAnimationElement::CreateGrayscaleElement( + end_value, + base::TimeDelta::FromMilliseconds( + kBrightnessGrayscaleFadeDurationMs))); + + std::vector<ui::LayerAnimationSequence*> animations; + animations.push_back(brightness_sequence.release()); + animations.push_back(grayscale_sequence.release()); + window->layer()->GetAnimator()->ScheduleTogether(animations); + if (!show) { + window->layer()->SetOpacity(kWindowAnimation_HideOpacity); + window->layer()->SetVisible(false); + } +} + +void AnimateShowWindow_BrightnessGrayscale(aura::Window* window) { + AnimateShowHideWindowCommon_BrightnessGrayscale(window, true); +} + +void AnimateHideWindow_BrightnessGrayscale(aura::Window* window) { + AnimateShowHideWindowCommon_BrightnessGrayscale(window, false); +} + bool AnimateShowWindow(aura::Window* window) { if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_SHOW)) return false; @@ -485,6 +552,9 @@ bool AnimateShowWindow(aura::Window* window) { case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: AnimateShowWindow_Minimize(window); return true; + case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: + AnimateShowWindow_BrightnessGrayscale(window); + return true; default: NOTREACHED(); return false; @@ -511,6 +581,9 @@ bool AnimateHideWindow(aura::Window* window) { case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: AnimateHideWindow_Minimize(window); return true; + case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: + AnimateHideWindow_BrightnessGrayscale(window); + return true; default: NOTREACHED(); return false; diff --git a/ash/wm/window_animations.h b/ash/wm/window_animations.h index 9a156bf..0705143 100644 --- a/ash/wm/window_animations.h +++ b/ash/wm/window_animations.h @@ -35,6 +35,8 @@ enum WindowVisibilityAnimationType { WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE, // Inverse of SHOW. WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE, // Window scale/rotates down // to its launcher icon. + // Fade in/out using brightness and grayscale web filters. + WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE, }; // Type of visibility change transition that a window should animate. diff --git a/ash/wm/window_animations_unittest.cc b/ash/wm/window_animations_unittest.cc index 8e453dc..7768b18 100644 --- a/ash/wm/window_animations_unittest.cc +++ b/ash/wm/window_animations_unittest.cc @@ -97,6 +97,47 @@ TEST_F(WindowAnimationsTest, ShowHide) { EXPECT_FALSE(window->layer()->visible()); } +TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { + aura::Window* default_container = + ash::Shell::GetContainer( + Shell::GetPrimaryRootWindow(), + internal::kShellWindowId_DefaultContainer); + scoped_ptr<aura::Window> window( + aura::test::CreateTestWindowWithId(0, default_container)); + window->Show(); + EXPECT_TRUE(window->layer()->visible()); + + // Hiding. + SetWindowVisibilityAnimationType( + window.get(), + WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); + ash::internal::AnimateOnChildWindowVisibilityChanged( + window.get(), false); + EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); + EXPECT_FALSE(window->layer()->GetTargetVisibility()); + EXPECT_FALSE(window->layer()->visible()); + + // Showing. + SetWindowVisibilityAnimationType( + window.get(), + WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); + ash::internal::AnimateOnChildWindowVisibilityChanged( + window.get(), true); + EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); + EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); + EXPECT_TRUE(window->layer()->visible()); + + // Stays shown. + ui::AnimationContainerElement* element = + static_cast<ui::AnimationContainerElement*>( + window->layer()->GetAnimator()); + element->Step(base::TimeTicks::Now() + + base::TimeDelta::FromSeconds(5)); + EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); + EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); + EXPECT_TRUE(window->layer()->visible()); +} + TEST_F(WindowAnimationsTest, LayerTargetVisibility) { aura::Window* default_container = ash::Shell::GetContainer( |