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 #include "ui/app_list/app_list_item.h"
7 #include "base/logging.h"
8 #include "ui/app_list/app_list_item_observer.h"
12 AppListItem::AppListItem(const std::string
& id
)
16 is_installing_(false),
17 percent_downloaded_(-1) {
20 AppListItem::~AppListItem() {
23 void AppListItem::SetIcon(const gfx::ImageSkia
& icon
, bool has_shadow
) {
25 has_shadow_
= has_shadow
;
26 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemIconChanged());
29 void AppListItem::SetHighlighted(bool highlighted
) {
30 if (highlighted_
== highlighted
)
33 highlighted_
= highlighted
;
34 FOR_EACH_OBSERVER(AppListItemObserver
,
36 ItemHighlightedChanged());
39 void AppListItem::SetIsInstalling(bool is_installing
) {
40 if (is_installing_
== is_installing
)
43 is_installing_
= is_installing
;
44 FOR_EACH_OBSERVER(AppListItemObserver
,
46 ItemIsInstallingChanged());
49 void AppListItem::SetPercentDownloaded(int percent_downloaded
) {
50 if (percent_downloaded_
== percent_downloaded
)
53 percent_downloaded_
= percent_downloaded
;
54 FOR_EACH_OBSERVER(AppListItemObserver
,
56 ItemPercentDownloadedChanged());
59 void AppListItem::AddObserver(AppListItemObserver
* observer
) {
60 observers_
.AddObserver(observer
);
63 void AppListItem::RemoveObserver(AppListItemObserver
* observer
) {
64 observers_
.RemoveObserver(observer
);
67 void AppListItem::Activate(int event_flags
) {
70 const char* AppListItem::GetItemType() const {
71 static const char* app_type
= "";
75 ui::MenuModel
* AppListItem::GetContextMenuModel() {
79 AppListItem
* AppListItem::FindChildItem(const std::string
& id
) {
83 size_t AppListItem::ChildItemCount() const {
87 void AppListItem::OnExtensionPreferenceChanged() {}
89 bool AppListItem::CompareForTest(const AppListItem
* other
) const {
90 return id_
== other
->id_
&&
91 folder_id_
== other
->folder_id_
&&
92 name_
== other
->name_
&&
93 short_name_
== other
->short_name_
&&
94 GetItemType() == other
->GetItemType() &&
95 position_
.Equals(other
->position_
);
98 std::string
AppListItem::ToDebugString() const {
99 return id_
.substr(0, 8) + " '" + name_
+ "'"
100 + " [" + position_
.ToDebugString() + "]";
105 void AppListItem::SetName(const std::string
& name
) {
106 if (name_
== name
&& (short_name_
.empty() || short_name_
== name
))
110 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemNameChanged());
113 void AppListItem::SetNameAndShortName(const std::string
& name
,
114 const std::string
& short_name
) {
115 if (name_
== name
&& short_name_
== short_name
)
118 short_name_
= short_name
;
119 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemNameChanged());
122 } // namespace app_list