- add sources.
[platform/framework/web/crosswalk.git] / src / ui / app_list / app_list_item_model.h
1 // Copyright (c) 2012 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_MODEL_H_
6 #define UI_APP_LIST_APP_LIST_ITEM_MODEL_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 AppListItemModelObserver;
23
24 // AppListItemModel provides icon and title to be shown in a AppListItemView
25 // and action to be executed when the AppListItemView is activated.
26 class APP_LIST_EXPORT AppListItemModel {
27  public:
28   explicit AppListItemModel(const std::string& id);
29   virtual ~AppListItemModel();
30
31   void SetIcon(const gfx::ImageSkia& icon, bool has_shadow);
32   const gfx::ImageSkia& icon() const { return icon_; }
33   bool has_shadow() const { return has_shadow_; }
34
35   void SetTitleAndFullName(const std::string& title,
36                            const std::string& full_name);
37   const std::string& title() const { return title_; }
38   const std::string& full_name() const { return full_name_; }
39
40   void SetHighlighted(bool highlighted);
41   bool highlighted() const { return highlighted_; }
42
43   void SetIsInstalling(bool is_installing);
44   bool is_installing() const { return is_installing_; }
45
46   void SetPercentDownloaded(int percent_downloaded);
47   int percent_downloaded() const { return percent_downloaded_; }
48
49   const std::string& id() const { return id_; }
50   const syncer::StringOrdinal& position() const { return position_; }
51   void set_position(const syncer::StringOrdinal& new_position) {
52     DCHECK(new_position.IsValid());
53     position_ = new_position;
54   }
55
56   void AddObserver(AppListItemModelObserver* observer);
57   void RemoveObserver(AppListItemModelObserver* observer);
58
59   // Activates (opens) the item. Does nothing by default.
60   virtual void Activate(int event_flags);
61
62   // Returns a static const char* identifier for the subclass (defaults to "").
63   // Pointers can be compared for quick type checking.
64   virtual const char* GetAppType() const;
65
66   // Returns the context menu model for this item, or NULL if there is currently
67   // no menu for the item (e.g. during install).
68   // Note the returned menu model is owned by this item.
69   virtual ui::MenuModel* GetContextMenuModel();
70
71  private:
72   friend class AppListModelTest;
73
74   const std::string id_;
75   syncer::StringOrdinal position_;
76   gfx::ImageSkia icon_;
77   bool has_shadow_;
78   std::string title_;
79   std::string full_name_;
80   bool highlighted_;
81   bool is_installing_;
82   int percent_downloaded_;
83
84   ObserverList<AppListItemModelObserver> observers_;
85
86   DISALLOW_COPY_AND_ASSIGN(AppListItemModel);
87 };
88
89 }  // namespace app_list
90
91 #endif  // UI_APP_LIST_APP_LIST_ITEM_MODEL_H_