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.
5 #ifndef UI_APP_LIST_APP_LIST_ITEM_MODEL_H_
6 #define UI_APP_LIST_APP_LIST_ITEM_MODEL_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 AppListItemModelObserver;
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 {
28 explicit AppListItemModel(const std::string& id);
29 virtual ~AppListItemModel();
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_; }
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_; }
40 void SetHighlighted(bool highlighted);
41 bool highlighted() const { return highlighted_; }
43 void SetIsInstalling(bool is_installing);
44 bool is_installing() const { return is_installing_; }
46 void SetPercentDownloaded(int percent_downloaded);
47 int percent_downloaded() const { return percent_downloaded_; }
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;
56 void AddObserver(AppListItemModelObserver* observer);
57 void RemoveObserver(AppListItemModelObserver* observer);
59 // Activates (opens) the item. Does nothing by default.
60 virtual void Activate(int event_flags);
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;
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();
72 friend class AppListModelTest;
74 const std::string id_;
75 syncer::StringOrdinal position_;
79 std::string full_name_;
82 int percent_downloaded_;
84 ObserverList<AppListItemModelObserver> observers_;
86 DISALLOW_COPY_AND_ASSIGN(AppListItemModel);
89 } // namespace app_list
91 #endif // UI_APP_LIST_APP_LIST_ITEM_MODEL_H_