Chromium Code Reviews| Index: cc/input/top_controls_manager.cc |
| diff --git a/cc/input/top_controls_manager.cc b/cc/input/top_controls_manager.cc |
| index 02a015246452ba5ecd83c30c4bfcb5e50540bd1b..981095b63aa66281383b1fe6179ef4949f43e29e 100644 |
| --- a/cc/input/top_controls_manager.cc |
| +++ b/cc/input/top_controls_manager.cc |
| @@ -40,7 +40,7 @@ TopControlsManager::TopControlsManager(TopControlsManagerClient* client, |
| float top_controls_hide_threshold) |
| : client_(client), |
| animation_direction_(NO_ANIMATION), |
| - visibility_restriction_(NONE), |
| + permitted_state_(BOTH), |
| controls_top_offset_(0.f), |
| top_controls_height_(top_controls_height), |
| current_scroll_delta_(0.f), |
| @@ -55,31 +55,36 @@ TopControlsManager::TopControlsManager(TopControlsManagerClient* client, |
| TopControlsManager::~TopControlsManager() { |
| } |
| -void TopControlsManager::UpdateTopControlsState(bool enable_hiding, |
| - bool enable_showing, |
| +void TopControlsManager::UpdateTopControlsState(TopControlsState constraints, |
| + TopControlsState current, |
| bool animate) { |
| - float final_controls_position = 0.f; |
| - |
| - if (enable_hiding && enable_showing) { |
| - visibility_restriction_ = NONE; |
| - } else if (enable_showing || !enable_hiding) { |
| - visibility_restriction_ = ALWAYS_SHOWN; |
| - } else { |
| - visibility_restriction_ = ALWAYS_HIDDEN; |
| - final_controls_position = -top_controls_height_; |
| + if (constraints == SHOWN) { |
| + DCHECK(current != HIDDEN); |
|
aelias_OOO_until_Jul13
2013/05/02 18:44:23
Nit, formulate it as:
DCHECK(!(constraints == SHO
Michael van Ouwerkerk
2013/05/08 16:21:15
Done.
|
| + } else if (constraints == HIDDEN) { |
| + DCHECK(current != SHOWN); |
| } |
| - if (visibility_restriction_ != NONE && |
| - final_controls_position != controls_top_offset_) { |
| - ResetAnimations(); |
| + permitted_state_ = constraints; |
| + |
| + // Don't do anything if it doesn't matter which state the controls are in. |
| + if (constraints == BOTH && current == BOTH) return; |
|
aelias_OOO_until_Jul13
2013/05/02 18:44:23
Style: return on next line
Michael van Ouwerkerk
2013/05/08 16:21:15
Done.
|
| + |
| + ResetAnimations(); |
| + if (constraints == SHOWN || current == SHOWN) { |
| + if (animate) { |
| + SetupAnimation(SHOWING_CONTROLS); |
| + } else { |
| + controls_top_offset_ = 0.f; |
| + } |
| + } |
| + if (constraints == HIDDEN || current == HIDDEN) { |
| if (animate) { |
| - SetupAnimation(visibility_restriction_ == ALWAYS_SHOWN ? |
| - SHOWING_CONTROLS : HIDING_CONTROLS); |
| + SetupAnimation(HIDING_CONTROLS); |
| } else { |
| - controls_top_offset_ = final_controls_position; |
| + controls_top_offset_ = -top_controls_height_; |
| } |
| - client_->DidChangeTopControlsPosition(); |
| } |
| + client_->DidChangeTopControlsPosition(); |
|
aelias_OOO_until_Jul13
2013/05/02 18:44:23
Please track the old value of controls_top_offset_
Michael van Ouwerkerk
2013/05/08 16:21:15
Done.
|
| } |
| void TopControlsManager::ScrollBegin() { |
| @@ -90,9 +95,9 @@ void TopControlsManager::ScrollBegin() { |
| gfx::Vector2dF TopControlsManager::ScrollBy( |
| const gfx::Vector2dF pending_delta) { |
| - if (visibility_restriction_ == ALWAYS_SHOWN && pending_delta.y() > 0) |
| + if (permitted_state_ == SHOWN && pending_delta.y() > 0) |
| return pending_delta; |
| - else if (visibility_restriction_ == ALWAYS_HIDDEN && pending_delta.y() < 0) |
| + else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) |
| return pending_delta; |
| current_scroll_delta_ += pending_delta.y(); |
| @@ -153,6 +158,19 @@ void TopControlsManager::ResetAnimations() { |
| } |
| void TopControlsManager::SetupAnimation(AnimationDirection direction) { |
| + DCHECK(direction != NO_ANIMATION); |
| + |
| + if (direction == SHOWING_CONTROLS && controls_top_offset_ == 0) |
| + return; |
| + |
| + if (direction == HIDING_CONTROLS && |
| + controls_top_offset_ == -top_controls_height_) { |
| + return; |
| + } |
| + |
| + if (top_controls_animation_ && animation_direction_ == direction) |
| + return; |
| + |
| top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); |
| double start_time = |
| (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); |
| @@ -166,6 +184,7 @@ void TopControlsManager::SetupAnimation(AnimationDirection direction) { |
| controls_top_offset_ + max_ending_offset, |
| EaseTimingFunction::Create())); |
| animation_direction_ = direction; |
| + client_->DidChangeTopControlsPosition(); |
| } |
| void TopControlsManager::StartAnimationIfNecessary() { |
| @@ -187,11 +206,8 @@ void TopControlsManager::StartAnimationIfNecessary() { |
| SHOWING_CONTROLS : HIDING_CONTROLS; |
| } |
| - if (show_controls != NO_ANIMATION && |
| - (!top_controls_animation_ || animation_direction_ != show_controls)) { |
| + if (show_controls != NO_ANIMATION) |
| SetupAnimation(show_controls); |
| - client_->DidChangeTopControlsPosition(); |
| - } |
| } |
| } |