Skip to content

Commit

Permalink
app_list: Make over scroll animation faster.
Browse files Browse the repository at this point in the history
- Add an over scroll animation duration of 50ms;
- Use the over scroll animation duration for transition to invalid page
  (i.e. over scroll); This was using normal page transition duration of 180ms
  before.
- Use the same duration for snap back animation; This was 100ms and now changed
  to 50ms.

Also fixed a bug that app launcher bubble moves to wrong location if starting an
over scroll before previous over scroll snap back animation finishes.

BUG=160590
TEST=Verify over scroll animation is fast enough.

R=sky@chromium.org


Review URL: https://chromiumcodereview.appspot.com/11275320

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167784 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
xiyuan@chromium.org committed Nov 15, 2012
1 parent aae0e59 commit b51f39b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 36 deletions.
16 changes: 8 additions & 8 deletions ash/wm/app_list_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ash/shell_window_ids.h"
#include "ash/wm/property_util.h"
#include "ash/wm/shelf_layout_manager.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_view.h"
#include "ui/app_list/pagination_model.h"
#include "ui/aura/focus_manager.h"
Expand All @@ -33,9 +34,6 @@ const int kAnimationDurationMs = 200;
// Offset in pixels to animation away/towards the launcher.
const int kAnimationOffset = 8;

// Duration for snap back animation after over-scroll in milliseconds.
const int kSnapBackAnimationDurationMs = 100;

// The maximum shift in pixels when over-scroll happens.
const int kMaxOverScrollShift = 48;

Expand Down Expand Up @@ -348,9 +346,11 @@ void AppListController::TransitionChanged() {
return;

views::Widget* widget = view_->GetWidget();
ui::LayerAnimator* widget_animator = GetLayer(widget)->GetAnimator();
if (!pagination_model_->IsRevertingCurrentTransition()) {
// Update cached |view_bounds_| before the first over-scroll move.
if (!should_snap_back_)
// Update cached |view_bounds_| if it is the first over-scroll move and
// widget does not have running animations.
if (!should_snap_back_ && !widget_animator->is_animating())
view_bounds_ = widget->GetWindowBoundsInScreen();

const int current_page = pagination_model_->selected_page();
Expand All @@ -365,9 +365,9 @@ void AppListController::TransitionChanged() {
should_snap_back_ = true;
} else if (should_snap_back_) {
should_snap_back_ = false;
ui::ScopedLayerAnimationSettings animation(GetLayer(widget)->GetAnimator());
animation.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kSnapBackAnimationDurationMs));
ui::ScopedLayerAnimationSettings animation(widget_animator);
animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
app_list::kOverscrollPageTransitionDurationMs));
widget->SetBounds(view_bounds_);
}
}
Expand Down
6 changes: 6 additions & 0 deletions ui/app_list/app_list_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ namespace app_list {

const SkColor kContentsBackgroundColor = SkColorSetRGB(0xF5, 0xF5, 0xF5);

// Duration in milliseconds for page transition.
const int kPageTransitionDurationInMs = 180;

// Duration in milliseconds for over scroll page transition.
const int kOverscrollPageTransitionDurationMs = 50;

} // namespace app_list
3 changes: 3 additions & 0 deletions ui/app_list/app_list_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace app_list {

APP_LIST_EXPORT extern const SkColor kContentsBackgroundColor;

APP_LIST_EXPORT extern const int kPageTransitionDurationInMs;
APP_LIST_EXPORT extern const int kOverscrollPageTransitionDurationMs;

} // namespace app_list

#endif // UI_APP_LIST_APP_LIST_CONSTANTS_H_
2 changes: 1 addition & 1 deletion ui/app_list/apps_grid_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ TEST_F(AppsGridViewTest, MouseDrag) {

TEST_F(AppsGridViewTest, MouseDragFlipPage) {
test_api_->SetPageFlipDelay(10);
pagination_model_->SetTransitionDuration(10);
pagination_model_->SetTransitionDurations(10, 10);

PageFlipWaiter page_flip_waiter(&message_loop_,
pagination_model_.get());
Expand Down
6 changes: 4 additions & 2 deletions ui/app_list/contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>

#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_view.h"
#include "ui/app_list/apps_grid_view.h"
#include "ui/app_list/pagination_model.h"
Expand All @@ -32,7 +33,6 @@ const int kMinScrollToSwitchPage = 20;
const int kMinHorizVelocityToSwitchPage = 800;

const double kFinishTransitionThreshold = 0.33;
const int kTransitionAnimationDurationInMs = 180;

// Helpers to get certain child view from |model|.
AppsGridView* GetAppsGridView(views::ViewModel* model) {
Expand All @@ -53,7 +53,9 @@ ContentsView::ContentsView(AppListView* app_list_view,
view_model_(new views::ViewModel),
ALLOW_THIS_IN_INITIALIZER_LIST(
bounds_animator_(new views::BoundsAnimator(this))) {
pagination_model_->SetTransitionDuration(kTransitionAnimationDurationInMs);
pagination_model_->SetTransitionDurations(
kPageTransitionDurationInMs,
kOverscrollPageTransitionDurationMs);

AppsGridView* apps_grid_view = new AppsGridView(app_list_view,
pagination_model);
Expand Down
42 changes: 21 additions & 21 deletions ui/app_list/pagination_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ PaginationModel::PaginationModel()
selected_page_(-1),
transition_(-1, 0),
pending_selected_page_(-1),
transition_duration_ms_(0) {
transition_duration_ms_(0),
overscroll_transition_duration_ms_(0) {
}

PaginationModel::~PaginationModel() {
Expand Down Expand Up @@ -44,11 +45,11 @@ void PaginationModel::SelectPage(int page, bool animate) {
return;

// Creates an animation if there is not one.
StartTranstionAnimation(page);
StartTransitionAnimation(Transition(page, 0));
return;
} else {
const bool showing = transition_animation_->IsShowing();
const int from_page = showing ? selected_page_ : transition_.target_page;
const int from_page = showing ? selected_page_ : transition_.target_page;
const int to_page = showing ? transition_.target_page : selected_page_;

if (from_page == page) {
Expand Down Expand Up @@ -95,8 +96,10 @@ void PaginationModel::SetTransition(const Transition& transition) {
NotifyTransitionChanged();
}

void PaginationModel::SetTransitionDuration(int duration_ms) {
void PaginationModel::SetTransitionDurations(int duration_ms,
int overscroll_duration_ms) {
transition_duration_ms_ = duration_ms;
overscroll_transition_duration_ms_ = overscroll_duration_ms;
}

void PaginationModel::StartScroll() {
Expand Down Expand Up @@ -134,11 +137,8 @@ void PaginationModel::EndScroll(bool cancel) {
if (!has_transition())
return;

CreateTransitionAnimation();
transition_animation_->Reset(transition_.progress);
StartTransitionAnimation(transition_);

// Always call Show to ensure animation will run.
transition_animation_->Show();
if (cancel)
transition_animation_->Hide();
}
Expand Down Expand Up @@ -190,19 +190,21 @@ int PaginationModel::CalculateTargetPage(int delta) const {
return std::max(start_page, std::min(end_page, target_page));
}

void PaginationModel::StartTranstionAnimation(int target_page) {
DCHECK(selected_page_ != target_page);
void PaginationModel::StartTransitionAnimation(const Transition& transition) {
DCHECK(selected_page_ != transition.target_page);

SetTransition(Transition(target_page, 0));
CreateTransitionAnimation();
transition_animation_->Show();
}
SetTransition(transition);

void PaginationModel::CreateTransitionAnimation() {
transition_animation_.reset(new ui::SlideAnimation(this));
transition_animation_->SetTweenType(ui::Tween::LINEAR);
if (transition_duration_ms_)
transition_animation_->SetSlideDuration(transition_duration_ms_);
transition_animation_->Reset(transition_.progress);

const int duration = is_valid_page(transition_.target_page) ?
transition_duration_ms_ : overscroll_transition_duration_ms_;
if (duration)
transition_animation_->SetSlideDuration(duration);

transition_animation_->Show();
}

void PaginationModel::ResetTransitionAnimation() {
Expand All @@ -223,10 +225,8 @@ void PaginationModel::AnimationEnded(const ui::Animation* animation) {

if (transition_animation_->GetCurrentValue() == 1) {
// Showing animation ends.
int target_page = transition_.target_page;

// If target page is not in valid range, reverse the animation.
if (target_page < 0 || target_page >= total_pages_) {
if (!is_valid_page(transition_.target_page)) {
// If target page is not in valid range, reverse the animation.
transition_animation_->Hide();
return;
}
Expand Down
6 changes: 3 additions & 3 deletions ui/app_list/pagination_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate {
void SelectPageRelative(int delta, bool animate);

void SetTransition(const Transition& transition);
void SetTransitionDuration(int duration_ms);
void SetTransitionDurations(int duration_ms, int overscroll_duration_ms);

// Starts a scroll transition. If there is a running transition animation,
// cancels it but keeps the transition info.
Expand Down Expand Up @@ -108,8 +108,7 @@ class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate {
// -1 or |total_pages_| is returned to indicate the situation.
int CalculateTargetPage(int delta) const;

void StartTranstionAnimation(int target_page);
void CreateTransitionAnimation();
void StartTransitionAnimation(const Transition& transition);
void ResetTransitionAnimation();

// ui::AnimationDelegate overrides:
Expand All @@ -128,6 +127,7 @@ class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate {

scoped_ptr<ui::SlideAnimation> transition_animation_;
int transition_duration_ms_; // Transition duration in millisecond.
int overscroll_transition_duration_ms_;

ObserverList<PaginationModelObserver> observers_;

Expand Down
2 changes: 1 addition & 1 deletion ui/app_list/pagination_model_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class PaginationModelTest : public testing::Test {
// testing::Test overrides:
virtual void SetUp() OVERRIDE {
pagination_.SetTotalPages(5);
pagination_.SetTransitionDuration(1);
pagination_.SetTransitionDurations(1, 1);
observer_.set_model(&pagination_);
pagination_.AddObserver(&observer_);
}
Expand Down

0 comments on commit b51f39b

Please sign in to comment.