| OLD | NEW | 
|---|
| (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 #include "ui/views/view.h" | 
|  | 11 | 
|  | 12 namespace app_list { | 
|  | 13 | 
|  | 14 // ContentsAnimator | 
|  | 15 | 
|  | 16 ContentsAnimator::ContentsAnimator(ContentsView* contents_view) | 
|  | 17     : contents_view_(contents_view) { | 
|  | 18 } | 
|  | 19 | 
|  | 20 ContentsAnimator::~ContentsAnimator() { | 
|  | 21 } | 
|  | 22 | 
|  | 23 gfx::Rect ContentsAnimator::GetOffscreenPageBounds(int page_index) const { | 
|  | 24   gfx::Rect bounds(contents_view_->GetContentsBounds()); | 
|  | 25   // The start page and search page origins are above; all other pages' origins | 
|  | 26   // are below. | 
|  | 27   int page_height = bounds.height(); | 
|  | 28   bool origin_above = contents_view_->GetPageIndexForState( | 
|  | 29                           AppListModel::STATE_START) == page_index || | 
|  | 30                       contents_view_->GetPageIndexForState( | 
|  | 31                           AppListModel::STATE_SEARCH_RESULTS) == page_index; | 
|  | 32   bounds.set_y(origin_above ? -page_height : page_height); | 
|  | 33   return bounds; | 
|  | 34 } | 
|  | 35 | 
|  | 36 // DefaultAnimator | 
|  | 37 | 
|  | 38 DefaultAnimator::DefaultAnimator(ContentsView* contents_view) | 
|  | 39     : ContentsAnimator(contents_view) { | 
|  | 40 } | 
|  | 41 | 
|  | 42 std::string DefaultAnimator::NameForTests() const { | 
|  | 43   return "DefaultAnimator"; | 
|  | 44 } | 
|  | 45 | 
|  | 46 void DefaultAnimator::Update(double progress, int from_page, int to_page) { | 
|  | 47   // Move the from page from 0 to its origin. Move the to page from its origin | 
|  | 48   // to 0. | 
|  | 49   gfx::Rect on_screen(contents_view()->GetDefaultContentsBounds()); | 
|  | 50   gfx::Rect from_page_origin(GetOffscreenPageBounds(from_page)); | 
|  | 51   gfx::Rect to_page_origin(GetOffscreenPageBounds(to_page)); | 
|  | 52   gfx::Rect from_page_rect( | 
|  | 53       gfx::Tween::RectValueBetween(progress, on_screen, from_page_origin)); | 
|  | 54   gfx::Rect to_page_rect( | 
|  | 55       gfx::Tween::RectValueBetween(progress, to_page_origin, on_screen)); | 
|  | 56 | 
|  | 57   contents_view()->GetPageView(from_page)->SetBoundsRect(from_page_rect); | 
|  | 58   contents_view()->GetPageView(to_page)->SetBoundsRect(to_page_rect); | 
|  | 59 } | 
|  | 60 | 
|  | 61 // StartToAppsAnimator | 
|  | 62 | 
|  | 63 StartToAppsAnimator::StartToAppsAnimator(ContentsView* contents_view) | 
|  | 64     : ContentsAnimator(contents_view) { | 
|  | 65 } | 
|  | 66 | 
|  | 67 std::string StartToAppsAnimator::NameForTests() const { | 
|  | 68   return "StartToAppsAnimator"; | 
|  | 69 } | 
|  | 70 | 
|  | 71 void StartToAppsAnimator::Update(double progress, | 
|  | 72                                  int start_page, | 
|  | 73                                  int apps_page) { | 
|  | 74   // TODO(mgiuca): This is just a clone of DefaultAnimator's animation. Write a | 
|  | 75   // custom animation for the All Apps button on the Start page. | 
|  | 76   gfx::Rect on_screen(contents_view()->GetDefaultContentsBounds()); | 
|  | 77   gfx::Rect from_page_origin(GetOffscreenPageBounds(start_page)); | 
|  | 78   gfx::Rect to_page_origin(GetOffscreenPageBounds(apps_page)); | 
|  | 79   gfx::Rect from_page_rect( | 
|  | 80       gfx::Tween::RectValueBetween(progress, on_screen, from_page_origin)); | 
|  | 81   gfx::Rect to_page_rect( | 
|  | 82       gfx::Tween::RectValueBetween(progress, to_page_origin, on_screen)); | 
|  | 83 | 
|  | 84   contents_view()->GetPageView(start_page)->SetBoundsRect(from_page_rect); | 
|  | 85   contents_view()->GetPageView(apps_page)->SetBoundsRect(to_page_rect); | 
|  | 86 } | 
|  | 87 | 
|  | 88 }  // app_list | 
| OLD | NEW | 
|---|