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 #ifndef UI_APP_LIST_FOLDER_IMAGE_H_ |
| 6 #define UI_APP_LIST_FOLDER_IMAGE_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/observer_list.h" |
| 11 #include "ui/app_list/app_list_item_list_observer.h" |
| 12 #include "ui/app_list/app_list_item_observer.h" |
| 13 #include "ui/gfx/image/image_skia.h" |
| 14 |
| 15 namespace gfx { |
| 16 class Rect; |
| 17 } |
| 18 |
| 19 namespace app_list { |
| 20 |
| 21 class AppListItem; |
| 22 class AppListItemList; |
| 23 |
| 24 class FolderImageObserver { |
| 25 public: |
| 26 virtual ~FolderImageObserver() {} |
| 27 |
| 28 // Called when the folder icon has changed. |
| 29 virtual void OnFolderImageUpdated() {} |
| 30 }; |
| 31 |
| 32 // The icon for an app list folder, dynamically generated by drawing the |
| 33 // folder's items inside a circle. Automatically keeps itself up to date. |
| 34 // Does not directly store the icon; just passes it for the observers to use. |
| 35 class APP_LIST_EXPORT FolderImage : public AppListItemListObserver, |
| 36 public AppListItemObserver { |
| 37 public: |
| 38 FolderImage(AppListItemList* item_list); |
| 39 ~FolderImage() override; |
| 40 |
| 41 // Generates the folder's icon from the icons of the items in the item list, |
| 42 // and calls OnFolderImageUpdated with the result. |
| 43 void UpdateIcon(); |
| 44 |
| 45 const gfx::ImageSkia& icon() const { return icon_; } |
| 46 |
| 47 // Returns the icon of one of the top items with |item_index|. |
| 48 const gfx::ImageSkia& GetTopIcon(size_t item_index); |
| 49 |
| 50 // Returns the target icon bounds for |item| to fly back to its parent folder |
| 51 // icon in animation UI. If |item| is one of the top item icon, this will |
| 52 // match its corresponding top item icon in the folder icon. Otherwise, |
| 53 // the target icon bounds is centered at the |folder_icon_bounds| with |
| 54 // the same size of the top item icon. |
| 55 // The Rect returned is in the same coordinates of |folder_icon_bounds|. |
| 56 gfx::Rect GetTargetIconRectInFolderForItem( |
| 57 AppListItem* item, |
| 58 const gfx::Rect& folder_icon_bounds); |
| 59 |
| 60 void AddObserver(FolderImageObserver* observer); |
| 61 void RemoveObserver(FolderImageObserver* observer); |
| 62 |
| 63 // AppListItemObserver overrides: |
| 64 void ItemIconChanged() override; |
| 65 |
| 66 // AppListItemListObserver overrides: |
| 67 void OnListItemAdded(size_t index, AppListItem* item) override; |
| 68 void OnListItemRemoved(size_t index, AppListItem* item) override; |
| 69 void OnListItemMoved(size_t from_index, |
| 70 size_t to_index, |
| 71 AppListItem* item) override; |
| 72 |
| 73 private: |
| 74 // Updates the folder's icon from the icons of |top_items_| and calls |
| 75 // OnFolderImageUpdated. Does not refresh the |top_items_| list, so should |
| 76 // only be called if the |item_list_| has not been changed (see UpdateIcon). |
| 77 void UpdateImageOnly(); |
| 78 |
| 79 // The icon image. |
| 80 gfx::ImageSkia icon_; |
| 81 |
| 82 // List of top-level app list items (to display small in the icon). |
| 83 AppListItemList* item_list_; |
| 84 |
| 85 // Top items for generating folder icon. |
| 86 std::vector<AppListItem*> top_items_; |
| 87 |
| 88 ObserverList<FolderImageObserver> observers_; |
| 89 }; |
| 90 |
| 91 } // namespace app_list |
| 92 |
| 93 #endif // UI_APP_LIST_FOLDER_IMAGE_H_ |
OLD | NEW |