Chromium Code Reviews| Index: ui/app_list/folder_image.h |
| diff --git a/ui/app_list/folder_image.h b/ui/app_list/folder_image.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ccad367554dc6fb800a43701711339fe50341eb8 |
| --- /dev/null |
| +++ b/ui/app_list/folder_image.h |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_APP_LIST_FOLDER_IMAGE_H_ |
| +#define UI_APP_LIST_FOLDER_IMAGE_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/observer_list.h" |
| +#include "ui/app_list/app_list_item_list_observer.h" |
| +#include "ui/app_list/app_list_item_observer.h" |
| + |
| +namespace gfx { |
| +class ImageSkia; |
| +class Rect; |
| +} |
| + |
| +namespace app_list { |
| + |
| +class AppListItem; |
| +class AppListItemList; |
| + |
| +class FolderImageObserver { |
| + public: |
| + // Called when the folder icon has changed. |
| + virtual void OnFolderImageUpdated(const gfx::ImageSkia& icon) {} |
|
calamity
2014/10/28 05:12:58
I think it would be less weird to have this with n
Matt Giuca
2014/10/29 07:11:23
Done.
|
| + |
| + protected: |
| + virtual ~FolderImageObserver() {} |
| +}; |
| + |
| +// The icon for an app list folder, dynamically generated by drawing the |
| +// folder's items inside a circle. Automatically keeps itself up to date. |
| +// Does not directly store the icon; just passes it for the observers to use. |
|
calamity
2014/10/28 05:12:57
Any reason not to store the icon? It would make th
Matt Giuca
2014/10/29 07:11:23
Done.
|
| +class FolderImage : public AppListItemListObserver, public AppListItemObserver { |
| + public: |
| + FolderImage(AppListItemList* item_list); |
| + |
|
calamity
2014/10/28 05:12:57
nit: no space
Matt Giuca
2014/10/29 07:11:23
Done.
|
| + ~FolderImage() override; |
| + |
| + // Generates the folder's icon from the icons of the items in the item list, |
| + // and calls OnFolderImageUpdated with the result. |
| + void UpdateIcon(); |
| + |
| + // Returns the icon of one of the top items with |item_index|. |
| + const gfx::ImageSkia& GetTopIcon(size_t item_index); |
| + |
| + // Returns the target icon bounds for |item| to fly back to its parent folder |
| + // icon in animation UI. If |item| is one of the top item icon, this will |
| + // match its corresponding top item icon in the folder icon. Otherwise, |
| + // the target icon bounds is centered at the |folder_icon_bounds| with |
| + // the same size of the top item icon. |
| + // The Rect returned is in the same coordinates of |folder_icon_bounds|. |
| + gfx::Rect GetTargetIconRectInFolderForItem( |
| + AppListItem* item, |
| + const gfx::Rect& folder_icon_bounds); |
| + |
| + void AddObserver(FolderImageObserver* observer); |
| + void RemoveObserver(FolderImageObserver* observer); |
| + |
| + // AppListItemObserver overrides: |
|
calamity
2014/10/28 05:12:58
Overridden from
Matt Giuca
2014/10/29 07:11:23
Nah.
|
| + void ItemIconChanged() override; |
| + |
| + // AppListItemListObserver overrides: |
|
calamity
2014/10/28 05:12:58
Overridden from
|
| + void OnListItemAdded(size_t index, AppListItem* item) override; |
| + void OnListItemRemoved(size_t index, AppListItem* item) override; |
| + void OnListItemMoved(size_t from_index, |
| + size_t to_index, |
| + AppListItem* item) override; |
| + |
| + private: |
| + // Updates the folder's icon from the icons of |top_items_| and calls |
| + // OnFolderImageUpdated. Does not refresh the |top_items_| list, so should |
| + // only be called if the |item_list_| has not been changed (see UpdateIcon). |
| + void UpdateImageOnly(); |
| + |
| + // List of top-level app list items (to display small in the icon). |
| + AppListItemList* item_list_; |
| + |
| + // Top items for generating folder icon. |
| + std::vector<AppListItem*> top_items_; |
| + |
| + ObserverList<FolderImageObserver> observers_; |
| +}; |
| + |
| +} // namespace app_list |
| + |
| +#endif // UI_APP_LIST_FOLDER_IMAGE_H_ |