Conform selector used in focus manager of history to <cr-menu> element.
[chromium-blink-merge.git] / ui / app_list / app_list_item.h
blobab5632fef2fdc0b9d271dcd87426edb9cd36b53a
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, bool has_shadow);
37 const gfx::ImageSkia& icon() const { return icon_; }
38 bool has_shadow() const { return has_shadow_; }
40 const std::string& GetDisplayName() const {
41 return short_name_.empty() ? name_ : short_name_;
44 const std::string& name() const { return name_; }
45 // Should only be used in tests; otheriwse use GetDisplayName().
46 const std::string& short_name() const { return short_name_; }
48 void set_highlighted(bool highlighted) { highlighted_ = highlighted; }
49 bool highlighted() const { return highlighted_; }
51 void SetIsInstalling(bool is_installing);
52 bool is_installing() const { return is_installing_; }
54 void SetPercentDownloaded(int percent_downloaded);
55 int percent_downloaded() const { return percent_downloaded_; }
57 bool IsInFolder() const { return !folder_id_.empty(); }
59 const std::string& id() const { return id_; }
60 const std::string& folder_id() const { return folder_id_; }
61 const syncer::StringOrdinal& position() const { return position_; }
63 void AddObserver(AppListItemObserver* observer);
64 void RemoveObserver(AppListItemObserver* observer);
66 // Activates (opens) the item. Does nothing by default.
67 virtual void Activate(int event_flags);
69 // Returns a static const char* identifier for the subclass (defaults to "").
70 // Pointers can be compared for quick type checking.
71 virtual const char* GetItemType() const;
73 // Returns the context menu model for this item, or NULL if there is currently
74 // no menu for the item (e.g. during install).
75 // Note the returned menu model is owned by this item.
76 virtual ui::MenuModel* GetContextMenuModel();
78 // Returns the item matching |id| contained in this item (e.g. if the item is
79 // a folder), or NULL if the item was not found or this is not a container.
80 virtual AppListItem* FindChildItem(const std::string& id);
82 // Returns the number of child items if it has any (e.g. is a folder) or 0.
83 virtual size_t ChildItemCount() const;
85 // Called when the extension preference changed. Used by ExtensionAppItem
86 // to update icon overlays.
87 virtual void OnExtensionPreferenceChanged();
89 // Utility functions for sync integration tests.
90 virtual bool CompareForTest(const AppListItem* other) const;
91 virtual std::string ToDebugString() const;
93 protected:
94 friend class ::FastShowPickler;
95 friend class AppListItemList;
96 friend class AppListItemListTest;
97 friend class AppListModel;
99 // These should only be called by AppListModel or in tests so that name
100 // changes trigger update notifications.
102 // Sets the full name of the item. Clears any shortened name.
103 void SetName(const std::string& name);
105 // Sets the full name and an optional shortened name of the item (e.g. to use
106 // if the full name is too long to fit in a view).
107 void SetNameAndShortName(const std::string& name,
108 const std::string& short_name);
110 void set_position(const syncer::StringOrdinal& new_position) {
111 DCHECK(new_position.IsValid());
112 position_ = new_position;
115 void set_folder_id(const std::string& folder_id) { folder_id_ = folder_id; }
117 private:
118 friend class AppListModelTest;
120 const std::string id_;
121 std::string folder_id_; // Id of containing folder; empty if top level item.
122 syncer::StringOrdinal position_;
123 gfx::ImageSkia icon_;
124 bool has_shadow_;
126 // The full name of an item. Used for display if |short_name_| is empty.
127 std::string name_;
129 // A shortened name for the item, used for display.
130 std::string short_name_;
132 bool highlighted_;
133 bool is_installing_;
134 int percent_downloaded_;
136 ObserverList<AppListItemObserver> observers_;
138 DISALLOW_COPY_AND_ASSIGN(AppListItem);
141 } // namespace app_list
143 #endif // UI_APP_LIST_APP_LIST_ITEM_H_