Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / app_list / app_list_item.h
blobd77fa9ef6093f1518f8c2821f9aff2e64dd9268f
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_
8 #include <string>
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"
16 class FastShowPickler;
18 namespace ui {
19 class MenuModel;
22 namespace app_list {
24 class AppListItemList;
25 class AppListItemListTest;
26 class AppListItemObserver;
27 class AppListModel;
29 // AppListItem provides icon and title to be shown in a AppListItemView
30 // and action to be executed when the AppListItemView is activated.
31 class APP_LIST_EXPORT AppListItem {
32 public:
33 explicit AppListItem(const std::string& id);
34 virtual ~AppListItem();
36 void SetIcon(const gfx::ImageSkia& icon);
37 const gfx::ImageSkia& icon() const { return icon_; }
39 const std::string& GetDisplayName() const {
40 return short_name_.empty() ? name_ : short_name_;
43 const std::string& name() const { return name_; }
44 // Should only be used in tests; otheriwse use GetDisplayName().
45 const std::string& short_name() const { return short_name_; }
47 void set_highlighted(bool highlighted) { highlighted_ = highlighted; }
48 bool highlighted() const { return highlighted_; }
50 void SetIsInstalling(bool is_installing);
51 bool is_installing() const { return is_installing_; }
53 void SetPercentDownloaded(int percent_downloaded);
54 int percent_downloaded() const { return percent_downloaded_; }
56 bool IsInFolder() const { return !folder_id_.empty(); }
58 const std::string& id() const { return id_; }
59 const std::string& folder_id() const { return folder_id_; }
60 const syncer::StringOrdinal& position() const { return position_; }
62 void AddObserver(AppListItemObserver* observer);
63 void RemoveObserver(AppListItemObserver* observer);
65 // Activates (opens) the item. Does nothing by default.
66 virtual void Activate(int event_flags);
68 // Returns a static const char* identifier for the subclass (defaults to "").
69 // Pointers can be compared for quick type checking.
70 virtual const char* GetItemType() const;
72 // Returns the context menu model for this item, or NULL if there is currently
73 // no menu for the item (e.g. during install).
74 // Note the returned menu model is owned by this item.
75 virtual ui::MenuModel* GetContextMenuModel();
77 // Returns the item matching |id| contained in this item (e.g. if the item is
78 // a folder), or NULL if the item was not found or this is not a container.
79 virtual AppListItem* FindChildItem(const std::string& id);
81 // Returns the number of child items if it has any (e.g. is a folder) or 0.
82 virtual size_t ChildItemCount() const;
84 // Called when the extension preference changed. Used by ExtensionAppItem
85 // to update icon overlays.
86 virtual void OnExtensionPreferenceChanged();
88 // Utility functions for sync integration tests.
89 virtual bool CompareForTest(const AppListItem* other) const;
90 virtual std::string ToDebugString() const;
92 protected:
93 friend class ::FastShowPickler;
94 friend class AppListItemList;
95 friend class AppListItemListTest;
96 friend class AppListModel;
98 // These should only be called by AppListModel or in tests so that name
99 // changes trigger update notifications.
101 // Sets the full name of the item. Clears any shortened name.
102 void SetName(const std::string& name);
104 // Sets the full name and an optional shortened name of the item (e.g. to use
105 // if the full name is too long to fit in a view).
106 void SetNameAndShortName(const std::string& name,
107 const std::string& short_name);
109 void set_position(const syncer::StringOrdinal& new_position) {
110 DCHECK(new_position.IsValid());
111 position_ = new_position;
114 void set_folder_id(const std::string& folder_id) { folder_id_ = folder_id; }
116 private:
117 friend class AppListModelTest;
119 const std::string id_;
120 std::string folder_id_; // Id of containing folder; empty if top level item.
121 syncer::StringOrdinal position_;
122 gfx::ImageSkia icon_;
124 // The full name of an item. Used for display if |short_name_| is empty.
125 std::string name_;
127 // A shortened name for the item, used for display.
128 std::string short_name_;
130 bool highlighted_;
131 bool is_installing_;
132 int percent_downloaded_;
134 base::ObserverList<AppListItemObserver> observers_;
136 DISALLOW_COPY_AND_ASSIGN(AppListItem);
139 } // namespace app_list
141 #endif // UI_APP_LIST_APP_LIST_ITEM_H_