| 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 23 matching lines...) Expand all Loading... |
| 34 if (selected_page_ >= total_pages_) | 34 if (selected_page_ >= total_pages_) |
| 35 SelectPage(total_pages_ - 1, false /* animate */); | 35 SelectPage(total_pages_ - 1, false /* animate */); |
| 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_.get()) { | 44 if (!transition_animation_) { |
| 45 if (page == selected_page_) | 45 if (page == selected_page_) |
| 46 return; | 46 return; |
| 47 | 47 |
| 48 // Suppress over scroll animation if the same one happens too fast. | 48 // Suppress over scroll animation if the same one happens too fast. |
| 49 if (!is_valid_page(page)) { | 49 if (!is_valid_page(page)) { |
| 50 const base::TimeTicks now = base::TimeTicks::Now(); | 50 const base::TimeTicks now = base::TimeTicks::Now(); |
| 51 | 51 |
| 52 if (page == last_overscroll_target_page_) { | 52 if (page == last_overscroll_target_page_) { |
| 53 const int kMinOverScrollTimeGapInMs = 500; | 53 const int kMinOverScrollTimeGapInMs = 500; |
| 54 const base::TimeDelta time_elapsed = | 54 const base::TimeDelta time_elapsed = |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 StartTransitionAnimation(transition_); | 161 StartTransitionAnimation(transition_); |
| 162 | 162 |
| 163 if (cancel) | 163 if (cancel) |
| 164 transition_animation_->Hide(); | 164 transition_animation_->Hide(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 bool PaginationModel::IsRevertingCurrentTransition() const { | 167 bool PaginationModel::IsRevertingCurrentTransition() const { |
| 168 // Use !IsShowing() so that we return true at the end of hide animation. | 168 // Use !IsShowing() so that we return true at the end of hide animation. |
| 169 return transition_animation_.get() && !transition_animation_->IsShowing(); | 169 return transition_animation_ && !transition_animation_->IsShowing(); |
| 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 void PaginationModel::NotifySelectedPageChanged(int old_selected, | 180 void PaginationModel::NotifySelectedPageChanged(int old_selected, |
| 181 int new_selected) { | 181 int new_selected) { |
| 182 FOR_EACH_OBSERVER(PaginationModelObserver, | 182 FOR_EACH_OBSERVER(PaginationModelObserver, |
| 183 observers_, | 183 observers_, |
| 184 SelectedPageChanged(old_selected, new_selected)); | 184 SelectedPageChanged(old_selected, new_selected)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void PaginationModel::NotifyTransitionChanged() { | 187 void PaginationModel::NotifyTransitionChanged() { |
| 188 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionChanged()); | 188 FOR_EACH_OBSERVER(PaginationModelObserver, observers_, TransitionChanged()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 int PaginationModel::CalculateTargetPage(int delta) const { | 191 int PaginationModel::CalculateTargetPage(int delta) const { |
| 192 DCHECK_GT(total_pages_, 0); | 192 DCHECK_GT(total_pages_, 0); |
| 193 | 193 |
| 194 int current_page = selected_page_; | 194 int current_page = selected_page_; |
| 195 if (transition_animation_.get() && transition_animation_->IsShowing()) { | 195 if (transition_animation_ && transition_animation_->IsShowing()) { |
| 196 current_page = pending_selected_page_ >= 0 ? | 196 current_page = pending_selected_page_ >= 0 ? |
| 197 pending_selected_page_ : transition_.target_page; | 197 pending_selected_page_ : transition_.target_page; |
| 198 } | 198 } |
| 199 | 199 |
| 200 const int target_page = current_page + delta; | 200 const int target_page = current_page + delta; |
| 201 | 201 |
| 202 int start_page = 0; | 202 int start_page = 0; |
| 203 int end_page = total_pages_ - 1; | 203 int end_page = total_pages_ - 1; |
| 204 | 204 |
| 205 // Use invalid page when |selected_page_| is at ends. | 205 // Use invalid page when |selected_page_| is at ends. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } else if (transition_animation_->GetCurrentValue() == 0) { | 258 } else if (transition_animation_->GetCurrentValue() == 0) { |
| 259 // Hiding animation ends. No page change should happen. | 259 // Hiding animation ends. No page change should happen. |
| 260 ResetTransitionAnimation(); | 260 ResetTransitionAnimation(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 if (next_target >= 0) | 263 if (next_target >= 0) |
| 264 SelectPage(next_target, true); | 264 SelectPage(next_target, true); |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace app_list | 267 } // namespace app_list |
| OLD | NEW |