top_icon_animation_view.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef ASH_APP_LIST_VIEWS_TOP_ICON_ANIMATION_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_TOP_ICON_ANIMATION_VIEW_H_
  6. #include "base/observer_list.h"
  7. #include "base/observer_list_types.h"
  8. #include "ui/compositor/layer_animation_observer.h"
  9. #include "ui/views/view.h"
  10. namespace views {
  11. class ImageView;
  12. class Label;
  13. } // namespace views
  14. namespace ash {
  15. class AppsGridView;
  16. class TopIconAnimationView;
  17. // Observer for top icon animation completion.
  18. class TopIconAnimationObserver : public base::CheckedObserver {
  19. public:
  20. // Called when top icon animation completes.
  21. virtual void OnTopIconAnimationsComplete(TopIconAnimationView* view) {}
  22. protected:
  23. ~TopIconAnimationObserver() override = default;
  24. };
  25. // Transitional view used for top item icons animation when opening or closing
  26. // a folder. Owns itself.
  27. class TopIconAnimationView : public views::View,
  28. public ui::ImplicitAnimationObserver {
  29. public:
  30. // |grid|: The apps grid to which the icon animation view belongs.
  31. // |icon|: The icon image of the item icon of full scale size.
  32. // |title|: The title of the item.
  33. // |scaled_rect|: Bounds of the small icon inside folder icon.
  34. // |open_folder|: Specify open/close folder animation to perform.
  35. // |item_in_folder_icon|: True if the item is inside folder icon.
  36. // The view will be self-cleaned by the end of animation.
  37. TopIconAnimationView(AppsGridView* grid,
  38. const gfx::ImageSkia& icon,
  39. const std::u16string& title,
  40. const gfx::Rect& scaled_rect,
  41. bool open_folder,
  42. bool item_in_folder_icon);
  43. TopIconAnimationView(const TopIconAnimationView&) = delete;
  44. TopIconAnimationView& operator=(const TopIconAnimationView&) = delete;
  45. ~TopIconAnimationView() override;
  46. void AddObserver(TopIconAnimationObserver* observer);
  47. void RemoveObserver(TopIconAnimationObserver* observer);
  48. // When opening a folder, transform the top item icon from the small icon
  49. // inside folder icon to the full scale icon at the target location.
  50. // When closing a folder, transform the full scale item icon from its
  51. // location to the small icon inside the folder icon.
  52. void TransformView(base::TimeDelta duration);
  53. // views::View:
  54. const char* GetClassName() const override;
  55. private:
  56. // views::View overrides:
  57. gfx::Size CalculatePreferredSize() const override;
  58. void Layout() override;
  59. // ui::ImplicitAnimationObserver overrides:
  60. void OnImplicitAnimationsCompleted() override;
  61. bool RequiresNotificationWhenAnimatorDestroyed() const override;
  62. const AppsGridView* grid_; // Owned by views hierarchy.
  63. gfx::Size icon_size_;
  64. views::ImageView* icon_; // Owned by views hierarchy.
  65. views::Label* title_; // 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. bool item_in_folder_icon_;
  71. base::ObserverList<TopIconAnimationObserver> observers_;
  72. };
  73. } // namespace ash
  74. #endif // ASH_APP_LIST_VIEWS_TOP_ICON_ANIMATION_VIEW_H_