summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorloyso <loyso@chromium.org>2016-01-07 20:27:38 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-08 04:29:33 +0000
commit8b876b75f69ae160847db39840784b3805c504a9 (patch)
tree2d8674c47d7c028b540a3eb1578c7bdd7e35db39
parent1000321a7949e79a9a64dcd70b78698deafd726d (diff)
downloadchromium_src-8b876b75f69ae160847db39840784b3805c504a9.zip
chromium_src-8b876b75f69ae160847db39840784b3805c504a9.tar.gz
chromium_src-8b876b75f69ae160847db39840784b3805c504a9.tar.bz2
CC Animation: Renaming and simplification in TopControlsManager.
1) TopControlsManager::animation must return bool (for the sake of encapsulation) 2) TopControlsManager::IsAnimationCompletedAtTime can be simplified. BUG=394777 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1569173002 Cr-Commit-Position: refs/heads/master@{#368272}
-rw-r--r--cc/input/top_controls_manager.cc21
-rw-r--r--cc/input/top_controls_manager.h6
-rw-r--r--cc/input/top_controls_manager_unittest.cc70
-rw-r--r--cc/trees/layer_tree_host_impl.cc4
-rw-r--r--cc/trees/layer_tree_host_impl_unittest.cc14
5 files changed, 52 insertions, 63 deletions
diff --git a/cc/input/top_controls_manager.cc b/cc/input/top_controls_manager.cc
index 6547f20..44ed920 100644
--- a/cc/input/top_controls_manager.cc
+++ b/cc/input/top_controls_manager.cc
@@ -161,10 +161,10 @@ gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) {
base::TimeDelta time = monotonic_time - base::TimeTicks();
float old_offset = ContentTopOffset();
- client_->SetCurrentTopControlsShownRatio(
- top_controls_animation_->GetValue(time));
+ float new_ratio = top_controls_animation_->GetValue(time);
+ client_->SetCurrentTopControlsShownRatio(new_ratio);
- if (IsAnimationCompleteAtTime(monotonic_time))
+ if (IsAnimationComplete(new_ratio))
ResetAnimations();
gfx::Vector2dF scroll_delta(0.f, ContentTopOffset() - old_offset);
@@ -222,18 +222,9 @@ void TopControlsManager::StartAnimationIfNecessary() {
}
}
-bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) {
- if (!top_controls_animation_)
- return true;
-
- base::TimeDelta animation_time = time - base::TimeTicks();
- float new_ratio = top_controls_animation_->GetValue(animation_time);
-
- if ((animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) ||
- (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f)) {
- return true;
- }
- return false;
+bool TopControlsManager::IsAnimationComplete(float new_ratio) {
+ return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) ||
+ (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f);
}
void TopControlsManager::ResetBaseline() {
diff --git a/cc/input/top_controls_manager.h b/cc/input/top_controls_manager.h
index 8cd7c29..0ae1818 100644
--- a/cc/input/top_controls_manager.h
+++ b/cc/input/top_controls_manager.h
@@ -44,9 +44,7 @@ class CC_EXPORT TopControlsManager
float TopControlsShownRatio() const;
float TopControlsHeight() const;
- KeyframedFloatAnimationCurve* animation() {
- return top_controls_animation_.get();
- }
+ bool has_animation() const { return top_controls_animation_; }
AnimationDirection animation_direction() { return animation_direction_; }
void UpdateTopControlsState(TopControlsState constraints,
@@ -75,7 +73,7 @@ class CC_EXPORT TopControlsManager
void ResetAnimations();
void SetupAnimation(AnimationDirection direction);
void StartAnimationIfNecessary();
- bool IsAnimationCompleteAtTime(base::TimeTicks time);
+ bool IsAnimationComplete(float new_ratio);
void ResetBaseline();
TopControlsManagerClient* client_; // The client manages the lifecycle of
diff --git a/cc/input/top_controls_manager_unittest.cc b/cc/input/top_controls_manager_unittest.cc
index 0d62a3c..b2ee9bf 100644
--- a/cc/input/top_controls_manager_unittest.cc
+++ b/cc/input/top_controls_manager_unittest.cc
@@ -158,17 +158,17 @@ TEST(TopControlsManagerTest, PartialShownHideAnimation) {
EXPECT_FLOAT_EQ(15.f, manager->ContentTopOffset());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous;
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_LT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(-100.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
}
@@ -188,17 +188,17 @@ TEST(TopControlsManagerTest, PartialShownShowAnimation) {
EXPECT_FLOAT_EQ(70.f, manager->ContentTopOffset());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous;
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_GT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(100.f, manager->ContentTopOffset());
}
@@ -214,17 +214,17 @@ TEST(TopControlsManagerTest, PartialHiddenWithAmbiguousThresholdShows) {
EXPECT_FLOAT_EQ(80.f, manager->ContentTopOffset());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous;
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_GT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(100.f, manager->ContentTopOffset());
}
@@ -240,17 +240,17 @@ TEST(TopControlsManagerTest, PartialHiddenWithAmbiguousThresholdHides) {
EXPECT_FLOAT_EQ(70.f, manager->ContentTopOffset());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous;
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_LT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(-100.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
}
@@ -270,17 +270,17 @@ TEST(TopControlsManagerTest, PartialShownWithAmbiguousThresholdHides) {
EXPECT_FLOAT_EQ(20.f, manager->ContentTopOffset());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous;
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_LT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(-100.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
}
@@ -300,17 +300,17 @@ TEST(TopControlsManagerTest, PartialShownWithAmbiguousThresholdShows) {
EXPECT_FLOAT_EQ(30.f, manager->ContentTopOffset());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous;
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_GT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(100.f, manager->ContentTopOffset());
}
@@ -341,7 +341,7 @@ TEST(TopControlsManagerTest, PinchIgnoresScroll) {
EXPECT_FLOAT_EQ(15.f, manager->ContentTopOffset());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
}
TEST(TopControlsManagerTest, PinchBeginStartsAnimationIfNecessary) {
@@ -353,47 +353,47 @@ TEST(TopControlsManagerTest, PinchBeginStartsAnimationIfNecessary) {
EXPECT_FLOAT_EQ(-100.f, manager->ControlsTopOffset());
manager->PinchBegin();
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
manager->PinchEnd();
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
manager->ScrollBy(gfx::Vector2dF(0.f, -15.f));
EXPECT_FLOAT_EQ(-85.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(15.f, manager->ContentTopOffset());
manager->PinchBegin();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous;
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_LT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
manager->PinchEnd();
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
manager->ScrollBy(gfx::Vector2dF(0.f, -55.f));
EXPECT_FLOAT_EQ(-45.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(55.f, manager->ContentTopOffset());
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
manager->ScrollEnd();
- EXPECT_TRUE(manager->animation());
+ EXPECT_TRUE(manager->has_animation());
time = base::TimeTicks::Now();
- while (manager->animation()) {
+ while (manager->has_animation()) {
previous = manager->TopControlsShownRatio();
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_GT(manager->TopControlsShownRatio(), previous);
}
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
}
@@ -404,12 +404,12 @@ TEST(TopControlsManagerTest, HeightChangeMaintainsFullyVisibleControls) {
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
client.SetTopControlsHeight(100.f);
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(100.f, manager->TopControlsHeight());
EXPECT_FLOAT_EQ(0, manager->ControlsTopOffset());
client.SetTopControlsHeight(50.f);
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(50.f, manager->TopControlsHeight());
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
}
@@ -423,12 +423,12 @@ TEST(TopControlsManagerTest, GrowingHeightKeepsTopControlsHidden) {
EXPECT_EQ(0.f, manager->ContentTopOffset());
client.SetTopControlsHeight(50.f);
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_EQ(-50.f, manager->ControlsTopOffset());
EXPECT_EQ(0.f, manager->ContentTopOffset());
client.SetTopControlsHeight(100.f);
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_EQ(-100.f, manager->ControlsTopOffset());
EXPECT_EQ(0.f, manager->ContentTopOffset());
}
@@ -444,12 +444,12 @@ TEST(TopControlsManagerTest, ShrinkingHeightKeepsTopControlsHidden) {
manager->ScrollEnd();
client.SetTopControlsHeight(50.f);
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(-50.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
client.SetTopControlsHeight(0.f);
- EXPECT_FALSE(manager->animation());
+ EXPECT_FALSE(manager->has_animation());
EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
}
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 4ff964e..c12e299 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -3173,12 +3173,12 @@ bool LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) {
}
bool LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) {
- if (!top_controls_manager_->animation())
+ if (!top_controls_manager_->has_animation())
return false;
gfx::Vector2dF scroll = top_controls_manager_->Animate(time);
- if (top_controls_manager_->animation())
+ if (top_controls_manager_->has_animation())
SetNeedsOneBeginImplFrame();
if (active_tree_->TotalScrollOffset().y() == 0.f)
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index 1d422e8..4c39390 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -7976,7 +7976,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) {
// End the scroll while the controls are still offset from their limit.
host_impl_->ScrollEnd();
- ASSERT_TRUE(host_impl_->top_controls_manager()->animation());
+ ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation());
EXPECT_TRUE(did_request_next_frame_);
EXPECT_TRUE(did_request_redraw_);
EXPECT_FALSE(did_request_commit_);
@@ -8010,12 +8010,12 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) {
EXPECT_TRUE(did_request_redraw_);
if (new_offset != 0) {
- EXPECT_TRUE(host_impl_->top_controls_manager()->animation());
+ EXPECT_TRUE(host_impl_->top_controls_manager()->has_animation());
EXPECT_TRUE(did_request_next_frame_);
}
host_impl_->DidFinishImplFrame();
}
- EXPECT_FALSE(host_impl_->top_controls_manager()->animation());
+ EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation());
}
TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) {
@@ -8050,7 +8050,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) {
// End the scroll while the controls are still offset from the limit.
host_impl_->ScrollEnd();
- ASSERT_TRUE(host_impl_->top_controls_manager()->animation());
+ ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation());
EXPECT_TRUE(did_request_next_frame_);
EXPECT_TRUE(did_request_redraw_);
EXPECT_FALSE(did_request_commit_);
@@ -8079,7 +8079,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) {
}
host_impl_->DidFinishImplFrame();
}
- EXPECT_FALSE(host_impl_->top_controls_manager()->animation());
+ EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation());
EXPECT_EQ(-top_controls_height_,
host_impl_->top_controls_manager()->ControlsTopOffset());
}
@@ -8117,7 +8117,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest,
// End the fling while the controls are still offset from the limit.
host_impl_->MainThreadHasStoppedFlinging();
- ASSERT_TRUE(host_impl_->top_controls_manager()->animation());
+ ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation());
EXPECT_TRUE(did_request_next_frame_);
EXPECT_TRUE(did_request_redraw_);
EXPECT_FALSE(did_request_commit_);
@@ -8144,7 +8144,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest,
}
host_impl_->DidFinishImplFrame();
}
- EXPECT_FALSE(host_impl_->top_controls_manager()->animation());
+ EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation());
EXPECT_EQ(-top_controls_height_,
host_impl_->top_controls_manager()->ControlsTopOffset());
}