| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 void PaginationModel::AddObserver(PaginationModelObserver* observer) { | 172 void PaginationModel::AddObserver(PaginationModelObserver* observer) { |
| 173 observers_.AddObserver(observer); | 173 observers_.AddObserver(observer); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void PaginationModel::RemoveObserver(PaginationModelObserver* observer) { | 176 void PaginationModel::RemoveObserver(PaginationModelObserver* observer) { |
| 177 observers_.RemoveObserver(observer); | 177 observers_.RemoveObserver(observer); |
| 178 } | 178 } |
| 179 | 179 |
| 180 int PaginationModel::SelectedTargetPage() const { |
| 181 // If no animation, or animation is in reverse, just the selected page. |
| 182 if (!transition_animation_ || !transition_animation_->IsShowing()) |
| 183 return selected_page_; |
| 184 |
| 185 // If, at the end of the current animation, we will animate to another page, |
| 186 // return that eventual page. |
| 187 if (pending_selected_page_ >= 0) |
| 188 return pending_selected_page_; |
| 189 |
| 190 // Just the target of the current animation. |
| 191 return transition_.target_page; |
| 192 } |
| 193 |
| 180 void PaginationModel::NotifySelectedPageChanged(int old_selected, | 194 void PaginationModel::NotifySelectedPageChanged(int old_selected, |
| 181 int new_selected) { | 195 int new_selected) { |
| 182 FOR_EACH_OBSERVER(PaginationModelObserver, | 196 FOR_EACH_OBSERVER(PaginationModelObserver, |
| 183 observers_, | 197 observers_, |
| 184 SelectedPageChanged(old_selected, new_selected)); | 198 SelectedPageChanged(old_selected, new_selected)); |
| 185 } | 199 } |
| 186 | 200 |
| 187 void PaginationModel::NotifyTransitionStarted() { | 201 void PaginationModel::NotifyTransitionStarted() { |
| 188 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionStarted()); | 202 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionStarted()); |
| 189 } | 203 } |
| 190 | 204 |
| 191 void PaginationModel::NotifyTransitionChanged() { | 205 void PaginationModel::NotifyTransitionChanged() { |
| 192 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionChanged()); | 206 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionChanged()); |
| 193 } | 207 } |
| 194 | 208 |
| 195 int PaginationModel::CalculateTargetPage(int delta) const { | 209 int PaginationModel::CalculateTargetPage(int delta) const { |
| 196 DCHECK_GT(total_pages_, 0); | 210 DCHECK_GT(total_pages_, 0); |
| 197 | 211 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 | 212 |
| 206 int start_page = 0; | 213 int start_page = 0; |
| 207 int end_page = total_pages_ - 1; | 214 int end_page = total_pages_ - 1; |
| 208 | 215 |
| 209 // Use invalid page when |selected_page_| is at ends. | 216 // Use invalid page when |selected_page_| is at ends. |
| 210 if (target_page < start_page && selected_page_ == start_page) | 217 if (target_page < start_page && selected_page_ == start_page) |
| 211 start_page = -1; | 218 start_page = -1; |
| 212 else if (target_page > end_page && selected_page_ == end_page) | 219 else if (target_page > end_page && selected_page_ == end_page) |
| 213 end_page = total_pages_; | 220 end_page = total_pages_; |
| 214 | 221 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } else if (transition_animation_->GetCurrentValue() == 0) { | 270 } else if (transition_animation_->GetCurrentValue() == 0) { |
| 264 // Hiding animation ends. No page change should happen. | 271 // Hiding animation ends. No page change should happen. |
| 265 ResetTransitionAnimation(); | 272 ResetTransitionAnimation(); |
| 266 } | 273 } |
| 267 | 274 |
| 268 if (next_target >= 0) | 275 if (next_target >= 0) |
| 269 SelectPage(next_target, true); | 276 SelectPage(next_target, true); |
| 270 } | 277 } |
| 271 | 278 |
| 272 } // namespace app_list | 279 } // namespace app_list |
| OLD | NEW |