| OLD | NEW |
| 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/gfx/animation/slide_animation.h" | 10 #include "ui/gfx/animation/slide_animation.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 int old_selected = selected_page_; | 92 int old_selected = selected_page_; |
| 93 selected_page_ = page; | 93 selected_page_ = page; |
| 94 NotifySelectedPageChanged(old_selected, selected_page_); | 94 NotifySelectedPageChanged(old_selected, selected_page_); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 void PaginationModel::SelectPageRelative(int delta, bool animate) { | 98 void PaginationModel::SelectPageRelative(int delta, bool animate) { |
| 99 SelectPage(CalculateTargetPage(delta), animate); | 99 SelectPage(CalculateTargetPage(delta), animate); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void PaginationModel::FinishAnimation() { |
| 103 SelectPage(SelectedTargetPage(), false); |
| 104 } |
| 105 |
| 102 void PaginationModel::SetTransition(const Transition& transition) { | 106 void PaginationModel::SetTransition(const Transition& transition) { |
| 103 // -1 and |total_pages_| is a valid target page, which means user is at | 107 // -1 and |total_pages_| is a valid target page, which means user is at |
| 104 // the end and there is no target page for this scroll. | 108 // the end and there is no target page for this scroll. |
| 105 DCHECK(transition.target_page >= -1 && | 109 DCHECK(transition.target_page >= -1 && |
| 106 transition.target_page <= total_pages_); | 110 transition.target_page <= total_pages_); |
| 107 DCHECK(transition.progress >= 0 && transition.progress <= 1); | 111 DCHECK(transition.progress >= 0 && transition.progress <= 1); |
| 108 | 112 |
| 109 if (transition_.Equals(transition)) | 113 if (transition_.Equals(transition)) |
| 110 return; | 114 return; |
| 111 | 115 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 174 } |
| 171 | 175 |
| 172 void PaginationModel::AddObserver(PaginationModelObserver* observer) { | 176 void PaginationModel::AddObserver(PaginationModelObserver* observer) { |
| 173 observers_.AddObserver(observer); | 177 observers_.AddObserver(observer); |
| 174 } | 178 } |
| 175 | 179 |
| 176 void PaginationModel::RemoveObserver(PaginationModelObserver* observer) { | 180 void PaginationModel::RemoveObserver(PaginationModelObserver* observer) { |
| 177 observers_.RemoveObserver(observer); | 181 observers_.RemoveObserver(observer); |
| 178 } | 182 } |
| 179 | 183 |
| 184 int PaginationModel::SelectedTargetPage() const { |
| 185 // If no animation, or animation is in reverse, just the selected page. |
| 186 if (!transition_animation_ || !transition_animation_->IsShowing()) |
| 187 return selected_page_; |
| 188 |
| 189 // If, at the end of the current animation, we will animate to another page, |
| 190 // return that eventual page. |
| 191 if (pending_selected_page_ >= 0) |
| 192 return pending_selected_page_; |
| 193 |
| 194 // Just the target of the current animation. |
| 195 return transition_.target_page; |
| 196 } |
| 197 |
| 180 void PaginationModel::NotifySelectedPageChanged(int old_selected, | 198 void PaginationModel::NotifySelectedPageChanged(int old_selected, |
| 181 int new_selected) { | 199 int new_selected) { |
| 182 FOR_EACH_OBSERVER(PaginationModelObserver, | 200 FOR_EACH_OBSERVER(PaginationModelObserver, |
| 183 observers_, | 201 observers_, |
| 184 SelectedPageChanged(old_selected, new_selected)); | 202 SelectedPageChanged(old_selected, new_selected)); |
| 185 } | 203 } |
| 186 | 204 |
| 187 void PaginationModel::NotifyTransitionStarted() { | 205 void PaginationModel::NotifyTransitionStarted() { |
| 188 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionStarted()); | 206 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionStarted()); |
| 189 } | 207 } |
| 190 | 208 |
| 191 void PaginationModel::NotifyTransitionChanged() { | 209 void PaginationModel::NotifyTransitionChanged() { |
| 192 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionChanged()); | 210 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionChanged()); |
| 193 } | 211 } |
| 194 | 212 |
| 195 int PaginationModel::CalculateTargetPage(int delta) const { | 213 int PaginationModel::CalculateTargetPage(int delta) const { |
| 196 DCHECK_GT(total_pages_, 0); | 214 DCHECK_GT(total_pages_, 0); |
| 197 | 215 const int target_page = SelectedTargetPage() + delta; |
| 198 int current_page = selected_page_; | |
| 199 if (transition_animation_ && transition_animation_->IsShowing()) { | |
| 200 current_page = pending_selected_page_ >= 0 ? | |
| 201 pending_selected_page_ : transition_.target_page; | |
| 202 } | |
| 203 | |
| 204 const int target_page = current_page + delta; | |
| 205 | 216 |
| 206 int start_page = 0; | 217 int start_page = 0; |
| 207 int end_page = total_pages_ - 1; | 218 int end_page = total_pages_ - 1; |
| 208 | 219 |
| 209 // Use invalid page when |selected_page_| is at ends. | 220 // Use invalid page when |selected_page_| is at ends. |
| 210 if (target_page < start_page && selected_page_ == start_page) | 221 if (target_page < start_page && selected_page_ == start_page) |
| 211 start_page = -1; | 222 start_page = -1; |
| 212 else if (target_page > end_page && selected_page_ == end_page) | 223 else if (target_page > end_page && selected_page_ == end_page) |
| 213 end_page = total_pages_; | 224 end_page = total_pages_; |
| 214 | 225 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } else if (transition_animation_->GetCurrentValue() == 0) { | 274 } else if (transition_animation_->GetCurrentValue() == 0) { |
| 264 // Hiding animation ends. No page change should happen. | 275 // Hiding animation ends. No page change should happen. |
| 265 ResetTransitionAnimation(); | 276 ResetTransitionAnimation(); |
| 266 } | 277 } |
| 267 | 278 |
| 268 if (next_target >= 0) | 279 if (next_target >= 0) |
| 269 SelectPage(next_target, true); | 280 SelectPage(next_target, true); |
| 270 } | 281 } |
| 271 | 282 |
| 272 } // namespace app_list | 283 } // namespace app_list |
| OLD | NEW |