Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / app_list_item.cc
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 #include "ui/app_list/app_list_item.h"
6
7 #include "base/logging.h"
8 #include "ui/app_list/app_list_item_observer.h"
9
10 namespace app_list {
11
12 AppListItem::AppListItem(const std::string& id)
13     : id_(id),
14       has_shadow_(false),
15       highlighted_(false),
16       is_installing_(false),
17       percent_downloaded_(-1) {
18 }
19
20 AppListItem::~AppListItem() {
21   FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemBeingDestroyed());
22 }
23
24 void AppListItem::SetIcon(const gfx::ImageSkia& icon, bool has_shadow) {
25   icon_ = icon;
26   has_shadow_ = has_shadow;
27   FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemIconChanged());
28 }
29
30 void AppListItem::SetIsInstalling(bool is_installing) {
31   if (is_installing_ == is_installing)
32     return;
33
34   is_installing_ = is_installing;
35   FOR_EACH_OBSERVER(AppListItemObserver,
36                     observers_,
37                     ItemIsInstallingChanged());
38 }
39
40 void AppListItem::SetPercentDownloaded(int percent_downloaded) {
41   if (percent_downloaded_ == percent_downloaded)
42     return;
43
44   percent_downloaded_ = percent_downloaded;
45   FOR_EACH_OBSERVER(AppListItemObserver,
46                     observers_,
47                     ItemPercentDownloadedChanged());
48 }
49
50 void AppListItem::AddObserver(AppListItemObserver* observer) {
51   observers_.AddObserver(observer);
52 }
53
54 void AppListItem::RemoveObserver(AppListItemObserver* observer) {
55   observers_.RemoveObserver(observer);
56 }
57
58 void AppListItem::Activate(int event_flags) {
59 }
60
61 const char* AppListItem::GetItemType() const {
62   static const char* app_type = "";
63   return app_type;
64 }
65
66 ui::MenuModel* AppListItem::GetContextMenuModel() {
67   return NULL;
68 }
69
70 AppListItem* AppListItem::FindChildItem(const std::string& id) {
71   return NULL;
72 }
73
74 size_t AppListItem::ChildItemCount() const {
75   return 0;
76 }
77
78 void AppListItem::OnExtensionPreferenceChanged() {}
79
80 bool AppListItem::CompareForTest(const AppListItem* other) const {
81   return id_ == other->id_ &&
82       folder_id_ == other->folder_id_ &&
83       name_ == other->name_ &&
84       short_name_ == other->short_name_ &&
85       GetItemType() == other->GetItemType() &&
86       position_.Equals(other->position_);
87 }
88
89 std::string AppListItem::ToDebugString() const {
90   return id_.substr(0, 8) + " '" + name_ + "'"
91       + " [" + position_.ToDebugString() + "]";
92 }
93
94 // Protected methods
95
96 void AppListItem::SetName(const std::string& name) {
97   if (name_ == name && (short_name_.empty() || short_name_ == name))
98     return;
99   name_ = name;
100   short_name_.clear();
101   FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemNameChanged());
102 }
103
104 void AppListItem::SetNameAndShortName(const std::string& name,
105                                       const std::string& short_name) {
106   if (name_ == name && short_name_ == short_name)
107     return;
108   name_ = name;
109   short_name_ = short_name;
110   FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemNameChanged());
111 }
112
113 }  // namespace app_list