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_ITEM_H_
6 #define UI_APP_LIST_APP_LIST_ITEM_H_
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
12 #include "sync/api/string_ordinal.h"
13 #include "ui/app_list/app_list_export.h"
14 #include "ui/gfx/image/image_skia.h"
22 class AppListItemList;
23 class AppListItemListTest;
24 class AppListItemObserver;
27 // AppListItem provides icon and title to be shown in a AppListItemView
28 // and action to be executed when the AppListItemView is activated.
29 class APP_LIST_EXPORT AppListItem {
31 explicit AppListItem(const std::string& id);
32 virtual ~AppListItem();
34 void SetIcon(const gfx::ImageSkia& icon, bool has_shadow);
35 const gfx::ImageSkia& icon() const { return icon_; }
36 bool has_shadow() const { return has_shadow_; }
38 void SetTitleAndFullName(const std::string& title,
39 const std::string& full_name);
40 const std::string& title() const { return title_; }
41 const std::string& full_name() const { return full_name_; }
43 void SetHighlighted(bool highlighted);
44 bool highlighted() const { return highlighted_; }
46 void SetIsInstalling(bool is_installing);
47 bool is_installing() const { return is_installing_; }
49 void SetPercentDownloaded(int percent_downloaded);
50 int percent_downloaded() const { return percent_downloaded_; }
52 bool IsInFolder() const { return !folder_id_.empty(); }
54 const std::string& id() const { return id_; }
55 const std::string& folder_id() const { return folder_id_; }
56 const syncer::StringOrdinal& position() const { return position_; }
58 void AddObserver(AppListItemObserver* observer);
59 void RemoveObserver(AppListItemObserver* observer);
61 // Activates (opens) the item. Does nothing by default.
62 virtual void Activate(int event_flags);
64 // Returns a static const char* identifier for the subclass (defaults to "").
65 // Pointers can be compared for quick type checking.
66 virtual const char* GetItemType() const;
68 // Returns the context menu model for this item, or NULL if there is currently
69 // no menu for the item (e.g. during install).
70 // Note the returned menu model is owned by this item.
71 virtual ui::MenuModel* GetContextMenuModel();
73 // Returns the item matching |id| contained in this item (e.g. if the item is
74 // a folder), or NULL if the item was not found or this is not a container.
75 virtual AppListItem* FindChildItem(const std::string& id);
77 // Returns the number of child items if it has any (e.g. is a folder) or 0.
78 virtual size_t ChildItemCount() const;
80 // Utility functions for sync integration tests.
81 virtual bool CompareForTest(const AppListItem* other) const;
82 virtual std::string ToDebugString() const;
85 friend class AppListItemList;
86 friend class AppListItemListTest;
87 friend class AppListModel;
89 void set_position(const syncer::StringOrdinal& new_position) {
90 DCHECK(new_position.IsValid());
91 position_ = new_position;
94 void set_folder_id(const std::string& folder_id) { folder_id_ = folder_id; }
97 friend class AppListModelTest;
99 const std::string id_;
100 std::string folder_id_; // Id of containing folder; empty if top level item.
101 syncer::StringOrdinal position_;
102 gfx::ImageSkia icon_;
105 std::string full_name_;
108 int percent_downloaded_;
110 ObserverList<AppListItemObserver> observers_;
112 DISALLOW_COPY_AND_ASSIGN(AppListItem);
115 } // namespace app_list
117 #endif // UI_APP_LIST_APP_LIST_ITEM_H_