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/base/animation/slide_animation.h" | 10 #include "ui/base/animation/slide_animation.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 PaginationModel::~PaginationModel() { | 24 PaginationModel::~PaginationModel() { |
25 } | 25 } |
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_) { |
koz (OOO until 15th September)
2013/08/05 01:09:11
nit: no curlies
| |
35 SelectPage(total_pages_ - 1, false /* animate */); | 35 SelectPage(std::max(total_pages_ - 1, 0), false /* animate */); |
36 } | |
36 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TotalPagesChanged()); | 37 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, 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_) |
(...skipping 29 matching lines...) Expand all Loading... | |
75 else | 76 else |
76 transition_animation_->Show(); | 77 transition_animation_->Show(); |
77 pending_selected_page_ = -1; | 78 pending_selected_page_ = -1; |
78 } else if (to_page != page) { | 79 } else if (to_page != page) { |
79 pending_selected_page_ = page; | 80 pending_selected_page_ = page; |
80 } else { | 81 } else { |
81 pending_selected_page_ = -1; | 82 pending_selected_page_ = -1; |
82 } | 83 } |
83 } | 84 } |
84 } else { | 85 } else { |
85 DCHECK(page >= 0 && page < total_pages_); | 86 DCHECK(page == 0 || (page > 0 && page < total_pages_)); |
koz (OOO until 15th September)
2013/08/05 01:09:11
This change seems unnecessary.
calamity
2013/08/08 04:52:12
Oops. Should be total_pages_ == 0. This needed to
| |
86 | 87 |
87 if (page == selected_page_) | 88 if (page == selected_page_) |
88 return; | 89 return; |
89 | 90 |
90 ResetTransitionAnimation(); | 91 ResetTransitionAnimation(); |
91 | 92 |
92 int old_selected = selected_page_; | 93 int old_selected = selected_page_; |
93 selected_page_ = page; | 94 selected_page_ = page; |
94 NotifySelectedPageChanged(old_selected, selected_page_); | 95 NotifySelectedPageChanged(old_selected, selected_page_); |
95 } | 96 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 } else if (transition_animation_->GetCurrentValue() == 0) { | 264 } else if (transition_animation_->GetCurrentValue() == 0) { |
264 // Hiding animation ends. No page change should happen. | 265 // Hiding animation ends. No page change should happen. |
265 ResetTransitionAnimation(); | 266 ResetTransitionAnimation(); |
266 } | 267 } |
267 | 268 |
268 if (next_target >= 0) | 269 if (next_target >= 0) |
269 SelectPage(next_target, true); | 270 SelectPage(next_target, true); |
270 } | 271 } |
271 | 272 |
272 } // namespace app_list | 273 } // namespace app_list |
OLD | NEW |