Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: athena/home/home_card_gesture_manager.cc

Issue 581933004: Update gesture logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 maximum height, in pixels, of a home card with final state
15 // VISIBLE_MINIMIZED.
16 const int kMinimizedFinalStateMaxHeight = 50;
17
18 // The maximum height, in pixels, of an initially centered home card with final
19 // state VISIBLE_MINIMIZED.
20 const int kMinimizedFinalStateMaxHeightInitiallyCentered = 90;
21
22 // The minimum height, as a percentage of the screen height, of a home card with
23 // final state VISIBLE_CENTERED.
24 const float kCenteredFinalStateMinScreenRatio = 0.5f;
25
26 // The minimum height, as a percentage of the screen height, of an initially
27 // minimized home card with final state VISIBLE_CENTERED.
28 const float kCenteredFinalStateMinScreenRatioInitiallyMinimized = 0.3f;
29
30 }
31
12 HomeCardGestureManager::HomeCardGestureManager(Delegate* delegate, 32 HomeCardGestureManager::HomeCardGestureManager(Delegate* delegate,
13 const gfx::Rect& screen_bounds) 33 const gfx::Rect& screen_bounds)
14 : delegate_(delegate), 34 : delegate_(delegate),
35 original_state_(HomeCard::HIDDEN),
15 y_offset_(0), 36 y_offset_(0),
16 last_estimated_height_(0), 37 last_estimated_height_(0),
17 screen_bounds_(screen_bounds) {} 38 screen_bounds_(screen_bounds) {}
18 39
19 HomeCardGestureManager::~HomeCardGestureManager() {} 40 HomeCardGestureManager::~HomeCardGestureManager() {}
20 41
21 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { 42 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) {
22 switch (event->type()) { 43 switch (event->type()) {
23 case ui::ET_GESTURE_SCROLL_BEGIN: 44 case ui::ET_GESTURE_SCROLL_BEGIN:
24 y_offset_ = event->location().y(); 45 y_offset_ = event->location().y();
46 original_state_ = HomeCard::Get()->GetState();
47 DCHECK_NE(HomeCard::HIDDEN, original_state_);
25 event->SetHandled(); 48 event->SetHandled();
26 break; 49 break;
27 case ui::ET_GESTURE_SCROLL_END: 50 case ui::ET_GESTURE_SCROLL_END:
28 event->SetHandled(); 51 event->SetHandled();
29 delegate_->OnGestureEnded(GetClosestState()); 52 delegate_->OnGestureEnded(GetFinalState());
30 break; 53 break;
31 case ui::ET_GESTURE_SCROLL_UPDATE: 54 case ui::ET_GESTURE_SCROLL_UPDATE:
32 UpdateScrollState(*event); 55 UpdateScrollState(*event);
33 break; 56 break;
34 case ui::ET_SCROLL_FLING_START: { 57 case ui::ET_SCROLL_FLING_START: {
35 const ui::GestureEventDetails& details = event->details(); 58 const ui::GestureEventDetails& details = event->details();
36 const float kFlingCompletionVelocity = 100.0f; 59 const float kFlingCompletionVelocity = 100.0f;
37 HomeCard::State final_state = GetClosestState(); 60 HomeCard::State final_state = GetFinalState();
38 if (::fabs(details.velocity_y()) > kFlingCompletionVelocity) { 61
62 // When the user does not drag far enough to switch the final state, but
63 // a fling happens at the end of the gesture, the state should change
64 // based on the direction of the fling.
65 // Checking |final_state| == |original_state| may cause unexpected results
66 // for gestures where the user flings in the opposite direction that they
67 // moved the home card (e.g. drag home card up from minimized state and
68 // then fling down)
69 // TODO(mukai): Consider this case once reported.
70 if (final_state == original_state_ &&
71 ::fabs(details.velocity_y()) > kFlingCompletionVelocity) {
39 if (details.velocity_y() > 0) { 72 if (details.velocity_y() > 0) {
40 final_state = std::min(HomeCard::VISIBLE_MINIMIZED, 73 final_state = std::min(HomeCard::VISIBLE_MINIMIZED,
41 static_cast<HomeCard::State>(final_state + 1)); 74 static_cast<HomeCard::State>(final_state + 1));
42 } else { 75 } else {
43 final_state = std::max(HomeCard::VISIBLE_CENTERED, 76 final_state = std::max(HomeCard::VISIBLE_CENTERED,
44 static_cast<HomeCard::State>(final_state - 1)); 77 static_cast<HomeCard::State>(final_state - 1));
45 } 78 }
46 } 79 }
47 delegate_->OnGestureEnded(final_state); 80 delegate_->OnGestureEnded(final_state);
48 break; 81 break;
49 } 82 }
50 default: 83 default:
51 // do nothing. 84 // do nothing.
52 break; 85 break;
53 } 86 }
54 } 87 }
55 88
56 HomeCard::State HomeCardGestureManager::GetClosestState() const { 89 HomeCard::State HomeCardGestureManager::GetFinalState() const {
57 const int kMinimizedHomeBufferSize = 50; 90 int height = (original_state_ == HomeCard::VISIBLE_CENTERED)
58 if (last_estimated_height_ <= 91 ? kMinimizedFinalStateMaxHeightInitiallyCentered
59 kHomeCardMinimizedHeight + kMinimizedHomeBufferSize) { 92 : kMinimizedFinalStateMaxHeight;
93 if (last_estimated_height_ < kHomeCardMinimizedHeight + height)
pkotwicz 2014/09/18 22:15:32 Nit: Can this simply be: if (last_estimated_height
Jun Mukai 2014/09/18 22:33:33 Done.
60 return HomeCard::VISIBLE_MINIMIZED; 94 return HomeCard::VISIBLE_MINIMIZED;
61 }
62 95
63 int centered_height = screen_bounds_.height(); 96 float ratio = (original_state_ == HomeCard::VISIBLE_MINIMIZED)
64 if (last_estimated_height_ - kHomeCardHeight <= 97 ? kCenteredFinalStateMinScreenRatioInitiallyMinimized
65 (centered_height - kHomeCardHeight) / 3) { 98 : kCenteredFinalStateMinScreenRatio;
99 if (last_estimated_height_ < screen_bounds_.height() * ratio)
66 return HomeCard::VISIBLE_BOTTOM; 100 return HomeCard::VISIBLE_BOTTOM;
67 } 101
68 return HomeCard::VISIBLE_CENTERED; 102 return HomeCard::VISIBLE_CENTERED;
69 } 103 }
70 104
71 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) { 105 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) {
72 last_estimated_height_ = 106 last_estimated_height_ =
73 screen_bounds_.height() - event.root_location().y() + y_offset_; 107 screen_bounds_.height() - event.root_location().y() + y_offset_;
74 108
75 if (last_estimated_height_ <= kHomeCardMinimizedHeight) { 109 if (last_estimated_height_ <= kHomeCardMinimizedHeight) {
76 delegate_->OnGestureProgressed( 110 delegate_->OnGestureProgressed(
77 HomeCard::VISIBLE_BOTTOM, HomeCard::VISIBLE_MINIMIZED, 1.0f); 111 HomeCard::VISIBLE_BOTTOM, HomeCard::VISIBLE_MINIMIZED, 1.0f);
(...skipping 14 matching lines...) Expand all
92 (bigger_height - smaller_height); 126 (bigger_height - smaller_height);
93 progress = std::min(1.0f, std::max(0.0f, progress)); 127 progress = std::min(1.0f, std::max(0.0f, progress));
94 128
95 delegate_->OnGestureProgressed( 129 delegate_->OnGestureProgressed(
96 static_cast<HomeCard::State>(bigger_state + 1), 130 static_cast<HomeCard::State>(bigger_state + 1),
97 bigger_state, 131 bigger_state,
98 progress); 132 progress);
99 } 133 }
100 134
101 } // namespace athena 135 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698