| 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 "chrome/browser/download/download_started_animation.h" | 5 #include "chrome/browser/download/download_started_animation.h" |
| 6 | 6 |
| 7 #include "content/public/browser/notification_details.h" | 7 #include "content/public/browser/notification_details.h" |
| 8 #include "content/public/browser/notification_observer.h" | 8 #include "content/public/browser/notification_observer.h" |
| 9 #include "content/public/browser/notification_registrar.h" | 9 #include "content/public/browser/notification_registrar.h" |
| 10 #include "content/public/browser/notification_source.h" | 10 #include "content/public/browser/notification_source.h" |
| 11 #include "content/public/browser/notification_types.h" | 11 #include "content/public/browser/notification_types.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
| 14 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 15 #include "ui/base/animation/linear_animation.h" | |
| 16 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/animation/linear_animation.h" |
| 17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 18 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 using content::WebContents; | 21 using content::WebContents; |
| 22 | 22 |
| 23 // How long to spend moving downwards and fading out after waiting. | 23 // How long to spend moving downwards and fading out after waiting. |
| 24 static const int kMoveTimeMs = 600; | 24 static const int kMoveTimeMs = 600; |
| 25 | 25 |
| 26 // The animation framerate. | 26 // The animation framerate. |
| 27 static const int kFrameRateHz = 60; | 27 static const int kFrameRateHz = 60; |
| 28 | 28 |
| 29 // What fraction of the frame height to move downward from the frame center. | 29 // What fraction of the frame height to move downward from the frame center. |
| 30 // Note that setting this greater than 0.5 will mean moving past the bottom of | 30 // Note that setting this greater than 0.5 will mean moving past the bottom of |
| 31 // the frame. | 31 // the frame. |
| 32 static const double kMoveFraction = 1.0 / 3.0; | 32 static const double kMoveFraction = 1.0 / 3.0; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // DownloadStartAnimation creates an animation (which begins running | 36 // DownloadStartAnimation creates an animation (which begins running |
| 37 // immediately) that animates an image downward from the center of the frame | 37 // immediately) that animates an image downward from the center of the frame |
| 38 // provided on the constructor, while simultaneously fading it out. To use, | 38 // provided on the constructor, while simultaneously fading it out. To use, |
| 39 // simply call "new DownloadStartAnimation"; the class cleans itself up when it | 39 // simply call "new DownloadStartAnimation"; the class cleans itself up when it |
| 40 // finishes animating. | 40 // finishes animating. |
| 41 class DownloadStartedAnimationWin : public ui::LinearAnimation, | 41 class DownloadStartedAnimationWin : public gfx::LinearAnimation, |
| 42 public content::NotificationObserver, | 42 public content::NotificationObserver, |
| 43 public views::ImageView { | 43 public views::ImageView { |
| 44 public: | 44 public: |
| 45 explicit DownloadStartedAnimationWin(WebContents* web_contents); | 45 explicit DownloadStartedAnimationWin(WebContents* web_contents); |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 // Move the animation to wherever it should currently be. | 48 // Move the animation to wherever it should currently be. |
| 49 void Reposition(); | 49 void Reposition(); |
| 50 | 50 |
| 51 // Shut down the animation cleanly. | 51 // Shut down the animation cleanly. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 73 gfx::Rect web_contents_bounds_; | 73 gfx::Rect web_contents_bounds_; |
| 74 | 74 |
| 75 // A scoped container for notification registries. | 75 // A scoped container for notification registries. |
| 76 content::NotificationRegistrar registrar_; | 76 content::NotificationRegistrar registrar_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(DownloadStartedAnimationWin); | 78 DISALLOW_COPY_AND_ASSIGN(DownloadStartedAnimationWin); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 DownloadStartedAnimationWin::DownloadStartedAnimationWin( | 81 DownloadStartedAnimationWin::DownloadStartedAnimationWin( |
| 82 WebContents* web_contents) | 82 WebContents* web_contents) |
| 83 : ui::LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL), | 83 : gfx::LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL), |
| 84 popup_(NULL), | 84 popup_(NULL), |
| 85 web_contents_(web_contents) { | 85 web_contents_(web_contents) { |
| 86 static gfx::ImageSkia* kDownloadImage = NULL; | 86 static gfx::ImageSkia* kDownloadImage = NULL; |
| 87 if (!kDownloadImage) { | 87 if (!kDownloadImage) { |
| 88 kDownloadImage = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 88 kDownloadImage = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 89 IDR_DOWNLOAD_ANIMATION_BEGIN); | 89 IDR_DOWNLOAD_ANIMATION_BEGIN); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // If we're too small to show the download image, then don't bother - | 92 // If we're too small to show the download image, then don't bother - |
| 93 // the shelf will be enough. | 93 // the shelf will be enough. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace | 183 } // namespace |
| 184 | 184 |
| 185 // static | 185 // static |
| 186 void DownloadStartedAnimation::Show(WebContents* web_contents) { | 186 void DownloadStartedAnimation::Show(WebContents* web_contents) { |
| 187 // The animation will delete itself when it's finished or when the tab | 187 // The animation will delete itself when it's finished or when the tab |
| 188 // contents is hidden or destroyed. | 188 // contents is hidden or destroyed. |
| 189 new DownloadStartedAnimationWin(web_contents); | 189 new DownloadStartedAnimationWin(web_contents); |
| 190 } | 190 } |
| OLD | NEW |