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

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

Issue 502583002: Exports gesture manager to a separate file and adds its unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const 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 | Annotate | Revision Log
« no previous file with comments | « athena/home/home_card_gesture_manager_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/public/home_card.h" 5 #include "athena/home/public/home_card.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "athena/common/container_priorities.h" 10 #include "athena/common/container_priorities.h"
11 #include "athena/env/public/athena_env.h" 11 #include "athena/env/public/athena_env.h"
12 #include "athena/home/app_list_view_delegate.h" 12 #include "athena/home/app_list_view_delegate.h"
13 #include "athena/home/athena_start_page_view.h" 13 #include "athena/home/athena_start_page_view.h"
14 #include "athena/home/home_card_constants.h"
15 #include "athena/home/home_card_gesture_manager.h"
14 #include "athena/home/minimized_home.h" 16 #include "athena/home/minimized_home.h"
15 #include "athena/home/public/app_model_builder.h" 17 #include "athena/home/public/app_model_builder.h"
16 #include "athena/input/public/accelerator_manager.h" 18 #include "athena/input/public/accelerator_manager.h"
17 #include "athena/screen/public/screen_manager.h" 19 #include "athena/screen/public/screen_manager.h"
18 #include "athena/wm/public/window_manager.h" 20 #include "athena/wm/public/window_manager.h"
19 #include "athena/wm/public/window_manager_observer.h" 21 #include "athena/wm/public/window_manager_observer.h"
20 #include "base/bind.h" 22 #include "base/bind.h"
21 #include "base/memory/weak_ptr.h" 23 #include "base/memory/weak_ptr.h"
22 #include "ui/app_list/search_provider.h" 24 #include "ui/app_list/search_provider.h"
23 #include "ui/app_list/views/app_list_main_view.h" 25 #include "ui/app_list/views/app_list_main_view.h"
24 #include "ui/app_list/views/contents_view.h" 26 #include "ui/app_list/views/contents_view.h"
25 #include "ui/aura/layout_manager.h" 27 #include "ui/aura/layout_manager.h"
26 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
27 #include "ui/compositor/closure_animation_observer.h" 29 #include "ui/compositor/closure_animation_observer.h"
28 #include "ui/compositor/scoped_layer_animation_settings.h" 30 #include "ui/compositor/scoped_layer_animation_settings.h"
29 #include "ui/views/background.h" 31 #include "ui/views/background.h"
30 #include "ui/views/layout/box_layout.h" 32 #include "ui/views/layout/box_layout.h"
31 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
32 #include "ui/views/widget/widget_delegate.h" 34 #include "ui/views/widget/widget_delegate.h"
33 #include "ui/wm/core/shadow_types.h" 35 #include "ui/wm/core/shadow_types.h"
34 #include "ui/wm/core/visibility_controller.h" 36 #include "ui/wm/core/visibility_controller.h"
35 #include "ui/wm/core/window_animations.h" 37 #include "ui/wm/core/window_animations.h"
36 #include "ui/wm/public/activation_change_observer.h" 38 #include "ui/wm/public/activation_change_observer.h"
37 #include "ui/wm/public/activation_client.h" 39 #include "ui/wm/public/activation_client.h"
38 40
39 namespace athena { 41 namespace athena {
40 namespace { 42 namespace {
41 43
42 HomeCard* instance = NULL; 44 HomeCard* instance = NULL;
43 const int kHomeCardHeight = 100;
44 const int kHomeCardMinimizedHeight = 6;
45 45
46 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, 46 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds,
47 HomeCard::State state) { 47 HomeCard::State state) {
48 switch (state) { 48 switch (state) {
49 case HomeCard::HIDDEN: 49 case HomeCard::HIDDEN:
50 break; 50 break;
51 51
52 case HomeCard::VISIBLE_CENTERED: 52 case HomeCard::VISIBLE_CENTERED:
53 return screen_bounds; 53 return screen_bounds;
54 54
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 virtual void SetChildBounds(aura::Window* child, 116 virtual void SetChildBounds(aura::Window* child,
117 const gfx::Rect& requested_bounds) OVERRIDE { 117 const gfx::Rect& requested_bounds) OVERRIDE {
118 SetChildBoundsDirect(child, requested_bounds); 118 SetChildBoundsDirect(child, requested_bounds);
119 } 119 }
120 120
121 Delegate* delegate_; 121 Delegate* delegate_;
122 122
123 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); 123 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
124 }; 124 };
125 125
126 class HomeCardGestureManager {
127 public:
128 class Delegate {
129 public:
130 // Called when the gesture has ended. The state of the home card will
131 // end up with |final_state|.
132 virtual void OnGestureEnded(HomeCard::State final_state) = 0;
133
134 // Called when the gesture position is updated so that |delegate| should
135 // update the visual. The arguments represent the state of the current
136 // gesture position is switching from |from_state| to |to_state|, and
137 // the level of the progress is at |progress|, which is 0 to 1.
138 // |from_state| and |to_state| could be same. For example, if the user moves
139 // the finger down to the bottom of the screen, both states are MINIMIZED.
140 // In that case |progress| is 0.
141 virtual void OnGestureProgressed(
142 HomeCard::State from_state,
143 HomeCard::State to_state,
144 float progress) = 0;
145 };
146
147 HomeCardGestureManager(Delegate* delegate,
148 const gfx::Rect& screen_bounds)
149 : delegate_(delegate),
150 last_state_(HomeCard::Get()->GetState()),
151 y_offset_(0),
152 last_estimated_top_(0),
153 screen_bounds_(screen_bounds) {}
154
155 void ProcessGestureEvent(ui::GestureEvent* event) {
156 switch (event->type()) {
157 case ui::ET_GESTURE_SCROLL_BEGIN:
158 y_offset_ = event->location().y();
159 event->SetHandled();
160 break;
161 case ui::ET_GESTURE_SCROLL_END:
162 event->SetHandled();
163 delegate_->OnGestureEnded(GetClosestState());
164 break;
165 case ui::ET_GESTURE_SCROLL_UPDATE:
166 UpdateScrollState(*event);
167 break;
168 case ui::ET_SCROLL_FLING_START: {
169 const ui::GestureEventDetails& details = event->details();
170 const float kFlingCompletionVelocity = 100.0f;
171 if (::fabs(details.velocity_y()) > kFlingCompletionVelocity) {
172 int step = (details.velocity_y() > 0) ? 1 : -1;
173 int new_state = static_cast<int>(last_state_) + step;
174 if (new_state >= HomeCard::VISIBLE_CENTERED &&
175 new_state <= HomeCard::VISIBLE_MINIMIZED) {
176 last_state_ = static_cast<HomeCard::State>(new_state);
177 }
178 delegate_->OnGestureEnded(last_state_);
179 }
180 break;
181 }
182 default:
183 // do nothing.
184 break;
185 }
186 }
187
188 private:
189 HomeCard::State GetClosestState() {
190 // The top position of the bounds for one smaller state than the current
191 // one.
192 int smaller_top = -1;
193 for (int i = HomeCard::VISIBLE_MINIMIZED;
194 i >= HomeCard::VISIBLE_CENTERED; --i) {
195 HomeCard::State state = static_cast<HomeCard::State>(i);
196 int top = GetBoundsForState(screen_bounds_, state).y();
197 if (last_estimated_top_ == top) {
198 return state;
199 } else if (last_estimated_top_ > top) {
200 if (smaller_top < 0)
201 return state;
202
203 if (smaller_top - last_estimated_top_ > (smaller_top - top) / 5) {
204 return state;
205 } else {
206 return static_cast<HomeCard::State>(i + 1);
207 }
208 }
209 smaller_top = top;
210 }
211
212 return last_state_;
213 }
214
215 void UpdateScrollState(const ui::GestureEvent& event) {
216 last_estimated_top_ = event.root_location().y() - y_offset_;
217
218 // The bounds which is at one smaller state than the current one.
219 gfx::Rect smaller_bounds;
220
221 for (int i = HomeCard::VISIBLE_MINIMIZED;
222 i >= HomeCard::VISIBLE_CENTERED; --i) {
223 HomeCard::State state = static_cast<HomeCard::State>(i);
224 const gfx::Rect bounds = GetBoundsForState(screen_bounds_, state);
225 if (last_estimated_top_ == bounds.y()) {
226 delegate_->OnGestureProgressed(last_state_, state, 1.0f);
227 last_state_ = state;
228 return;
229 } else if (last_estimated_top_ > bounds.y()) {
230 if (smaller_bounds.IsEmpty()) {
231 // Smaller than minimized -- returning the minimized bounds.
232 delegate_->OnGestureProgressed(last_state_, state, 1.0f);
233 } else {
234 // The finger is between two states.
235 float progress =
236 static_cast<float>((smaller_bounds.y() - last_estimated_top_)) /
237 (smaller_bounds.y() - bounds.y());
238 if (last_state_ == state) {
239 if (event.details().scroll_y() > 0) {
240 state = static_cast<HomeCard::State>(state + 1);
241 progress = 1.0f - progress;
242 } else {
243 last_state_ = static_cast<HomeCard::State>(last_state_ + 1);
244 }
245 }
246 delegate_->OnGestureProgressed(last_state_, state, progress);
247 }
248 last_state_ = state;
249 return;
250 }
251 smaller_bounds = bounds;
252 }
253 }
254
255 Delegate* delegate_;
256 HomeCard::State last_state_;
257
258 // The offset from the top edge of the home card and the initial position of
259 // gesture.
260 int y_offset_;
261
262 // The estimated top edge of the home card after the last touch event.
263 int last_estimated_top_;
264
265 // The bounds of the screen to compute the home card bounds.
266 gfx::Rect screen_bounds_;
267
268 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManager);
269 };
270
271 // The container view of home card contents of each state. 126 // The container view of home card contents of each state.
272 class HomeCardView : public views::WidgetDelegateView { 127 class HomeCardView : public views::WidgetDelegateView {
273 public: 128 public:
274 HomeCardView(app_list::AppListViewDelegate* view_delegate, 129 HomeCardView(app_list::AppListViewDelegate* view_delegate,
275 aura::Window* container, 130 aura::Window* container,
276 HomeCardGestureManager::Delegate* gesture_delegate) 131 HomeCardGestureManager::Delegate* gesture_delegate)
277 : gesture_delegate_(gesture_delegate), 132 : gesture_delegate_(gesture_delegate),
278 weak_factory_(this) { 133 weak_factory_(this) {
279 // Ideally AppListMainView should be used here and have AthenaStartPageView 134 // Ideally AppListMainView should be used here and have AthenaStartPageView
280 // as its child view, so that custom pages and apps grid are available in 135 // as its child view, so that custom pages and apps grid are available in
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 instance = NULL; 518 instance = NULL;
664 } 519 }
665 520
666 // static 521 // static
667 HomeCard* HomeCard::Get() { 522 HomeCard* HomeCard::Get() {
668 DCHECK(instance); 523 DCHECK(instance);
669 return instance; 524 return instance;
670 } 525 }
671 526
672 } // namespace athena 527 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/home_card_gesture_manager_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698