Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "athena/home/home_card_gesture_manager.h" | 5 #include "athena/home/home_card_gesture_manager.h" |
| 6 | 6 |
| 7 #include "athena/home/home_card_constants.h" | 7 #include "athena/home/home_card_constants.h" |
| 8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
| 9 | 9 |
| 10 namespace athena { | 10 namespace athena { |
| 11 | 11 |
| 12 namespace { | |
| 13 | |
| 14 // The additional height to the minimized home. If the currently estimated | |
| 15 // height is smaller than this buffer, it is considered as the minimized state. | |
| 16 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.
| |
| 17 | |
| 18 // Same as |kMinimizedHomeBufferSize| but this value is used when the original | |
| 19 // state is centered. | |
| 20 const int kMinimizedHomeBufferSizeForCentered = 90; | |
| 21 | |
| 22 // The height boundary between the bottom state and the centereed state. If | |
| 23 // the currently estimated height is bigger than this, it is considered as the | |
| 24 // centered state. Otherwise, it's bottom (or minimized if it's too way small). | |
| 25 // This value is the rate to the actual screen height. | |
| 26 const float kBottomBoundaryRate = 0.5f; | |
| 27 | |
| 28 // Same as |kBottomBoundaryRate| but used when the original state is minimized. | |
| 29 const float kBottomBoundaryRateForMinimized = 0.3f; | |
| 30 | |
| 31 } | |
| 32 | |
| 12 HomeCardGestureManager::HomeCardGestureManager(Delegate* delegate, | 33 HomeCardGestureManager::HomeCardGestureManager(Delegate* delegate, |
| 13 const gfx::Rect& screen_bounds) | 34 const gfx::Rect& screen_bounds) |
| 14 : delegate_(delegate), | 35 : delegate_(delegate), |
| 36 original_state_(HomeCard::HIDDEN), | |
| 15 y_offset_(0), | 37 y_offset_(0), |
| 16 last_estimated_height_(0), | 38 last_estimated_height_(0), |
| 17 screen_bounds_(screen_bounds) {} | 39 screen_bounds_(screen_bounds) {} |
| 18 | 40 |
| 19 HomeCardGestureManager::~HomeCardGestureManager() {} | 41 HomeCardGestureManager::~HomeCardGestureManager() {} |
| 20 | 42 |
| 21 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { | 43 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { |
| 22 switch (event->type()) { | 44 switch (event->type()) { |
| 23 case ui::ET_GESTURE_SCROLL_BEGIN: | 45 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 24 y_offset_ = event->location().y(); | 46 y_offset_ = event->location().y(); |
| 47 original_state_ = HomeCard::Get()->GetState(); | |
| 48 DCHECK_NE(HomeCard::HIDDEN, original_state_); | |
| 25 event->SetHandled(); | 49 event->SetHandled(); |
| 26 break; | 50 break; |
| 27 case ui::ET_GESTURE_SCROLL_END: | 51 case ui::ET_GESTURE_SCROLL_END: |
| 28 event->SetHandled(); | 52 event->SetHandled(); |
| 29 delegate_->OnGestureEnded(GetClosestState()); | 53 delegate_->OnGestureEnded(GetClosestState()); |
| 30 break; | 54 break; |
| 31 case ui::ET_GESTURE_SCROLL_UPDATE: | 55 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 32 UpdateScrollState(*event); | 56 UpdateScrollState(*event); |
| 33 break; | 57 break; |
| 34 case ui::ET_SCROLL_FLING_START: { | 58 case ui::ET_SCROLL_FLING_START: { |
| 35 const ui::GestureEventDetails& details = event->details(); | 59 const ui::GestureEventDetails& details = event->details(); |
| 36 const float kFlingCompletionVelocity = 100.0f; | 60 const float kFlingCompletionVelocity = 100.0f; |
| 37 HomeCard::State final_state = GetClosestState(); | 61 HomeCard::State final_state = GetClosestState(); |
| 38 if (::fabs(details.velocity_y()) > kFlingCompletionVelocity) { | 62 |
| 63 // 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.
| |
| 64 // but a fling happens at the end of a gesture, it should change the state | |
| 65 // in the direction to the fling velocity. | |
| 66 // This check of |final_state| and |original_state_| may cause unexpected | |
| 67 // results for some gestures, such like swipe up from minimized state -> | |
| 68 // move up to full screen -> fling down there. This type of gestures are | |
| 69 // considered rare. | |
| 70 // TODO(mukai): consider such case once reported. | |
| 71 if (final_state == original_state_ && | |
| 72 ::fabs(details.velocity_y()) > kFlingCompletionVelocity) { | |
| 39 if (details.velocity_y() > 0) { | 73 if (details.velocity_y() > 0) { |
| 40 final_state = std::min(HomeCard::VISIBLE_MINIMIZED, | 74 final_state = std::min(HomeCard::VISIBLE_MINIMIZED, |
| 41 static_cast<HomeCard::State>(final_state + 1)); | 75 static_cast<HomeCard::State>(final_state + 1)); |
| 42 } else { | 76 } else { |
| 43 final_state = std::max(HomeCard::VISIBLE_CENTERED, | 77 final_state = std::max(HomeCard::VISIBLE_CENTERED, |
| 44 static_cast<HomeCard::State>(final_state - 1)); | 78 static_cast<HomeCard::State>(final_state - 1)); |
| 45 } | 79 } |
| 46 } | 80 } |
| 47 delegate_->OnGestureEnded(final_state); | 81 delegate_->OnGestureEnded(final_state); |
| 48 break; | 82 break; |
| 49 } | 83 } |
| 50 default: | 84 default: |
| 51 // do nothing. | 85 // do nothing. |
| 52 break; | 86 break; |
| 53 } | 87 } |
| 54 } | 88 } |
| 55 | 89 |
| 56 HomeCard::State HomeCardGestureManager::GetClosestState() const { | 90 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.
| |
| 57 const int kMinimizedHomeBufferSize = 50; | 91 int buffer = (original_state_ == HomeCard::VISIBLE_CENTERED) |
| 58 if (last_estimated_height_ <= | 92 ? kMinimizedHomeBufferSizeForCentered |
| 59 kHomeCardMinimizedHeight + kMinimizedHomeBufferSize) { | 93 : kMinimizedHomeBufferSize; |
| 94 if (last_estimated_height_ < kHomeCardMinimizedHeight + buffer) | |
| 60 return HomeCard::VISIBLE_MINIMIZED; | 95 return HomeCard::VISIBLE_MINIMIZED; |
| 61 } | |
| 62 | 96 |
| 63 int centered_height = screen_bounds_.height(); | 97 float multiplier = (original_state_ == HomeCard::VISIBLE_MINIMIZED) |
| 64 if (last_estimated_height_ - kHomeCardHeight <= | 98 ? kBottomBoundaryRateForMinimized |
| 65 (centered_height - kHomeCardHeight) / 3) { | 99 : kBottomBoundaryRate; |
| 100 if (last_estimated_height_ < screen_bounds_.height() * multiplier) | |
| 66 return HomeCard::VISIBLE_BOTTOM; | 101 return HomeCard::VISIBLE_BOTTOM; |
| 67 } | 102 |
| 68 return HomeCard::VISIBLE_CENTERED; | 103 return HomeCard::VISIBLE_CENTERED; |
| 69 } | 104 } |
| 70 | 105 |
| 71 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) { | 106 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) { |
| 72 last_estimated_height_ = | 107 last_estimated_height_ = |
| 73 screen_bounds_.height() - event.root_location().y() + y_offset_; | 108 screen_bounds_.height() - event.root_location().y() + y_offset_; |
| 74 | 109 |
| 75 if (last_estimated_height_ <= kHomeCardMinimizedHeight) { | 110 if (last_estimated_height_ <= kHomeCardMinimizedHeight) { |
| 76 delegate_->OnGestureProgressed( | 111 delegate_->OnGestureProgressed( |
| 77 HomeCard::VISIBLE_BOTTOM, HomeCard::VISIBLE_MINIMIZED, 1.0f); | 112 HomeCard::VISIBLE_BOTTOM, HomeCard::VISIBLE_MINIMIZED, 1.0f); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 92 (bigger_height - smaller_height); | 127 (bigger_height - smaller_height); |
| 93 progress = std::min(1.0f, std::max(0.0f, progress)); | 128 progress = std::min(1.0f, std::max(0.0f, progress)); |
| 94 | 129 |
| 95 delegate_->OnGestureProgressed( | 130 delegate_->OnGestureProgressed( |
| 96 static_cast<HomeCard::State>(bigger_state + 1), | 131 static_cast<HomeCard::State>(bigger_state + 1), |
| 97 bigger_state, | 132 bigger_state, |
| 98 progress); | 133 progress); |
| 99 } | 134 } |
| 100 | 135 |
| 101 } // namespace athena | 136 } // namespace athena |
| OLD | NEW |