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/gfx/geometry/rect.h"
19 class AppListItemList;
21 typedef std::vector<gfx::Rect> Rects;
23 // AppListFolderItem implements the model/controller for folders.
24 class APP_LIST_EXPORT AppListFolderItem : public AppListItem,
25 public AppListItemListObserver,
26 public AppListItemObserver {
28 static const char kItemType[];
30 explicit AppListFolderItem(const std::string& id);
31 virtual ~AppListFolderItem();
33 // Updates the folder's icon.
36 // Returns the icon of one of the top items with |item_index|.
37 const gfx::ImageSkia& GetTopIcon(size_t item_index);
39 // Returns the target icon bounds for |item| to fly back to its parent folder
40 // icon in animation UI. If |item| is one of the top item icon, this will
41 // match its corresponding top item icon in the folder icon. Otherwise,
42 // the target icon bounds is centered at the |folder_icon_bounds| with
43 // the same size of the top item icon.
44 // The Rect returned is in the same coordinates of |folder_icon_bounds|.
45 gfx::Rect GetTargetIconRectInFolderForItem(
46 AppListItem* item, const gfx::Rect& folder_icon_bounds);
48 AppListItemList* item_list() { return item_list_.get(); }
49 const AppListItemList* item_list() const { return item_list_.get(); }
52 virtual void Activate(int event_flags) OVERRIDE;
53 virtual const char* GetItemType() const OVERRIDE;
54 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE;
55 virtual AppListItem* FindChildItem(const std::string& id) OVERRIDE;
56 virtual size_t ChildItemCount() const OVERRIDE;
57 virtual bool CompareForTest(const AppListItem* other) const OVERRIDE;
59 // Calculates the top item icons' bounds inside |folder_icon_bounds|.
60 // Returns the bounds of top item icons in sequence of top left, top right,
61 // bottom left, bottom right.
62 static Rects GetTopIconsBounds(const gfx::Rect& folder_icon_bounds);
64 // Returns an id for a new folder.
65 static std::string GenerateId();
68 // AppListItemObserver
69 virtual void ItemIconChanged() OVERRIDE;
70 virtual void ItemTitleChanged() OVERRIDE;
71 virtual void ItemHighlightedChanged() OVERRIDE;
72 virtual void ItemIsInstallingChanged() OVERRIDE;
73 virtual void ItemPercentDownloadedChanged() OVERRIDE;
75 // AppListItemListObserver
76 virtual void OnListItemAdded(size_t index, AppListItem* item) OVERRIDE;
77 virtual void OnListItemRemoved(size_t index,
78 AppListItem* item) OVERRIDE;;
79 virtual void OnListItemMoved(size_t from_index,
81 AppListItem* item) OVERRIDE;
83 void UpdateTopItems();
85 scoped_ptr<AppListItemList> item_list_;
86 // Top items for generating folder icon.
87 std::vector<AppListItem*> top_items_;
89 DISALLOW_COPY_AND_ASSIGN(AppListFolderItem);
92 } // namespace app_list
94 #endif // UI_APP_LIST_APP_LIST_FOLDER_ITEM_H_