| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/app_launched_animation.h" | 5 #include "chrome/browser/app_launched_animation.h" | 
| 6 | 6 | 
| 7 #include "app/animation.h" |  | 
| 8 #include "app/animation_delegate.h" |  | 
| 9 #include "app/slide_animation.h" |  | 
| 10 #include "chrome/browser/extensions/image_loading_tracker.h" | 7 #include "chrome/browser/extensions/image_loading_tracker.h" | 
| 11 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" | 
| 12 #include "chrome/common/extensions/extension_icon_set.h" | 9 #include "chrome/common/extensions/extension_icon_set.h" | 
| 13 #include "chrome/common/extensions/extension_resource.h" | 10 #include "chrome/common/extensions/extension_resource.h" | 
| 14 #include "gfx/rect.h" | 11 #include "gfx/rect.h" | 
|  | 12 #include "ui/base/animation/animation.h" | 
|  | 13 #include "ui/base/animation/animation_delegate.h" | 
|  | 14 #include "ui/base/animation/slide_animation.h" | 
| 15 #include "views/controls/image_view.h" | 15 #include "views/controls/image_view.h" | 
| 16 #include "views/widget/widget_win.h" | 16 #include "views/widget/widget_win.h" | 
| 17 | 17 | 
| 18 namespace { | 18 namespace { | 
| 19 | 19 | 
| 20 // Start at 1, end at 0 | 20 // Start at 1, end at 0 | 
| 21 //    0ms You click the icon | 21 //    0ms You click the icon | 
| 22 //    0ms The launcher and contents begins to fade out, the icon | 22 //    0ms The launcher and contents begins to fade out, the icon | 
| 23 //        you clicked does not (stays opaque) | 23 //        you clicked does not (stays opaque) | 
| 24 //    0ms The app begins loading behind the launcher | 24 //    0ms The app begins loading behind the launcher | 
| 25 // +100ms The app icon begins to fade out. | 25 // +100ms The app icon begins to fade out. | 
| 26 // +200ms The launcher finishes fading out | 26 // +200ms The launcher finishes fading out | 
| 27 // +350ms The app icon finishes fading out | 27 // +350ms The app icon finishes fading out | 
| 28 | 28 | 
| 29 // How long the fade should take. | 29 // How long the fade should take. | 
| 30 static const int kDurationMS = 250; | 30 static const int kDurationMS = 250; | 
| 31 | 31 | 
| 32 // The delay before the fade out should start. | 32 // The delay before the fade out should start. | 
| 33 static const int kDelayMS = 100; | 33 static const int kDelayMS = 100; | 
| 34 | 34 | 
| 35 // AppLaunchedAnimation creates an animation. It loads the icon for the | 35 // AppLaunchedAnimation creates an animation. It loads the icon for the | 
| 36 // extension and once the image is loaded the animation starts. The icon fades | 36 // extension and once the image is loaded the animation starts. The icon fades | 
| 37 // out after a short delay. | 37 // out after a short delay. | 
| 38 class AppLaunchedAnimationWin : public AnimationDelegate, | 38 class AppLaunchedAnimationWin : public ui::AnimationDelegate, | 
| 39                                 public ImageLoadingTracker::Observer, | 39                                 public ImageLoadingTracker::Observer, | 
| 40                                 public views::ImageView { | 40                                 public views::ImageView { | 
| 41  public: | 41  public: | 
| 42   AppLaunchedAnimationWin(const Extension* extension, const gfx::Rect& rect); | 42   AppLaunchedAnimationWin(const Extension* extension, const gfx::Rect& rect); | 
| 43 | 43 | 
| 44  private: | 44  private: | 
| 45   // AnimationDelegate | 45   // ui::AnimationDelegate | 
| 46   virtual void AnimationProgressed(const Animation* animation); | 46   virtual void AnimationProgressed(const ui::Animation* animation); | 
| 47   virtual void AnimationCanceled(const Animation* animation); | 47   virtual void AnimationCanceled(const ui::Animation* animation); | 
| 48   virtual void AnimationEnded(const Animation* animation); | 48   virtual void AnimationEnded(const ui::Animation* animation); | 
| 49 | 49 | 
| 50   // We use a HWND for the popup so that it may float above any HWNDs in our UI. | 50   // We use a HWND for the popup so that it may float above any HWNDs in our UI. | 
| 51   views::WidgetWin* popup_; | 51   views::WidgetWin* popup_; | 
| 52 | 52 | 
| 53   // The rect to use for the popup. | 53   // The rect to use for the popup. | 
| 54   gfx::Rect rect_; | 54   gfx::Rect rect_; | 
| 55 | 55 | 
| 56   // Used for loading extension application icon. | 56   // Used for loading extension application icon. | 
| 57   ImageLoadingTracker app_icon_loader_; | 57   ImageLoadingTracker app_icon_loader_; | 
| 58 | 58 | 
| 59   // ImageLoadingTracker::Observer. | 59   // ImageLoadingTracker::Observer. | 
| 60   virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource, | 60   virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource, | 
| 61                              int index); | 61                              int index); | 
| 62 | 62 | 
| 63   // Hover animation. | 63   // Hover animation. | 
| 64   scoped_ptr<SlideAnimation> animation_; | 64   scoped_ptr<ui::SlideAnimation> animation_; | 
| 65 | 65 | 
| 66   DISALLOW_COPY_AND_ASSIGN(AppLaunchedAnimationWin); | 66   DISALLOW_COPY_AND_ASSIGN(AppLaunchedAnimationWin); | 
| 67 }; | 67 }; | 
| 68 | 68 | 
| 69 AppLaunchedAnimationWin::AppLaunchedAnimationWin(const Extension* extension, | 69 AppLaunchedAnimationWin::AppLaunchedAnimationWin(const Extension* extension, | 
| 70                                                  const gfx::Rect& rect) | 70                                                  const gfx::Rect& rect) | 
| 71     : popup_(NULL), | 71     : popup_(NULL), | 
| 72       rect_(rect), | 72       rect_(rect), | 
| 73       ALLOW_THIS_IN_INITIALIZER_LIST(app_icon_loader_(this)) { | 73       ALLOW_THIS_IN_INITIALIZER_LIST(app_icon_loader_(this)) { | 
| 74   DCHECK(extension); | 74   DCHECK(extension); | 
| 75   app_icon_loader_.LoadImage( | 75   app_icon_loader_.LoadImage( | 
| 76       extension, | 76       extension, | 
| 77       extension->GetIconResource(Extension::EXTENSION_ICON_LARGE, | 77       extension->GetIconResource(Extension::EXTENSION_ICON_LARGE, | 
| 78                                  ExtensionIconSet::MATCH_EXACTLY), | 78                                  ExtensionIconSet::MATCH_EXACTLY), | 
| 79       rect_.size(), | 79       rect_.size(), | 
| 80       ImageLoadingTracker::DONT_CACHE); | 80       ImageLoadingTracker::DONT_CACHE); | 
| 81 } | 81 } | 
| 82 | 82 | 
| 83 void AppLaunchedAnimationWin::AnimationCanceled(const Animation* animation) { | 83 void AppLaunchedAnimationWin::AnimationCanceled(const ui::Animation* animation) 
     { | 
| 84   AnimationEnded(animation); | 84   AnimationEnded(animation); | 
| 85 } | 85 } | 
| 86 | 86 | 
| 87 void AppLaunchedAnimationWin::AnimationEnded(const Animation* animation) { | 87 void AppLaunchedAnimationWin::AnimationEnded(const ui::Animation* animation) { | 
| 88   popup_->Close(); | 88   popup_->Close(); | 
| 89 } | 89 } | 
| 90 | 90 | 
| 91 void AppLaunchedAnimationWin::AnimationProgressed(const Animation* animation) { | 91 void AppLaunchedAnimationWin::AnimationProgressed( | 
|  | 92     const ui::Animation* animation) { | 
| 92   // GetCurrentValue goes from 1 to 0 since we are hiding. | 93   // GetCurrentValue goes from 1 to 0 since we are hiding. | 
| 93   const double current_value = 1.0 - animation->GetCurrentValue(); | 94   const double current_value = 1.0 - animation->GetCurrentValue(); | 
| 94   const double current_time = current_value * (kDelayMS + kDurationMS); | 95   const double current_time = current_value * (kDelayMS + kDurationMS); | 
| 95 | 96 | 
| 96   double opacity = 1.0 - | 97   double opacity = 1.0 - | 
| 97       std::max(0.0, static_cast<double>(current_time - kDelayMS)) / | 98       std::max(0.0, static_cast<double>(current_time - kDelayMS)) / | 
| 98           static_cast<double>(kDurationMS); | 99           static_cast<double>(kDurationMS); | 
| 99 | 100 | 
| 100   popup_->SetOpacity(static_cast<SkColor>(opacity * 255.0)); | 101   popup_->SetOpacity(static_cast<SkColor>(opacity * 255.0)); | 
| 101   SchedulePaint(); | 102   SchedulePaint(); | 
| 102 } | 103 } | 
| 103 | 104 | 
| 104 void AppLaunchedAnimationWin::OnImageLoaded(SkBitmap* image, | 105 void AppLaunchedAnimationWin::OnImageLoaded(SkBitmap* image, | 
| 105                                             ExtensionResource resource, | 106                                             ExtensionResource resource, | 
| 106                                             int index) { | 107                                             int index) { | 
| 107   if (image) { | 108   if (image) { | 
| 108     SetImage(image); | 109     SetImage(image); | 
| 109 | 110 | 
| 110     popup_ = new views::WidgetWin; | 111     popup_ = new views::WidgetWin; | 
| 111     popup_->set_window_style(WS_POPUP); | 112     popup_->set_window_style(WS_POPUP); | 
| 112     popup_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | | 113     popup_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | | 
| 113                                 WS_EX_TRANSPARENT); | 114                                 WS_EX_TRANSPARENT); | 
| 114     popup_->SetOpacity(static_cast<SkColor>(255)); | 115     popup_->SetOpacity(static_cast<SkColor>(255)); | 
| 115 | 116 | 
| 116     popup_->Init(NULL, rect_); | 117     popup_->Init(NULL, rect_); | 
| 117     popup_->SetContentsView(this); | 118     popup_->SetContentsView(this); | 
| 118     popup_->Show(); | 119     popup_->Show(); | 
| 119 | 120 | 
| 120     // Start animation. | 121     // Start animation. | 
| 121     animation_.reset(new SlideAnimation(this)); | 122     animation_.reset(new ui::SlideAnimation(this)); | 
| 122     animation_->SetSlideDuration(kDelayMS + kDurationMS); | 123     animation_->SetSlideDuration(kDelayMS + kDurationMS); | 
| 123     animation_->SetTweenType(Tween::LINEAR); | 124     animation_->SetTweenType(ui::Tween::LINEAR); | 
| 124     animation_->Reset(1.0); | 125     animation_->Reset(1.0); | 
| 125     animation_->Hide(); | 126     animation_->Hide(); | 
| 126   } | 127   } | 
| 127 } | 128 } | 
| 128 | 129 | 
| 129 }  // namespace | 130 }  // namespace | 
| 130 | 131 | 
| 131 // static | 132 // static | 
| 132 void AppLaunchedAnimation::Show(const Extension* extension, | 133 void AppLaunchedAnimation::Show(const Extension* extension, | 
| 133                                 const gfx::Rect& rect) { | 134                                 const gfx::Rect& rect) { | 
| 134   // The animation will delete itself when it's finished. | 135   // The animation will delete itself when it's finished. | 
| 135   new AppLaunchedAnimationWin(extension, rect); | 136   new AppLaunchedAnimationWin(extension, rect); | 
| 136 } | 137 } | 
| OLD | NEW | 
|---|