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.
5 #ifndef UI_APP_LIST_FOLDER_IMAGE_H_
6 #define UI_APP_LIST_FOLDER_IMAGE_H_
10 #include "base/observer_list.h"
11 #include "ui/app_list/app_list_export.h"
12 #include "ui/app_list/app_list_item_list_observer.h"
13 #include "ui/app_list/app_list_item_observer.h"
14 #include "ui/gfx/image/image_skia.h"
23 class AppListItemList
;
25 class APP_LIST_EXPORT FolderImageObserver
{
27 // Called when the folder icon has changed.
28 virtual void OnFolderImageUpdated() {}
31 virtual ~FolderImageObserver() {}
34 // The icon for an app list folder, dynamically generated by drawing the
35 // folder's items inside a circle. Automatically keeps itself up to date, and
36 // notifies observers when it changes.
37 class APP_LIST_EXPORT FolderImage
: public AppListItemListObserver
,
38 public AppListItemObserver
{
40 explicit FolderImage(AppListItemList
* item_list
);
41 ~FolderImage() override
;
43 // Generates the folder's icon from the icons of the items in the item list,
44 // and notifies observers that the icon has changed.
47 const gfx::ImageSkia
& icon() const { return icon_
; }
49 // Returns the icon of one of the top items with |item_index|.
50 const gfx::ImageSkia
& GetTopIcon(size_t item_index
);
52 // Calculates the top item icons' bounds inside |folder_icon_bounds|.
53 // Returns the bounds of top item icons in sequence of top left, top right,
54 // bottom left, bottom right.
55 static std::vector
<gfx::Rect
> GetTopIconsBounds(
56 const gfx::Rect
& folder_icon_bounds
);
58 // Returns the target icon bounds for |item| to fly back to its parent folder
59 // icon in animation UI. If |item| is one of the top item icon, this will
60 // match its corresponding top item icon in the folder icon. Otherwise,
61 // the target icon bounds is centered at the |folder_icon_bounds| with
62 // the same size of the top item icon.
63 // The Rect returned is in the same coordinates of |folder_icon_bounds|.
64 gfx::Rect
GetTargetIconRectInFolderForItem(
66 const gfx::Rect
& folder_icon_bounds
);
68 void AddObserver(FolderImageObserver
* observer
);
69 void RemoveObserver(FolderImageObserver
* observer
);
71 // AppListItemObserver overrides:
72 void ItemIconChanged() override
;
74 // AppListItemListObserver overrides:
75 void OnListItemAdded(size_t index
, AppListItem
* item
) override
;
76 void OnListItemRemoved(size_t index
, AppListItem
* item
) override
;
77 void OnListItemMoved(size_t from_index
,
79 AppListItem
* item
) override
;
82 // Updates the folder's icon from the icons of |top_items_| and calls
83 // OnFolderImageUpdated. Does not refresh the |top_items_| list, so should
84 // only be called if the |item_list_| has not been changed (see UpdateIcon).
85 void RedrawIconAndNotify();
90 // List of top-level app list items (to display small in the icon).
91 AppListItemList
* item_list_
;
93 // Top items for generating folder icon.
94 std::vector
<AppListItem
*> top_items_
;
96 ObserverList
<FolderImageObserver
> observers_
;
99 } // namespace app_list
101 #endif // UI_APP_LIST_FOLDER_IMAGE_H_