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

Side by Side Diff: ui/app_list/pagination_model.cc

Issue 10826209: gestures: Generate only either scroll-end or fling-start events at the end of a scroll gesture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win-fix Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/app_list/pagination_model.h" 5 #include "ui/app_list/pagination_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/app_list/pagination_model_observer.h" 9 #include "ui/app_list/pagination_model_observer.h"
10 #include "ui/base/animation/slide_animation.h" 10 #include "ui/base/animation/slide_animation.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } else if (transition_.target_page != page) { 49 } else if (transition_.target_page != page) {
50 // If there is a running transition, remembers it if it's new. 50 // If there is a running transition, remembers it if it's new.
51 pending_selected_page_ = page; 51 pending_selected_page_ = page;
52 } 52 }
53 } else { 53 } else {
54 DCHECK(page >= 0 && page < total_pages_); 54 DCHECK(page >= 0 && page < total_pages_);
55 55
56 if (page == selected_page_) 56 if (page == selected_page_)
57 return; 57 return;
58 58
59 ResetTranstionAnimation(); 59 ResetTransitionAnimation();
60 60
61 int old_selected = selected_page_; 61 int old_selected = selected_page_;
62 selected_page_ = page; 62 selected_page_ = page;
63 NotifySelectedPageChanged(old_selected, selected_page_); 63 NotifySelectedPageChanged(old_selected, selected_page_);
64 } 64 }
65 } 65 }
66 66
67 void PaginationModel::SelectPageRelative(int delta, bool animate) { 67 void PaginationModel::SelectPageRelative(int delta, bool animate) {
68 SelectPage(CalculateTargetPage(delta), animate); 68 SelectPage(CalculateTargetPage(delta), animate);
69 } 69 }
70 70
71 void PaginationModel::SetTransition(const Transition& transition) { 71 void PaginationModel::SetTransition(const Transition& transition) {
72 // -1 and |total_pages_| is a valid target page, which means user is at 72 // -1 and |total_pages_| is a valid target page, which means user is at
73 // the end and there is no target page for this scroll. 73 // the end and there is no target page for this scroll.
74 DCHECK(transition.target_page >= -1 && 74 DCHECK(transition.target_page >= -1 &&
75 transition.target_page <= total_pages_); 75 transition.target_page <= total_pages_);
76 DCHECK(transition.progress >= 0 && transition.progress <= 1); 76 DCHECK(transition.progress >= 0 && transition.progress <= 1);
77 77
78 if (transition_.Equals(transition)) 78 if (transition_.Equals(transition))
79 return; 79 return;
80 80
81 transition_ = transition; 81 transition_ = transition;
82 NotifyTransitionChanged(); 82 NotifyTransitionChanged();
83 } 83 }
84 84
85 void PaginationModel::SetTransitionDuration(int duration_ms) { 85 void PaginationModel::SetTransitionDuration(int duration_ms) {
86 transition_duration_ms_ = duration_ms; 86 transition_duration_ms_ = duration_ms;
87 } 87 }
88 88
89 void PaginationModel::ResetTransitionAnimation() {
90 transition_animation_.reset();
91 transition_.target_page = -1;
92 transition_.progress = 0;
93 pending_selected_page_ = -1;
94 }
95
89 void PaginationModel::StartScroll() { 96 void PaginationModel::StartScroll() {
90 // Cancels current transition animation (if any). 97 // Cancels current transition animation (if any).
91 transition_animation_.reset(); 98 transition_animation_.reset();
92 } 99 }
93 100
94 void PaginationModel::UpdateScroll(double delta) { 101 void PaginationModel::UpdateScroll(double delta) {
95 // Translates scroll delta to desired page change direction. 102 // Translates scroll delta to desired page change direction.
96 int page_change_dir = delta > 0 ? -1 : 1; 103 int page_change_dir = delta > 0 ? -1 : 1;
97 104
98 // Initializes a transition if there is none. 105 // Initializes a transition if there is none.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 CreateTransitionAnimation(); 185 CreateTransitionAnimation();
179 transition_animation_->Show(); 186 transition_animation_->Show();
180 } 187 }
181 188
182 void PaginationModel::CreateTransitionAnimation() { 189 void PaginationModel::CreateTransitionAnimation() {
183 transition_animation_.reset(new ui::SlideAnimation(this)); 190 transition_animation_.reset(new ui::SlideAnimation(this));
184 if (transition_duration_ms_) 191 if (transition_duration_ms_)
185 transition_animation_->SetSlideDuration(transition_duration_ms_); 192 transition_animation_->SetSlideDuration(transition_duration_ms_);
186 } 193 }
187 194
188 void PaginationModel::ResetTranstionAnimation() {
189 transition_animation_.reset();
190 transition_.target_page = -1;
191 transition_.progress = 0;
192 pending_selected_page_ = -1;
193 }
194
195 void PaginationModel::AnimationProgressed(const ui::Animation* animation) { 195 void PaginationModel::AnimationProgressed(const ui::Animation* animation) {
196 transition_.progress = transition_animation_->GetCurrentValue(); 196 transition_.progress = transition_animation_->GetCurrentValue();
197 NotifyTransitionChanged(); 197 NotifyTransitionChanged();
198 } 198 }
199 199
200 void PaginationModel::AnimationEnded(const ui::Animation* animation) { 200 void PaginationModel::AnimationEnded(const ui::Animation* animation) {
201 // Save |pending_selected_page_| because SelectPage resets it. 201 // Save |pending_selected_page_| because SelectPage resets it.
202 int next_target = pending_selected_page_; 202 int next_target = pending_selected_page_;
203 203
204 if (transition_animation_->GetCurrentValue() == 1) { 204 if (transition_animation_->GetCurrentValue() == 1) {
205 // Showing animation ends. 205 // Showing animation ends.
206 int target_page = transition_.target_page; 206 int target_page = transition_.target_page;
207 207
208 // If target page is not in valid range, reverse the animation. 208 // If target page is not in valid range, reverse the animation.
209 if (target_page < 0 || target_page >= total_pages_) { 209 if (target_page < 0 || target_page >= total_pages_) {
210 transition_animation_->Hide(); 210 transition_animation_->Hide();
211 return; 211 return;
212 } 212 }
213 213
214 // Otherwise, change page and finish the transition. 214 // Otherwise, change page and finish the transition.
215 DCHECK(selected_page_ != transition_.target_page); 215 DCHECK(selected_page_ != transition_.target_page);
216 SelectPage(transition_.target_page, false /* animate */); 216 SelectPage(transition_.target_page, false /* animate */);
217 } else if (transition_animation_->GetCurrentValue() == 0) { 217 } else if (transition_animation_->GetCurrentValue() == 0) {
218 // Hiding animation ends. No page change should happen. 218 // Hiding animation ends. No page change should happen.
219 ResetTranstionAnimation(); 219 ResetTransitionAnimation();
220 } 220 }
221 221
222 if (next_target >= 0) 222 if (next_target >= 0)
223 SelectPage(next_target, true); 223 SelectPage(next_target, true);
224 } 224 }
225 225
226 } // namespace app_list 226 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698