Chromium Code Reviews| Index: athena/home/home_card_gesture_manager.cc |
| diff --git a/athena/home/home_card_gesture_manager.cc b/athena/home/home_card_gesture_manager.cc |
| index 9d53e3500889ac2218329ddd2937af6ed8396023..cc7ee829d2431959fe8db6b7187ec3fd12d2a4da 100644 |
| --- a/athena/home/home_card_gesture_manager.cc |
| +++ b/athena/home/home_card_gesture_manager.cc |
| @@ -9,9 +9,31 @@ |
| namespace athena { |
| +namespace { |
| + |
| +// The additional height to the minimized home. If the currently estimated |
| +// height is smaller than this buffer, it is considered as the minimized state. |
| +const int kMinimizedHomeBufferSize = 50; |
|
pkotwicz
2014/09/18 21:11:50
This might be slightly clearer:
// The maximum he
Jun Mukai
2014/09/18 21:57:29
Done.
|
| + |
| +// Same as |kMinimizedHomeBufferSize| but this value is used when the original |
| +// state is centered. |
| +const int kMinimizedHomeBufferSizeForCentered = 90; |
| + |
| +// The height boundary between the bottom state and the centereed state. If |
| +// the currently estimated height is bigger than this, it is considered as the |
| +// centered state. Otherwise, it's bottom (or minimized if it's too way small). |
| +// This value is the rate to the actual screen height. |
| +const float kBottomBoundaryRate = 0.5f; |
| + |
| +// Same as |kBottomBoundaryRate| but used when the original state is minimized. |
| +const float kBottomBoundaryRateForMinimized = 0.3f; |
| + |
| +} |
| + |
| HomeCardGestureManager::HomeCardGestureManager(Delegate* delegate, |
| const gfx::Rect& screen_bounds) |
| : delegate_(delegate), |
| + original_state_(HomeCard::HIDDEN), |
| y_offset_(0), |
| last_estimated_height_(0), |
| screen_bounds_(screen_bounds) {} |
| @@ -22,6 +44,8 @@ void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { |
| switch (event->type()) { |
| case ui::ET_GESTURE_SCROLL_BEGIN: |
| y_offset_ = event->location().y(); |
| + original_state_ = HomeCard::Get()->GetState(); |
| + DCHECK_NE(HomeCard::HIDDEN, original_state_); |
| event->SetHandled(); |
| break; |
| case ui::ET_GESTURE_SCROLL_END: |
| @@ -35,7 +59,17 @@ void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { |
| const ui::GestureEventDetails& details = event->details(); |
| const float kFlingCompletionVelocity = 100.0f; |
| HomeCard::State final_state = GetClosestState(); |
| - if (::fabs(details.velocity_y()) > kFlingCompletionVelocity) { |
| + |
| + // When the scroll updates don't move enough to switch to another states |
|
pkotwicz
2014/09/18 21:11:50
How about: "When the user does not drag far enough
Jun Mukai
2014/09/18 21:57:29
Done.
|
| + // but a fling happens at the end of a gesture, it should change the state |
| + // in the direction to the fling velocity. |
| + // This check of |final_state| and |original_state_| may cause unexpected |
| + // results for some gestures, such like swipe up from minimized state -> |
| + // move up to full screen -> fling down there. This type of gestures are |
| + // considered rare. |
| + // TODO(mukai): consider such case once reported. |
| + if (final_state == original_state_ && |
| + ::fabs(details.velocity_y()) > kFlingCompletionVelocity) { |
| if (details.velocity_y() > 0) { |
| final_state = std::min(HomeCard::VISIBLE_MINIMIZED, |
| static_cast<HomeCard::State>(final_state + 1)); |
| @@ -54,17 +88,18 @@ void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { |
| } |
| HomeCard::State HomeCardGestureManager::GetClosestState() const { |
|
pkotwicz
2014/09/18 21:11:50
GetFinalState() is probably a better name
Jun Mukai
2014/09/18 21:57:29
Done.
|
| - const int kMinimizedHomeBufferSize = 50; |
| - if (last_estimated_height_ <= |
| - kHomeCardMinimizedHeight + kMinimizedHomeBufferSize) { |
| + int buffer = (original_state_ == HomeCard::VISIBLE_CENTERED) |
| + ? kMinimizedHomeBufferSizeForCentered |
| + : kMinimizedHomeBufferSize; |
| + if (last_estimated_height_ < kHomeCardMinimizedHeight + buffer) |
| return HomeCard::VISIBLE_MINIMIZED; |
| - } |
| - int centered_height = screen_bounds_.height(); |
| - if (last_estimated_height_ - kHomeCardHeight <= |
| - (centered_height - kHomeCardHeight) / 3) { |
| + float multiplier = (original_state_ == HomeCard::VISIBLE_MINIMIZED) |
| + ? kBottomBoundaryRateForMinimized |
| + : kBottomBoundaryRate; |
| + if (last_estimated_height_ < screen_bounds_.height() * multiplier) |
| return HomeCard::VISIBLE_BOTTOM; |
| - } |
| + |
| return HomeCard::VISIBLE_CENTERED; |
| } |