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() {
21 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemBeingDestroyed());
24 void AppListItem::SetIcon(const gfx::ImageSkia
& icon
, bool has_shadow
) {
26 has_shadow_
= has_shadow
;
27 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemIconChanged());
30 void AppListItem::SetHighlighted(bool highlighted
) {
31 if (highlighted_
== highlighted
)
34 highlighted_
= highlighted
;
35 FOR_EACH_OBSERVER(AppListItemObserver
,
37 ItemHighlightedChanged());
40 void AppListItem::SetIsInstalling(bool is_installing
) {
41 if (is_installing_
== is_installing
)
44 is_installing_
= is_installing
;
45 FOR_EACH_OBSERVER(AppListItemObserver
,
47 ItemIsInstallingChanged());
50 void AppListItem::SetPercentDownloaded(int percent_downloaded
) {
51 if (percent_downloaded_
== percent_downloaded
)
54 percent_downloaded_
= percent_downloaded
;
55 FOR_EACH_OBSERVER(AppListItemObserver
,
57 ItemPercentDownloadedChanged());
60 void AppListItem::AddObserver(AppListItemObserver
* observer
) {
61 observers_
.AddObserver(observer
);
64 void AppListItem::RemoveObserver(AppListItemObserver
* observer
) {
65 observers_
.RemoveObserver(observer
);
68 void AppListItem::Activate(int event_flags
) {
71 const char* AppListItem::GetItemType() const {
72 static const char* app_type
= "";
76 ui::MenuModel
* AppListItem::GetContextMenuModel() {
80 AppListItem
* AppListItem::FindChildItem(const std::string
& id
) {
84 size_t AppListItem::ChildItemCount() const {
88 void AppListItem::OnExtensionPreferenceChanged() {}
90 bool AppListItem::CompareForTest(const AppListItem
* other
) const {
91 return id_
== other
->id_
&&
92 folder_id_
== other
->folder_id_
&&
93 name_
== other
->name_
&&
94 short_name_
== other
->short_name_
&&
95 GetItemType() == other
->GetItemType() &&
96 position_
.Equals(other
->position_
);
99 std::string
AppListItem::ToDebugString() const {
100 return id_
.substr(0, 8) + " '" + name_
+ "'"
101 + " [" + position_
.ToDebugString() + "]";
106 void AppListItem::SetName(const std::string
& name
) {
107 if (name_
== name
&& (short_name_
.empty() || short_name_
== name
))
111 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemNameChanged());
114 void AppListItem::SetNameAndShortName(const std::string
& name
,
115 const std::string
& short_name
) {
116 if (name_
== name
&& short_name_
== short_name
)
119 short_name_
= short_name
;
120 FOR_EACH_OBSERVER(AppListItemObserver
, observers_
, ItemNameChanged());
123 } // namespace app_list