| 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/gfx/animation/slide_animation.h" |
| 11 | 11 |
| 12 namespace app_list { | 12 namespace app_list { |
| 13 | 13 |
| 14 PaginationModel::PaginationModel() | 14 PaginationModel::PaginationModel() |
| 15 : total_pages_(-1), | 15 : total_pages_(-1), |
| 16 selected_page_(-1), | 16 selected_page_(-1), |
| 17 transition_(-1, 0), | 17 transition_(-1, 0), |
| 18 pending_selected_page_(-1), | 18 pending_selected_page_(-1), |
| 19 transition_duration_ms_(0), | 19 transition_duration_ms_(0), |
| 20 overscroll_transition_duration_ms_(0), | 20 overscroll_transition_duration_ms_(0), |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 214 |
| 215 return std::max(start_page, std::min(end_page, target_page)); | 215 return std::max(start_page, std::min(end_page, target_page)); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void PaginationModel::StartTransitionAnimation(const Transition& transition) { | 218 void PaginationModel::StartTransitionAnimation(const Transition& transition) { |
| 219 DCHECK(selected_page_ != transition.target_page); | 219 DCHECK(selected_page_ != transition.target_page); |
| 220 | 220 |
| 221 NotifyTransitionStarted(); | 221 NotifyTransitionStarted(); |
| 222 SetTransition(transition); | 222 SetTransition(transition); |
| 223 | 223 |
| 224 transition_animation_.reset(new ui::SlideAnimation(this)); | 224 transition_animation_.reset(new gfx::SlideAnimation(this)); |
| 225 transition_animation_->SetTweenType(ui::Tween::LINEAR); | 225 transition_animation_->SetTweenType(gfx::Tween::LINEAR); |
| 226 transition_animation_->Reset(transition_.progress); | 226 transition_animation_->Reset(transition_.progress); |
| 227 | 227 |
| 228 const int duration = is_valid_page(transition_.target_page) ? | 228 const int duration = is_valid_page(transition_.target_page) ? |
| 229 transition_duration_ms_ : overscroll_transition_duration_ms_; | 229 transition_duration_ms_ : overscroll_transition_duration_ms_; |
| 230 if (duration) | 230 if (duration) |
| 231 transition_animation_->SetSlideDuration(duration); | 231 transition_animation_->SetSlideDuration(duration); |
| 232 | 232 |
| 233 transition_animation_->Show(); | 233 transition_animation_->Show(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void PaginationModel::ResetTransitionAnimation() { | 236 void PaginationModel::ResetTransitionAnimation() { |
| 237 transition_animation_.reset(); | 237 transition_animation_.reset(); |
| 238 transition_.target_page = -1; | 238 transition_.target_page = -1; |
| 239 transition_.progress = 0; | 239 transition_.progress = 0; |
| 240 pending_selected_page_ = -1; | 240 pending_selected_page_ = -1; |
| 241 } | 241 } |
| 242 | 242 |
| 243 void PaginationModel::AnimationProgressed(const ui::Animation* animation) { | 243 void PaginationModel::AnimationProgressed(const gfx::Animation* animation) { |
| 244 transition_.progress = transition_animation_->GetCurrentValue(); | 244 transition_.progress = transition_animation_->GetCurrentValue(); |
| 245 NotifyTransitionChanged(); | 245 NotifyTransitionChanged(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void PaginationModel::AnimationEnded(const ui::Animation* animation) { | 248 void PaginationModel::AnimationEnded(const gfx::Animation* animation) { |
| 249 // Save |pending_selected_page_| because SelectPage resets it. | 249 // Save |pending_selected_page_| because SelectPage resets it. |
| 250 int next_target = pending_selected_page_; | 250 int next_target = pending_selected_page_; |
| 251 | 251 |
| 252 if (transition_animation_->GetCurrentValue() == 1) { | 252 if (transition_animation_->GetCurrentValue() == 1) { |
| 253 // Showing animation ends. | 253 // Showing animation ends. |
| 254 if (!is_valid_page(transition_.target_page)) { | 254 if (!is_valid_page(transition_.target_page)) { |
| 255 // If target page is not in valid range, reverse the animation. | 255 // If target page is not in valid range, reverse the animation. |
| 256 transition_animation_->Hide(); | 256 transition_animation_->Hide(); |
| 257 return; | 257 return; |
| 258 } | 258 } |
| 259 | 259 |
| 260 // Otherwise, change page and finish the transition. | 260 // Otherwise, change page and finish the transition. |
| 261 DCHECK(selected_page_ != transition_.target_page); | 261 DCHECK(selected_page_ != transition_.target_page); |
| 262 SelectPage(transition_.target_page, false /* animate */); | 262 SelectPage(transition_.target_page, false /* animate */); |
| 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 |