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/wm | |
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/wm')
-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 |
3 files changed, 116 insertions, 0 deletions
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( |