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 14 matching lines...) Expand all Loading... | |
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_) |
35 SelectPage(total_pages_ - 1, false /* animate */); | 35 SelectPage(std::max(total_pages_ - 1, 0), false /* animate */); |
tapted
2013/09/10 00:29:26
this change looks orthogonal.. is it a bug? Or, pe
calamity
2013/09/10 22:50:46
It prevents the app list from populating with 0 ap
| |
36 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TotalPagesChanged()); | 36 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TotalPagesChanged()); |
37 } | 37 } |
38 | 38 |
39 void PaginationModel::SelectPage(int page, bool animate) { | 39 void PaginationModel::SelectPage(int page, bool animate) { |
40 if (animate) { | 40 if (animate) { |
41 // -1 and |total_pages_| are valid target page for animation. | 41 // -1 and |total_pages_| are valid target page for animation. |
42 DCHECK(page >= -1 && page <= total_pages_); | 42 DCHECK(page >= -1 && page <= total_pages_); |
43 | 43 |
44 if (!transition_animation_) { | 44 if (!transition_animation_) { |
45 if (page == selected_page_) | 45 if (page == selected_page_) |
(...skipping 29 matching lines...) Expand all Loading... | |
75 else | 75 else |
76 transition_animation_->Show(); | 76 transition_animation_->Show(); |
77 pending_selected_page_ = -1; | 77 pending_selected_page_ = -1; |
78 } else if (to_page != page) { | 78 } else if (to_page != page) { |
79 pending_selected_page_ = page; | 79 pending_selected_page_ = page; |
80 } else { | 80 } else { |
81 pending_selected_page_ = -1; | 81 pending_selected_page_ = -1; |
82 } | 82 } |
83 } | 83 } |
84 } else { | 84 } else { |
85 DCHECK(page >= 0 && page < total_pages_); | 85 DCHECK(total_pages_ == 0 || (page >= 0 && page < total_pages_)); |
86 | 86 |
87 if (page == selected_page_) | 87 if (page == selected_page_) |
88 return; | 88 return; |
89 | 89 |
90 ResetTransitionAnimation(); | 90 ResetTransitionAnimation(); |
91 | 91 |
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 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 } else if (transition_animation_->GetCurrentValue() == 0) { | 263 } else if (transition_animation_->GetCurrentValue() == 0) { |
264 // Hiding animation ends. No page change should happen. | 264 // Hiding animation ends. No page change should happen. |
265 ResetTransitionAnimation(); | 265 ResetTransitionAnimation(); |
266 } | 266 } |
267 | 267 |
268 if (next_target >= 0) | 268 if (next_target >= 0) |
269 SelectPage(next_target, true); | 269 SelectPage(next_target, true); |
270 } | 270 } |
271 | 271 |
272 } // namespace app_list | 272 } // namespace app_list |
OLD | NEW |