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 #ifndef UI_APP_LIST_VIEWS_TOP_ICON_ANIMATION_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_TOP_ICON_ANIMATION_VIEW_H_ 7 8 #include "base/observer_list.h" 9 #include "ui/compositor/layer_animation_observer.h" 10 #include "ui/views/view.h" 11 12 namespace views { 13 class ImageView; 14 } 15 16 namespace app_list { 17 18 // Observer for top icon animation completion. 19 class TopIconAnimationObserver { 20 public: 21 // Called when top icon animation completes. 22 virtual void OnTopIconAnimationsComplete() {} 23 24 protected: 25 TopIconAnimationObserver() {} 26 virtual ~TopIconAnimationObserver() {} 27 28 private: 29 DISALLOW_COPY_AND_ASSIGN(TopIconAnimationObserver); 30 }; 31 32 // Transitional view used for top item icons animation when opening or closing 33 // a folder. Owns itself. 34 class TopIconAnimationView : public views::View, 35 public ui::ImplicitAnimationObserver { 36 public: 37 // |icon|: The icon image of the item icon of full scale size. 38 // |scaled_rect|: Bounds of the small icon inside folder icon. 39 // |open_folder|: Specify open/close folder animation to perform. 40 // The view will be self-cleaned by the end of animation. 41 TopIconAnimationView(const gfx::ImageSkia& icon, 42 const gfx::Rect& scaled_rect, 43 bool open_folder); 44 virtual ~TopIconAnimationView(); 45 46 void AddObserver(TopIconAnimationObserver* observer); 47 void RemoveObserver(TopIconAnimationObserver* observer); 48 49 // When opening a folder, transform the top item icon from the small icon 50 // inside folder icon to the full scale icon at the target location. 51 // When closing a folder, transform the full scale item icon from its 52 // location to the small icon inside the folder icon. 53 void TransformView(); 54 55 private: 56 // views::View overrides: 57 virtual gfx::Size GetPreferredSize() const OVERRIDE; 58 virtual void Layout() OVERRIDE; 59 60 // ui::ImplicitAnimationObserver overrides: 61 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 62 virtual bool RequiresNotificationWhenAnimatorDestroyed() const OVERRIDE; 63 64 gfx::Size icon_size_; 65 views::ImageView* icon_; // Owned by views hierarchy. 66 // Rect of the scaled down top item icon inside folder icon's ink bubble. 67 gfx::Rect scaled_rect_; 68 // true: opening folder; false: closing folder. 69 bool open_folder_; 70 71 ObserverList<TopIconAnimationObserver> observers_; 72 73 DISALLOW_COPY_AND_ASSIGN(TopIconAnimationView); 74 }; 75 76 } // namespace app_list 77 78 #endif // UI_APP_LIST_VIEWS_TOP_ICON_ANIMATION_VIEW_H_ 79