| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 void PaginationModel::SetTotalPages(int total_pages) { | 27 void PaginationModel::SetTotalPages(int total_pages) { |
| 28 if (total_pages == total_pages_) | 28 if (total_pages == total_pages_) |
| 29 return; | 29 return; |
| 30 | 30 |
| 31 total_pages_ = total_pages; | 31 total_pages_ = total_pages; |
| 32 if (selected_page_ < 0) | 32 if (selected_page_ < 0) |
| 33 SelectPage(0, false /* animate */); | 33 SelectPage(0, false /* animate */); |
| 34 if (selected_page_ >= total_pages_) | 34 if (selected_page_ >= total_pages_) |
| 35 SelectPage(std::max(total_pages_ - 1, 0), false /* animate */); | 35 SelectPage(std::max(total_pages_ - 1, 0), false /* animate */); |
| 36 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TotalPagesChanged()); | 36 for (auto& observer : observers_) |
| 37 observer.TotalPagesChanged(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void PaginationModel::SelectPage(int page, bool animate) { | 40 void PaginationModel::SelectPage(int page, bool animate) { |
| 40 if (animate) { | 41 if (animate) { |
| 41 // -1 and |total_pages_| are valid target page for animation. | 42 // -1 and |total_pages_| are valid target page for animation. |
| 42 DCHECK(page >= -1 && page <= total_pages_); | 43 DCHECK(page >= -1 && page <= total_pages_); |
| 43 | 44 |
| 44 if (!transition_animation_) { | 45 if (!transition_animation_) { |
| 45 if (page == selected_page_) | 46 if (page == selected_page_) |
| 46 return; | 47 return; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // return that eventual page. | 191 // return that eventual page. |
| 191 if (pending_selected_page_ >= 0) | 192 if (pending_selected_page_ >= 0) |
| 192 return pending_selected_page_; | 193 return pending_selected_page_; |
| 193 | 194 |
| 194 // Just the target of the current animation. | 195 // Just the target of the current animation. |
| 195 return transition_.target_page; | 196 return transition_.target_page; |
| 196 } | 197 } |
| 197 | 198 |
| 198 void PaginationModel::NotifySelectedPageChanged(int old_selected, | 199 void PaginationModel::NotifySelectedPageChanged(int old_selected, |
| 199 int new_selected) { | 200 int new_selected) { |
| 200 FOR_EACH_OBSERVER(PaginationModelObserver, | 201 for (auto& observer : observers_) |
| 201 observers_, | 202 observer.SelectedPageChanged(old_selected, new_selected); |
| 202 SelectedPageChanged(old_selected, new_selected)); | |
| 203 } | 203 } |
| 204 | 204 |
| 205 void PaginationModel::NotifyTransitionStarted() { | 205 void PaginationModel::NotifyTransitionStarted() { |
| 206 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionStarted()); | 206 for (auto& observer : observers_) |
| 207 observer.TransitionStarted(); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void PaginationModel::NotifyTransitionChanged() { | 210 void PaginationModel::NotifyTransitionChanged() { |
| 210 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionChanged()); | 211 for (auto& observer : observers_) |
| 212 observer.TransitionChanged(); |
| 211 } | 213 } |
| 212 | 214 |
| 213 int PaginationModel::CalculateTargetPage(int delta) const { | 215 int PaginationModel::CalculateTargetPage(int delta) const { |
| 214 DCHECK_GT(total_pages_, 0); | 216 DCHECK_GT(total_pages_, 0); |
| 215 const int target_page = SelectedTargetPage() + delta; | 217 const int target_page = SelectedTargetPage() + delta; |
| 216 | 218 |
| 217 int start_page = 0; | 219 int start_page = 0; |
| 218 int end_page = total_pages_ - 1; | 220 int end_page = total_pages_ - 1; |
| 219 | 221 |
| 220 // Use invalid page when |selected_page_| is at ends. | 222 // Use invalid page when |selected_page_| is at ends. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } else if (transition_animation_->GetCurrentValue() == 0) { | 276 } else if (transition_animation_->GetCurrentValue() == 0) { |
| 275 // Hiding animation ends. No page change should happen. | 277 // Hiding animation ends. No page change should happen. |
| 276 ResetTransitionAnimation(); | 278 ResetTransitionAnimation(); |
| 277 } | 279 } |
| 278 | 280 |
| 279 if (next_target >= 0) | 281 if (next_target >= 0) |
| 280 SelectPage(next_target, true); | 282 SelectPage(next_target, true); |
| 281 } | 283 } |
| 282 | 284 |
| 283 } // namespace app_list | 285 } // namespace app_list |
| OLD | NEW |