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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { | 43 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { |
44 switch (event->type()) { | 44 switch (event->type()) { |
45 case ui::ET_GESTURE_SCROLL_BEGIN: | 45 case ui::ET_GESTURE_SCROLL_BEGIN: |
46 y_offset_ = event->location().y(); | 46 y_offset_ = event->location().y(); |
47 original_state_ = HomeCard::Get()->GetState(); | 47 original_state_ = HomeCard::Get()->GetState(); |
48 DCHECK_NE(HomeCard::HIDDEN, original_state_); | 48 DCHECK_NE(HomeCard::HIDDEN, original_state_); |
49 event->SetHandled(); | 49 event->SetHandled(); |
50 break; | 50 break; |
51 case ui::ET_GESTURE_SCROLL_END: | 51 case ui::ET_GESTURE_SCROLL_END: |
52 event->SetHandled(); | 52 event->SetHandled(); |
53 delegate_->OnGestureEnded(GetFinalState()); | 53 delegate_->OnGestureEnded(GetFinalState(), false); |
54 break; | 54 break; |
55 case ui::ET_GESTURE_SCROLL_UPDATE: | 55 case ui::ET_GESTURE_SCROLL_UPDATE: |
56 UpdateScrollState(*event); | 56 UpdateScrollState(*event); |
57 break; | 57 break; |
58 case ui::ET_SCROLL_FLING_START: { | 58 case ui::ET_SCROLL_FLING_START: { |
59 const ui::GestureEventDetails& details = event->details(); | 59 const ui::GestureEventDetails& details = event->details(); |
60 const float kFlingCompletionVelocity = 100.0f; | 60 const float kFlingCompletionVelocity = 100.0f; |
61 HomeCard::State final_state = GetFinalState(); | 61 HomeCard::State final_state = GetFinalState(); |
62 | 62 |
63 // When the user does not drag far enough to switch the final state, but | 63 // When the user does not drag far enough to switch the final state, but |
64 // a fling happens at the end of the gesture, the state should change | 64 // a fling happens at the end of the gesture, the state should change |
65 // based on the direction of the fling. | 65 // based on the direction of the fling. |
66 // Checking |final_state| == |original_state| may cause unexpected results | 66 // Checking |final_state| == |original_state| may cause unexpected results |
67 // for gestures where the user flings in the opposite direction that they | 67 // for gestures where the user flings in the opposite direction that they |
68 // moved the home card (e.g. drag home card up from minimized state and | 68 // moved the home card (e.g. drag home card up from minimized state and |
69 // then fling down) | 69 // then fling down) |
70 // TODO(mukai): Consider this case once reported. | 70 // TODO(mukai): Consider this case once reported. |
71 if (final_state == original_state_ && | 71 bool is_fling = ::fabs(details.velocity_y()) > kFlingCompletionVelocity; |
72 ::fabs(details.velocity_y()) > kFlingCompletionVelocity) { | 72 if (final_state == original_state_ && is_fling) { |
73 if (details.velocity_y() > 0) { | 73 if (details.velocity_y() > 0) { |
74 final_state = std::min(HomeCard::VISIBLE_MINIMIZED, | 74 final_state = std::min(HomeCard::VISIBLE_MINIMIZED, |
75 static_cast<HomeCard::State>(final_state + 1)); | 75 static_cast<HomeCard::State>(final_state + 1)); |
76 } else { | 76 } else { |
77 final_state = std::max(HomeCard::VISIBLE_CENTERED, | 77 final_state = std::max(HomeCard::VISIBLE_CENTERED, |
78 static_cast<HomeCard::State>(final_state - 1)); | 78 static_cast<HomeCard::State>(final_state - 1)); |
79 } | 79 } |
80 } | 80 } |
81 delegate_->OnGestureEnded(final_state); | 81 delegate_->OnGestureEnded(final_state, is_fling); |
82 break; | 82 break; |
83 } | 83 } |
84 default: | 84 default: |
85 // do nothing. | 85 // do nothing. |
86 break; | 86 break; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 HomeCard::State HomeCardGestureManager::GetFinalState() const { | 90 HomeCard::State HomeCardGestureManager::GetFinalState() const { |
91 int max_height = (original_state_ == HomeCard::VISIBLE_CENTERED) | 91 int max_height = (original_state_ == HomeCard::VISIBLE_CENTERED) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 (bigger_height - smaller_height); | 127 (bigger_height - smaller_height); |
128 progress = std::min(1.0f, std::max(0.0f, progress)); | 128 progress = std::min(1.0f, std::max(0.0f, progress)); |
129 | 129 |
130 delegate_->OnGestureProgressed( | 130 delegate_->OnGestureProgressed( |
131 static_cast<HomeCard::State>(bigger_state + 1), | 131 static_cast<HomeCard::State>(bigger_state + 1), |
132 bigger_state, | 132 bigger_state, |
133 progress); | 133 progress); |
134 } | 134 } |
135 | 135 |
136 } // namespace athena | 136 } // namespace athena |
OLD | NEW |