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 HomeCardGestureManager::HomeCardGestureManager(Delegate* delegate, | 12 HomeCardGestureManager::HomeCardGestureManager(Delegate* delegate, |
13 const gfx::Rect& screen_bounds) | 13 const gfx::Rect& screen_bounds) |
14 : delegate_(delegate), | 14 : delegate_(delegate), |
15 last_state_(HomeCard::Get()->GetState()), | |
16 y_offset_(0), | 15 y_offset_(0), |
17 last_estimated_height_(0), | 16 last_estimated_height_(0), |
18 screen_bounds_(screen_bounds) {} | 17 screen_bounds_(screen_bounds) {} |
19 | 18 |
20 HomeCardGestureManager::~HomeCardGestureManager() {} | 19 HomeCardGestureManager::~HomeCardGestureManager() {} |
21 | 20 |
22 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { | 21 void HomeCardGestureManager::ProcessGestureEvent(ui::GestureEvent* event) { |
23 switch (event->type()) { | 22 switch (event->type()) { |
24 case ui::ET_GESTURE_SCROLL_BEGIN: | 23 case ui::ET_GESTURE_SCROLL_BEGIN: |
25 y_offset_ = event->location().y(); | 24 y_offset_ = event->location().y(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 67 } |
69 return HomeCard::VISIBLE_CENTERED; | 68 return HomeCard::VISIBLE_CENTERED; |
70 } | 69 } |
71 | 70 |
72 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) { | 71 void HomeCardGestureManager::UpdateScrollState(const ui::GestureEvent& event) { |
73 last_estimated_height_ = | 72 last_estimated_height_ = |
74 screen_bounds_.height() - event.root_location().y() + y_offset_; | 73 screen_bounds_.height() - event.root_location().y() + y_offset_; |
75 | 74 |
76 if (last_estimated_height_ <= kHomeCardMinimizedHeight) { | 75 if (last_estimated_height_ <= kHomeCardMinimizedHeight) { |
77 delegate_->OnGestureProgressed( | 76 delegate_->OnGestureProgressed( |
78 last_state_, HomeCard::VISIBLE_MINIMIZED, 1.0f); | 77 HomeCard::VISIBLE_BOTTOM, HomeCard::VISIBLE_MINIMIZED, 1.0f); |
79 last_state_ = HomeCard::VISIBLE_MINIMIZED; | |
80 return; | 78 return; |
81 } | 79 } |
82 | 80 |
83 HomeCard::State state = HomeCard::VISIBLE_BOTTOM; | 81 HomeCard::State bigger_state = HomeCard::VISIBLE_BOTTOM; |
84 float smaller_height = kHomeCardMinimizedHeight; | 82 float smaller_height = kHomeCardMinimizedHeight; |
85 float bigger_height = kHomeCardHeight; | 83 float bigger_height = kHomeCardHeight; |
86 if (last_estimated_height_ > kHomeCardHeight) { | 84 if (last_estimated_height_ > kHomeCardHeight) { |
87 state = HomeCard::VISIBLE_CENTERED; | 85 bigger_state = HomeCard::VISIBLE_CENTERED; |
88 smaller_height = kHomeCardHeight; | 86 smaller_height = kHomeCardHeight; |
89 bigger_height = screen_bounds_.height(); | 87 bigger_height = screen_bounds_.height(); |
90 } | 88 } |
91 | 89 |
92 // The finger is between two states. | 90 // The finger is between two states. |
93 float progress = (last_estimated_height_ - smaller_height) / | 91 float progress = (last_estimated_height_ - smaller_height) / |
94 (bigger_height - smaller_height); | 92 (bigger_height - smaller_height); |
95 progress = std::min(1.0f, std::max(0.0f, progress)); | 93 progress = std::min(1.0f, std::max(0.0f, progress)); |
96 | 94 |
97 if (last_state_ == state) { | 95 delegate_->OnGestureProgressed( |
98 if (event.details().scroll_y() > 0) { | 96 static_cast<HomeCard::State>(bigger_state + 1), |
99 state = static_cast<HomeCard::State>(state + 1); | 97 bigger_state, |
100 progress = 1.0f - progress; | 98 progress); |
101 } else { | |
102 last_state_ = static_cast<HomeCard::State>(last_state_ + 1); | |
103 } | |
104 } | |
105 delegate_->OnGestureProgressed(last_state_, state, progress); | |
106 last_state_ = state; | |
107 } | 99 } |
108 | 100 |
109 } // namespace athena | 101 } // namespace athena |
OLD | NEW |