1 // Copyright 2013 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_APP_LIST_FOLDER_ITEM_H_
6 #define UI_APP_LIST_APP_LIST_FOLDER_ITEM_H_
11 #include "ui/app_list/app_list_export.h"
12 #include "ui/app_list/app_list_item.h"
13 #include "ui/app_list/app_list_item_list_observer.h"
14 #include "ui/app_list/app_list_item_observer.h"
22 class AppListItemList
;
24 // AppListFolderItem implements the model/controller for folders.
25 class APP_LIST_EXPORT AppListFolderItem
: public AppListItem
,
26 public AppListItemListObserver
,
27 public AppListItemObserver
{
29 // The folder type affects folder behavior.
31 // Default folder type.
33 // Items can not be moved to/from OEM folders in the UI.
37 static const char kItemType
[];
39 AppListFolderItem(const std::string
& id
, FolderType folder_type
);
40 ~AppListFolderItem() override
;
42 // Updates the folder's icon.
45 // Returns the icon of one of the top items with |item_index|.
46 const gfx::ImageSkia
& GetTopIcon(size_t item_index
);
48 // Returns the target icon bounds for |item| to fly back to its parent folder
49 // icon in animation UI. If |item| is one of the top item icon, this will
50 // match its corresponding top item icon in the folder icon. Otherwise,
51 // the target icon bounds is centered at the |folder_icon_bounds| with
52 // the same size of the top item icon.
53 // The Rect returned is in the same coordinates of |folder_icon_bounds|.
54 gfx::Rect
GetTargetIconRectInFolderForItem(
55 AppListItem
* item
, const gfx::Rect
& folder_icon_bounds
);
57 AppListItemList
* item_list() { return item_list_
.get(); }
58 const AppListItemList
* item_list() const { return item_list_
.get(); }
60 FolderType
folder_type() const { return folder_type_
; }
63 void Activate(int event_flags
) override
;
64 const char* GetItemType() const override
;
65 ui::MenuModel
* GetContextMenuModel() override
;
66 AppListItem
* FindChildItem(const std::string
& id
) override
;
67 size_t ChildItemCount() const override
;
68 void OnExtensionPreferenceChanged() override
;
69 bool CompareForTest(const AppListItem
* other
) const override
;
71 // Returns an id for a new folder.
72 static std::string
GenerateId();
75 // AppListItemObserver
76 void ItemIconChanged() override
;
78 // AppListItemListObserver
79 void OnListItemAdded(size_t index
, AppListItem
* item
) override
;
80 void OnListItemRemoved(size_t index
, AppListItem
* item
) override
;
82 void OnListItemMoved(size_t from_index
,
84 AppListItem
* item
) override
;
86 void UpdateTopItems();
88 // The type of folder; may affect behavior of folder views.
89 const FolderType folder_type_
;
91 // List of items in the folder.
92 scoped_ptr
<AppListItemList
> item_list_
;
94 // Top items for generating folder icon.
95 std::vector
<AppListItem
*> top_items_
;
97 DISALLOW_COPY_AND_ASSIGN(AppListFolderItem
);
100 } // namespace app_list
102 #endif // UI_APP_LIST_APP_LIST_FOLDER_ITEM_H_