Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / app_list_item.h
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.
4
5 #ifndef UI_APP_LIST_APP_LIST_ITEM_H_
6 #define UI_APP_LIST_APP_LIST_ITEM_H_
7
8 #include <string>
9
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"
15
16 namespace ui {
17 class MenuModel;
18 }
19
20 namespace app_list {
21
22 class AppListItemList;
23 class AppListItemListTest;
24 class AppListItemObserver;
25 class AppListModel;
26
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 {
30  public:
31   explicit AppListItem(const std::string& id);
32   virtual ~AppListItem();
33
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_; }
37
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_; }
42
43   void SetHighlighted(bool highlighted);
44   bool highlighted() const { return highlighted_; }
45
46   void SetIsInstalling(bool is_installing);
47   bool is_installing() const { return is_installing_; }
48
49   void SetPercentDownloaded(int percent_downloaded);
50   int percent_downloaded() const { return percent_downloaded_; }
51
52   bool IsInFolder() const { return !folder_id_.empty(); }
53
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_; }
57
58   void AddObserver(AppListItemObserver* observer);
59   void RemoveObserver(AppListItemObserver* observer);
60
61   // Activates (opens) the item. Does nothing by default.
62   virtual void Activate(int event_flags);
63
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;
67
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();
72
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);
76
77   // Returns the number of child items if it has any (e.g. is a folder) or 0.
78   virtual size_t ChildItemCount() const;
79
80   // Utility functions for sync integration tests.
81   virtual bool CompareForTest(const AppListItem* other) const;
82   virtual std::string ToDebugString() const;
83
84  protected:
85   friend class AppListItemList;
86   friend class AppListItemListTest;
87   friend class AppListModel;
88
89   void set_position(const syncer::StringOrdinal& new_position) {
90     DCHECK(new_position.IsValid());
91     position_ = new_position;
92   }
93
94   void set_folder_id(const std::string& folder_id) { folder_id_ = folder_id; }
95
96  private:
97   friend class AppListModelTest;
98
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_;
103   bool has_shadow_;
104   std::string title_;
105   std::string full_name_;
106   bool highlighted_;
107   bool is_installing_;
108   int percent_downloaded_;
109
110   ObserverList<AppListItemObserver> observers_;
111
112   DISALLOW_COPY_AND_ASSIGN(AppListItem);
113 };
114
115 }  // namespace app_list
116
117 #endif  // UI_APP_LIST_APP_LIST_ITEM_H_