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"
15 #include "ui/app_list/folder_image.h"
24 class AppListItemList
;
26 // AppListFolderItem implements the model/controller for folders.
27 class APP_LIST_EXPORT AppListFolderItem
: public AppListItem
,
28 public FolderImageObserver
{
30 // The folder type affects folder behavior.
32 // Default folder type.
34 // Items can not be moved to/from OEM folders in the UI.
38 static const char kItemType
[];
40 AppListFolderItem(const std::string
& id
, FolderType folder_type
);
41 ~AppListFolderItem() override
;
43 // Returns the icon of one of the top items with |item_index|.
44 const gfx::ImageSkia
& GetTopIcon(size_t item_index
);
46 // Returns the target icon bounds for |item| to fly back to its parent folder
47 // icon in animation UI. If |item| is one of the top item icon, this will
48 // match its corresponding top item icon in the folder icon. Otherwise,
49 // the target icon bounds is centered at the |folder_icon_bounds| with
50 // the same size of the top item icon.
51 // The Rect returned is in the same coordinates of |folder_icon_bounds|.
52 gfx::Rect
GetTargetIconRectInFolderForItem(
53 AppListItem
* item
, const gfx::Rect
& folder_icon_bounds
);
55 AppListItemList
* item_list() { return item_list_
.get(); }
56 const AppListItemList
* item_list() const { return item_list_
.get(); }
59 // TODO(mgiuca): return a const FolderImage& (requires that
60 // base::ObserverList::HasObserver takes a const*).
61 FolderImage
* folder_image() { return &folder_image_
; }
63 FolderType
folder_type() const { return folder_type_
; }
65 // AppListItem overrides:
66 void Activate(int event_flags
) override
;
67 const char* GetItemType() const override
;
68 ui::MenuModel
* GetContextMenuModel() override
;
69 AppListItem
* FindChildItem(const std::string
& id
) override
;
70 size_t ChildItemCount() const override
;
71 void OnExtensionPreferenceChanged() override
;
72 bool CompareForTest(const AppListItem
* other
) const override
;
74 // Returns an id for a new folder.
75 static std::string
GenerateId();
77 // FolderImageObserver overrides:
78 void OnFolderImageUpdated() override
;
81 // The type of folder; may affect behavior of folder views.
82 const FolderType folder_type_
;
84 // List of items in the folder.
85 scoped_ptr
<AppListItemList
> item_list_
;
87 FolderImage folder_image_
;
89 DISALLOW_COPY_AND_ASSIGN(AppListFolderItem
);
92 } // namespace app_list
94 #endif // UI_APP_LIST_APP_LIST_FOLDER_ITEM_H_