diff options
author | aelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 03:48:35 +0000 |
---|---|---|
committer | aelias@chromium.org <aelias@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-19 03:48:35 +0000 |
commit | 6bc09e8cee1b19b45ee4cddfd1deb0a228d383d2 (patch) | |
tree | 070a0b62ccd1d1b8d65e5d11c0eae08873d9d8af /cc/animation | |
parent | 3ac1345e0f73f043933e44ca2998708a6cafa3d6 (diff) | |
download | chromium_src-6bc09e8cee1b19b45ee4cddfd1deb0a228d383d2.zip chromium_src-6bc09e8cee1b19b45ee4cddfd1deb0a228d383d2.tar.gz chromium_src-6bc09e8cee1b19b45ee4cddfd1deb0a228d383d2.tar.bz2 |
cc: Chromify ScrollbarAnimationController.
Style-only change.
Review URL: https://chromiumcodereview.appspot.com/12541024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188946 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/animation')
4 files changed, 229 insertions, 225 deletions
diff --git a/cc/animation/scrollbar_animation_controller.h b/cc/animation/scrollbar_animation_controller.h index 8c7aafe..aa106cf 100644 --- a/cc/animation/scrollbar_animation_controller.h +++ b/cc/animation/scrollbar_animation_controller.h @@ -11,22 +11,23 @@ namespace cc { -// This abstract class represents the compositor-side analogy of ScrollbarAnimator. -// Individual platforms should subclass it to provide specialized implementation. +// This abstract class represents the compositor-side analogy of +// ScrollbarAnimator. Individual platforms should subclass it to provide +// specialized implementation. class CC_EXPORT ScrollbarAnimationController { -public: - virtual ~ScrollbarAnimationController() {} + public: + virtual ~ScrollbarAnimationController() {} - virtual bool isScrollGestureInProgress() const = 0; - virtual bool isAnimating() const = 0; - virtual base::TimeDelta delayBeforeStart(base::TimeTicks now) const = 0; + virtual bool IsScrollGestureInProgress() const = 0; + virtual bool IsAnimating() const = 0; + virtual base::TimeDelta DelayBeforeStart(base::TimeTicks now) const = 0; - virtual bool animate(base::TimeTicks) = 0; - virtual void didScrollGestureBegin() = 0; - virtual void didScrollGestureEnd(base::TimeTicks now) = 0; - virtual void didProgrammaticallyUpdateScroll(base::TimeTicks now) = 0; + virtual bool Animate(base::TimeTicks now) = 0; + virtual void DidScrollGestureBegin() = 0; + virtual void DidScrollGestureEnd(base::TimeTicks now) = 0; + virtual void DidProgrammaticallyUpdateScroll(base::TimeTicks now) = 0; }; -} // namespace cc +} // namespace cc #endif // CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_H_ diff --git a/cc/animation/scrollbar_animation_controller_linear_fade.cc b/cc/animation/scrollbar_animation_controller_linear_fade.cc index 88804b8..e22207d 100644 --- a/cc/animation/scrollbar_animation_controller_linear_fade.cc +++ b/cc/animation/scrollbar_animation_controller_linear_fade.cc @@ -9,86 +9,87 @@ namespace cc { -scoped_ptr<ScrollbarAnimationControllerLinearFade> ScrollbarAnimationControllerLinearFade::create(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength) -{ - return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(scrollLayer, fadeoutDelay, fadeoutLength)); +scoped_ptr<ScrollbarAnimationControllerLinearFade> +ScrollbarAnimationControllerLinearFade::Create(LayerImpl* scroll_layer, + base::TimeDelta fadeout_delay, + base::TimeDelta fadeout_length) { + return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade( + scroll_layer, fadeout_delay, fadeout_length)); } -ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength) - : ScrollbarAnimationController() - , m_scrollLayer(scrollLayer) - , m_scrollGestureInProgress(false) - , m_fadeoutDelay(fadeoutDelay) - , m_fadeoutLength(fadeoutLength) -{ +ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade( + LayerImpl* scroll_layer, + base::TimeDelta fadeout_delay, + base::TimeDelta fadeout_length) + : ScrollbarAnimationController(), + scroll_layer_(scroll_layer), + scroll_gesture_in_progress_(false), + fadeout_delay_(fadeout_delay), + fadeout_length_(fadeout_length) {} + +ScrollbarAnimationControllerLinearFade:: + ~ScrollbarAnimationControllerLinearFade() {} + +bool ScrollbarAnimationControllerLinearFade::IsScrollGestureInProgress() const { + return scroll_gesture_in_progress_; } -ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade() -{ +bool ScrollbarAnimationControllerLinearFade::IsAnimating() const { + return !last_awaken_time_.is_null(); } -bool ScrollbarAnimationControllerLinearFade::isScrollGestureInProgress() const -{ - return m_scrollGestureInProgress; +base::TimeDelta ScrollbarAnimationControllerLinearFade::DelayBeforeStart( + base::TimeTicks now) const { + if (now > last_awaken_time_ + fadeout_delay_) + return base::TimeDelta(); + return fadeout_delay_ - (now - last_awaken_time_); } -bool ScrollbarAnimationControllerLinearFade::isAnimating() const -{ - return !m_lastAwakenTime.is_null(); +bool ScrollbarAnimationControllerLinearFade::Animate(base::TimeTicks now) { + float opacity = OpacityAtTime(now); + scroll_layer_->SetScrollbarOpacity(opacity); + if (!opacity) + last_awaken_time_ = base::TimeTicks(); + return IsAnimating() && DelayBeforeStart(now) == base::TimeDelta(); } -base::TimeDelta ScrollbarAnimationControllerLinearFade::delayBeforeStart(base::TimeTicks now) const -{ - if (now > m_lastAwakenTime + m_fadeoutDelay) - return base::TimeDelta(); - return m_fadeoutDelay - (now - m_lastAwakenTime); +void ScrollbarAnimationControllerLinearFade::DidScrollGestureBegin() { + scroll_layer_->SetScrollbarOpacity(1.0f); + scroll_gesture_in_progress_ = true; + last_awaken_time_ = base::TimeTicks(); } -bool ScrollbarAnimationControllerLinearFade::animate(base::TimeTicks now) -{ - float opacity = opacityAtTime(now); - m_scrollLayer->SetScrollbarOpacity(opacity); - if (!opacity) - m_lastAwakenTime = base::TimeTicks(); - return isAnimating() && delayBeforeStart(now) == base::TimeDelta(); +void ScrollbarAnimationControllerLinearFade::DidScrollGestureEnd( + base::TimeTicks now) { + scroll_gesture_in_progress_ = false; + last_awaken_time_ = now; } -void ScrollbarAnimationControllerLinearFade::didScrollGestureBegin() -{ - m_scrollLayer->SetScrollbarOpacity(1); - m_scrollGestureInProgress = true; - m_lastAwakenTime = base::TimeTicks(); +void ScrollbarAnimationControllerLinearFade::DidProgrammaticallyUpdateScroll( + base::TimeTicks now) { + // Don't set scroll_gesture_in_progress_ as this scroll is not from a gesture + // and we won't receive ScrollEnd. + scroll_layer_->SetScrollbarOpacity(1.0f); + last_awaken_time_ = now; } -void ScrollbarAnimationControllerLinearFade::didScrollGestureEnd(base::TimeTicks now) -{ - m_scrollGestureInProgress = false; - m_lastAwakenTime = now; -} - -void ScrollbarAnimationControllerLinearFade::didProgrammaticallyUpdateScroll(base::TimeTicks now) -{ - // Don't set m_scrollGestureInProgress as this scroll is not from a gesture - // and we won't receive ScrollEnd. - m_scrollLayer->SetScrollbarOpacity(1); - m_lastAwakenTime = now; -} - -float ScrollbarAnimationControllerLinearFade::opacityAtTime(base::TimeTicks now) -{ - if (m_scrollGestureInProgress) - return 1; +float ScrollbarAnimationControllerLinearFade::OpacityAtTime( + base::TimeTicks now) { + if (scroll_gesture_in_progress_) + return 1.0f; - if (m_lastAwakenTime.is_null()) - return 0; + if (last_awaken_time_.is_null()) + return 0.0f; - base::TimeDelta delta = now - m_lastAwakenTime; + base::TimeDelta delta = now - last_awaken_time_; - if (delta <= m_fadeoutDelay) - return 1; - if (delta < m_fadeoutDelay + m_fadeoutLength) - return (m_fadeoutDelay + m_fadeoutLength - delta).InSecondsF() / m_fadeoutLength.InSecondsF(); - return 0; + if (delta <= fadeout_delay_) + return 1.0f; + if (delta < fadeout_delay_ + fadeout_length_) { + return (fadeout_delay_ + fadeout_length_ - delta).InSecondsF() / + fadeout_length_.InSecondsF(); + } + return 0.0f; } } // namespace cc diff --git a/cc/animation/scrollbar_animation_controller_linear_fade.h b/cc/animation/scrollbar_animation_controller_linear_fade.h index a126306..19a94d8 100644 --- a/cc/animation/scrollbar_animation_controller_linear_fade.h +++ b/cc/animation/scrollbar_animation_controller_linear_fade.h @@ -12,39 +12,43 @@ namespace cc { class LayerImpl; -class CC_EXPORT ScrollbarAnimationControllerLinearFade : public ScrollbarAnimationController { -public: - static scoped_ptr<ScrollbarAnimationControllerLinearFade> create(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength); +class CC_EXPORT ScrollbarAnimationControllerLinearFade : + public ScrollbarAnimationController { + public: + static scoped_ptr<ScrollbarAnimationControllerLinearFade> Create( + LayerImpl* scroll_layer, + base::TimeDelta fadeout_delay, + base::TimeDelta fadeout_length); - virtual ~ScrollbarAnimationControllerLinearFade(); + virtual ~ScrollbarAnimationControllerLinearFade(); - // ScrollbarAnimationController overrides. - virtual bool isScrollGestureInProgress() const OVERRIDE; - virtual bool isAnimating() const OVERRIDE; - virtual base::TimeDelta delayBeforeStart(base::TimeTicks now) const OVERRIDE; + // ScrollbarAnimationController overrides. + virtual bool IsScrollGestureInProgress() const OVERRIDE; + virtual bool IsAnimating() const OVERRIDE; + virtual base::TimeDelta DelayBeforeStart(base::TimeTicks now) const OVERRIDE; - virtual bool animate(base::TimeTicks) OVERRIDE; - virtual void didScrollGestureBegin() OVERRIDE; - virtual void didScrollGestureEnd(base::TimeTicks now) OVERRIDE; - virtual void didProgrammaticallyUpdateScroll(base::TimeTicks now) OVERRIDE; + virtual bool Animate(base::TimeTicks now) OVERRIDE; + virtual void DidScrollGestureBegin() OVERRIDE; + virtual void DidScrollGestureEnd(base::TimeTicks now) OVERRIDE; + virtual void DidProgrammaticallyUpdateScroll(base::TimeTicks now) OVERRIDE; -protected: - ScrollbarAnimationControllerLinearFade(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLength); + protected: + ScrollbarAnimationControllerLinearFade(LayerImpl* scroll_layer, + base::TimeDelta fadeout_delay, + base::TimeDelta fadeout_length); -private: - float opacityAtTime(base::TimeTicks); + private: + float OpacityAtTime(base::TimeTicks now); - LayerImpl* m_scrollLayer; + LayerImpl* scroll_layer_; - base::TimeTicks m_lastAwakenTime; - bool m_scrollGestureInProgress; + base::TimeTicks last_awaken_time_; + bool scroll_gesture_in_progress_; - base::TimeDelta m_fadeoutDelay; - base::TimeDelta m_fadeoutLength; - - double m_currentTimeForTesting; + base::TimeDelta fadeout_delay_; + base::TimeDelta fadeout_length_; }; -} // namespace cc +} // namespace cc #endif // CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_LINEAR_FADE_H_ diff --git a/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc b/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc index ca92b70..b791f39 100644 --- a/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc +++ b/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc @@ -15,153 +15,151 @@ namespace cc { namespace { class ScrollbarAnimationControllerLinearFadeTest : public testing::Test { -public: - ScrollbarAnimationControllerLinearFadeTest() - : m_hostImpl(&m_proxy) - { - } - -protected: - virtual void SetUp() - { - m_scrollLayer = LayerImpl::Create(m_hostImpl.active_tree(), 1); - scoped_ptr<ScrollbarGeometryFixedThumb> geometry(ScrollbarGeometryFixedThumb::create(FakeWebScrollbarThemeGeometry::create(false))); - m_scrollbarLayer = ScrollbarLayerImpl::Create(m_hostImpl.active_tree(), 2, geometry.Pass()); - - m_scrollLayer->SetMaxScrollOffset(gfx::Vector2d(50, 50)); - m_scrollLayer->SetBounds(gfx::Size(50, 50)); - m_scrollLayer->SetHorizontalScrollbarLayer(m_scrollbarLayer.get()); - - m_scrollbarController = ScrollbarAnimationControllerLinearFade::create(m_scrollLayer.get(), base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(3)); - } - - FakeImplProxy m_proxy; - FakeLayerTreeHostImpl m_hostImpl; - scoped_ptr<ScrollbarAnimationControllerLinearFade> m_scrollbarController; - scoped_ptr<LayerImpl> m_scrollLayer; - scoped_ptr<ScrollbarLayerImpl> m_scrollbarLayer; - + public: + ScrollbarAnimationControllerLinearFadeTest() : host_impl_(&proxy_) {} + + protected: + virtual void SetUp() { + scroll_layer_ = LayerImpl::Create(host_impl_.active_tree(), 1); + scoped_ptr<ScrollbarGeometryFixedThumb> geometry( + ScrollbarGeometryFixedThumb::create( + FakeWebScrollbarThemeGeometry::create(false))); + scrollbar_layer_ = ScrollbarLayerImpl::Create( + host_impl_.active_tree(), 2, geometry.Pass()); + + scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(50, 50)); + scroll_layer_->SetBounds(gfx::Size(50, 50)); + scroll_layer_->SetHorizontalScrollbarLayer(scrollbar_layer_.get()); + + scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create( + scroll_layer_.get(), + base::TimeDelta::FromSeconds(2), + base::TimeDelta::FromSeconds(3)); + } + + FakeImplProxy proxy_; + FakeLayerTreeHostImpl host_impl_; + scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; + scoped_ptr<LayerImpl> scroll_layer_; + scoped_ptr<ScrollbarLayerImpl> scrollbar_layer_; }; -TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyHiddenInBegin) -{ - m_scrollbarController->animate(base::TimeTicks()); - EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); +TEST_F(ScrollbarAnimationControllerLinearFadeTest, HiddenInBegin) { + scrollbar_controller_->Animate(base::TimeTicks()); + EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); } -TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScrollGesture) -{ - base::TimeTicks time; - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->didScrollGestureBegin(); - EXPECT_TRUE(m_scrollbarController->isScrollGestureInProgress()); - EXPECT_FALSE(m_scrollbarController->isAnimating()); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); +TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollGesture) { + base::TimeTicks time; + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->DidScrollGestureBegin(); + EXPECT_TRUE(scrollbar_controller_->IsScrollGestureInProgress()); + EXPECT_FALSE(scrollbar_controller_->IsAnimating()); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(100); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); - m_scrollbarController->didScrollGestureEnd(time); + time += base::TimeDelta::FromSeconds(100); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); + scrollbar_controller_->DidScrollGestureEnd(time); - EXPECT_FALSE(m_scrollbarController->isScrollGestureInProgress()); - EXPECT_TRUE(m_scrollbarController->isAnimating()); - EXPECT_EQ(2, m_scrollbarController->delayBeforeStart(time).InSeconds()); + EXPECT_FALSE(scrollbar_controller_->IsScrollGestureInProgress()); + EXPECT_TRUE(scrollbar_controller_->IsAnimating()); + EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); + time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->didScrollGestureBegin(); - m_scrollbarController->didScrollGestureEnd(time); + scrollbar_controller_->DidScrollGestureBegin(); + scrollbar_controller_->DidScrollGestureEnd(time); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); } -TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByProgrammaticScroll) -{ - base::TimeTicks time; - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->didProgrammaticallyUpdateScroll(time); - EXPECT_FALSE(m_scrollbarController->isScrollGestureInProgress()); - EXPECT_TRUE(m_scrollbarController->isAnimating()); - EXPECT_EQ(2, m_scrollbarController->delayBeforeStart(time).InSeconds()); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); - m_scrollbarController->didProgrammaticallyUpdateScroll(time); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->didProgrammaticallyUpdateScroll(time); - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); - - time += base::TimeDelta::FromSeconds(1); - m_scrollbarController->animate(time); - EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); +TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByProgrammaticScroll) { + base::TimeTicks time; + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->DidProgrammaticallyUpdateScroll(time); + EXPECT_FALSE(scrollbar_controller_->IsScrollGestureInProgress()); + EXPECT_TRUE(scrollbar_controller_->IsAnimating()); + EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds()); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); + scrollbar_controller_->DidProgrammaticallyUpdateScroll(time); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->DidProgrammaticallyUpdateScroll(time); + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); + + time += base::TimeDelta::FromSeconds(1); + scrollbar_controller_->Animate(time); + EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); } } // namespace |