app_list_item.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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
10namespace app_list {
11
12AppListItem::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
20AppListItem::~AppListItem() {
21}
22
23void AppListItem::SetIcon(const gfx::ImageSkia& icon, bool has_shadow) {
24  icon_ = icon;
25  has_shadow_ = has_shadow;
26  FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemIconChanged());
27}
28
29void AppListItem::SetTitleAndFullName(const std::string& title,
30                                      const std::string& full_name) {
31  if (title_ == title && full_name_ == full_name)
32    return;
33
34  title_ = title;
35  full_name_ = full_name;
36  FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemTitleChanged());
37}
38
39void AppListItem::SetHighlighted(bool highlighted) {
40  if (highlighted_ == highlighted)
41    return;
42
43  highlighted_ = highlighted;
44  FOR_EACH_OBSERVER(AppListItemObserver,
45                    observers_,
46                    ItemHighlightedChanged());
47}
48
49void AppListItem::SetIsInstalling(bool is_installing) {
50  if (is_installing_ == is_installing)
51    return;
52
53  is_installing_ = is_installing;
54  FOR_EACH_OBSERVER(AppListItemObserver,
55                    observers_,
56                    ItemIsInstallingChanged());
57}
58
59void AppListItem::SetPercentDownloaded(int percent_downloaded) {
60  if (percent_downloaded_ == percent_downloaded)
61    return;
62
63  percent_downloaded_ = percent_downloaded;
64  FOR_EACH_OBSERVER(AppListItemObserver,
65                    observers_,
66                    ItemPercentDownloadedChanged());
67}
68
69void AppListItem::AddObserver(AppListItemObserver* observer) {
70  observers_.AddObserver(observer);
71}
72
73void AppListItem::RemoveObserver(AppListItemObserver* observer) {
74  observers_.RemoveObserver(observer);
75}
76
77void AppListItem::Activate(int event_flags) {
78}
79
80const char* AppListItem::GetItemType() const {
81  static const char* app_type = "";
82  return app_type;
83}
84
85ui::MenuModel* AppListItem::GetContextMenuModel() {
86  return NULL;
87}
88
89AppListItem* AppListItem::FindChildItem(const std::string& id) {
90  return NULL;
91}
92
93size_t AppListItem::ChildItemCount() const {
94  return 0;
95}
96
97bool AppListItem::CompareForTest(const AppListItem* other) const {
98  return id_ == other->id_ &&
99      folder_id_ == other->folder_id_ &&
100      title_ == other->title_ &&
101      GetItemType() == other->GetItemType() &&
102      position_.Equals(other->position_);
103}
104
105std::string AppListItem::ToDebugString() const {
106  return id_.substr(0, 8) + " '" + title_ + "'"
107      + " [" + position_.ToDebugString() + "]";
108}
109
110}  // namespace app_list
111