Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: ui/app_list/views/contents_animator.cc

Issue 701773002: App list: Added contents view custom animation framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename some arguments. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/app_list/views/contents_animator.h"
6
7 #include "ui/app_list/views/contents_view.h"
8 #include "ui/gfx/animation/tween.h"
9 #include "ui/gfx/geometry/rect.h"
10
11 namespace app_list {
12
13 // ContentsAnimator
14
15 ContentsAnimator::ContentsAnimator(ContentsView* contents_view)
16 : contents_view_(contents_view) {
17 }
18
19 ContentsAnimator::~ContentsAnimator() {
20 }
21
22 gfx::Rect ContentsAnimator::GetOffscreenPageBounds(int page_index) const {
23 gfx::Rect bounds(contents_view_->GetContentsBounds());
24 // The start page and search page origins are above; all other pages' origins
25 // are below.
26 int page_height = bounds.height();
27 bool origin_above = contents_view_->GetPageIndexForState(
28 AppListModel::STATE_START) == page_index ||
29 contents_view_->GetPageIndexForState(
30 AppListModel::STATE_SEARCH_RESULTS) == page_index;
31 bounds.set_y(origin_above ? -page_height : page_height);
32 return bounds;
33 }
34
35 // DefaultAnimator
36
37 DefaultAnimator::DefaultAnimator(ContentsView* contents_view)
38 : ContentsAnimator(contents_view) {
39 }
40
41 std::string DefaultAnimator::NameForTests() const {
42 return "DefaultAnimator";
43 }
44
45 void DefaultAnimator::Update(double progress, int from_page, int to_page) {
46 // Move the from page from 0 to its origin. Move the to page from its origin
47 // to 0.
48 gfx::Rect on_screen(contents_view()->GetDefaultContentsBounds());
49 gfx::Rect from_page_origin(GetOffscreenPageBounds(from_page));
50 gfx::Rect to_page_origin(GetOffscreenPageBounds(to_page));
51 gfx::Rect from_page_rect(
52 gfx::Tween::RectValueBetween(progress, on_screen, from_page_origin));
53 gfx::Rect to_page_rect(
54 gfx::Tween::RectValueBetween(progress, to_page_origin, on_screen));
55
56 contents_view()->GetPageView(from_page)->SetBoundsRect(from_page_rect);
57 contents_view()->GetPageView(to_page)->SetBoundsRect(to_page_rect);
58 }
59
60 // StartToAppsAnimator
61
62 StartToAppsAnimator::StartToAppsAnimator(ContentsView* contents_view)
63 : ContentsAnimator(contents_view) {
64 }
65
66 std::string StartToAppsAnimator::NameForTests() const {
67 return "StartToAppsAnimator";
68 }
69
70 void StartToAppsAnimator::Update(double progress,
71 int start_page,
72 int apps_page) {
73 // TODO(mgiuca): This is just a clone of DefaultAnimator's animation. Write a
74 // custom animation for the All Apps button on the Start page.
75 gfx::Rect on_screen(contents_view()->GetDefaultContentsBounds());
76 gfx::Rect from_page_origin(GetOffscreenPageBounds(start_page));
77 gfx::Rect to_page_origin(GetOffscreenPageBounds(apps_page));
78 gfx::Rect from_page_rect(
79 gfx::Tween::RectValueBetween(progress, on_screen, from_page_origin));
80 gfx::Rect to_page_rect(
81 gfx::Tween::RectValueBetween(progress, to_page_origin, on_screen));
82
83 contents_view()->GetPageView(start_page)->SetBoundsRect(from_page_rect);
84 contents_view()->GetPageView(apps_page)->SetBoundsRect(to_page_rect);
85 }
86
87 } // app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698