| 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 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 case ui::ET_GESTURE_SCROLL_END: | 28 case ui::ET_GESTURE_SCROLL_END: |
| 29 event->SetHandled(); | 29 event->SetHandled(); |
| 30 delegate_->OnGestureEnded(GetClosestState()); | 30 delegate_->OnGestureEnded(GetClosestState()); |
| 31 break; | 31 break; |
| 32 case ui::ET_GESTURE_SCROLL_UPDATE: | 32 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 33 UpdateScrollState(*event); | 33 UpdateScrollState(*event); |
| 34 break; | 34 break; |
| 35 case ui::ET_SCROLL_FLING_START: { | 35 case ui::ET_SCROLL_FLING_START: { |
| 36 const ui::GestureEventDetails& details = event->details(); | 36 const ui::GestureEventDetails& details = event->details(); |
| 37 const float kFlingCompletionVelocity = 100.0f; | 37 const float kFlingCompletionVelocity = 100.0f; |
| 38 HomeCard::State final_state = GetClosestState(); |
| 38 if (::fabs(details.velocity_y()) > kFlingCompletionVelocity) { | 39 if (::fabs(details.velocity_y()) > kFlingCompletionVelocity) { |
| 39 int step = (details.velocity_y() > 0) ? 1 : -1; | 40 if (details.velocity_y() > 0) { |
| 40 int new_state = static_cast<int>(last_state_) + step; | 41 final_state = std::min(HomeCard::VISIBLE_MINIMIZED, |
| 41 if (new_state >= HomeCard::VISIBLE_CENTERED && | 42 static_cast<HomeCard::State>(final_state + 1)); |
| 42 new_state <= HomeCard::VISIBLE_MINIMIZED) { | 43 } else { |
| 43 last_state_ = static_cast<HomeCard::State>(new_state); | 44 final_state = std::max(HomeCard::VISIBLE_CENTERED, |
| 45 static_cast<HomeCard::State>(final_state - 1)); |
| 44 } | 46 } |
| 45 delegate_->OnGestureEnded(last_state_); | |
| 46 } | 47 } |
| 48 delegate_->OnGestureEnded(final_state); |
| 47 break; | 49 break; |
| 48 } | 50 } |
| 49 default: | 51 default: |
| 50 // do nothing. | 52 // do nothing. |
| 51 break; | 53 break; |
| 52 } | 54 } |
| 53 } | 55 } |
| 54 | 56 |
| 55 HomeCard::State HomeCardGestureManager::GetClosestState() const { | 57 HomeCard::State HomeCardGestureManager::GetClosestState() const { |
| 56 // The top position of the bounds for one smaller state than the current | 58 const int kMinimizedHomeBufferSize = 50; |
| 57 // one. | 59 if (last_estimated_height_ <= |
| 58 | 60 kHomeCardMinimizedHeight + kMinimizedHomeBufferSize) { |
| 59 if (last_estimated_height_ <= kHomeCardMinimizedHeight) | |
| 60 return HomeCard::VISIBLE_MINIMIZED; | 61 return HomeCard::VISIBLE_MINIMIZED; |
| 61 | |
| 62 HomeCard::State smaller_state = HomeCard::VISIBLE_MINIMIZED; | |
| 63 int smaller_height = kHomeCardMinimizedHeight; | |
| 64 int bigger_height = kHomeCardHeight; | |
| 65 if (last_estimated_height_ > kHomeCardHeight) { | |
| 66 smaller_state = HomeCard::VISIBLE_BOTTOM; | |
| 67 smaller_height = kHomeCardHeight; | |
| 68 bigger_height = screen_bounds_.height(); | |
| 69 } | 62 } |
| 70 | 63 |
| 71 if (last_estimated_height_ - smaller_height <= | 64 int centered_height = screen_bounds_.height(); |
| 72 (bigger_height - smaller_height) / 5) { | 65 if (last_estimated_height_ - kHomeCardHeight <= |
| 73 return smaller_state; | 66 (centered_height - kHomeCardHeight) / 3) { |
| 67 return HomeCard::VISIBLE_BOTTOM; |
| 74 } | 68 } |
| 75 | 69 return HomeCard::VISIBLE_CENTERED; |
| 76 return static_cast<HomeCard::State>(smaller_state - 1); | |
| 77 } | 70 } |
| 78 | 71 |
| 79 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) { | 72 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) { |
| 80 last_estimated_height_ = | 73 last_estimated_height_ = |
| 81 screen_bounds_.height() - event.root_location().y() + y_offset_; | 74 screen_bounds_.height() - event.root_location().y() + y_offset_; |
| 82 | 75 |
| 83 if (last_estimated_height_ <= kHomeCardMinimizedHeight) { | 76 if (last_estimated_height_ <= kHomeCardMinimizedHeight) { |
| 84 delegate_->OnGestureProgressed( | 77 delegate_->OnGestureProgressed( |
| 85 last_state_, HomeCard::VISIBLE_MINIMIZED, 1.0f); | 78 last_state_, HomeCard::VISIBLE_MINIMIZED, 1.0f); |
| 86 last_state_ = HomeCard::VISIBLE_MINIMIZED; | 79 last_state_ = HomeCard::VISIBLE_MINIMIZED; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 106 progress = 1.0f - progress; | 99 progress = 1.0f - progress; |
| 107 } else { | 100 } else { |
| 108 last_state_ = static_cast<HomeCard::State>(last_state_ + 1); | 101 last_state_ = static_cast<HomeCard::State>(last_state_ + 1); |
| 109 } | 102 } |
| 110 } | 103 } |
| 111 delegate_->OnGestureProgressed(last_state_, state, progress); | 104 delegate_->OnGestureProgressed(last_state_, state, progress); |
| 112 last_state_ = state; | 105 last_state_ = state; |
| 113 } | 106 } |
| 114 | 107 |
| 115 } // namespace athena | 108 } // namespace athena |
| OLD | NEW |