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 FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemBeingDestroyed()); 22} 23 24void 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 30void AppListItem::SetHighlighted(bool highlighted) { 31 if (highlighted_ == highlighted) 32 return; 33 34 highlighted_ = highlighted; 35 FOR_EACH_OBSERVER(AppListItemObserver, 36 observers_, 37 ItemHighlightedChanged()); 38} 39 40void AppListItem::SetIsInstalling(bool is_installing) { 41 if (is_installing_ == is_installing) 42 return; 43 44 is_installing_ = is_installing; 45 FOR_EACH_OBSERVER(AppListItemObserver, 46 observers_, 47 ItemIsInstallingChanged()); 48} 49 50void AppListItem::SetPercentDownloaded(int percent_downloaded) { 51 if (percent_downloaded_ == percent_downloaded) 52 return; 53 54 percent_downloaded_ = percent_downloaded; 55 FOR_EACH_OBSERVER(AppListItemObserver, 56 observers_, 57 ItemPercentDownloadedChanged()); 58} 59 60void AppListItem::AddObserver(AppListItemObserver* observer) { 61 observers_.AddObserver(observer); 62} 63 64void AppListItem::RemoveObserver(AppListItemObserver* observer) { 65 observers_.RemoveObserver(observer); 66} 67 68void AppListItem::Activate(int event_flags) { 69} 70 71const char* AppListItem::GetItemType() const { 72 static const char* app_type = ""; 73 return app_type; 74} 75 76ui::MenuModel* AppListItem::GetContextMenuModel() { 77 return NULL; 78} 79 80AppListItem* AppListItem::FindChildItem(const std::string& id) { 81 return NULL; 82} 83 84size_t AppListItem::ChildItemCount() const { 85 return 0; 86} 87 88void AppListItem::OnExtensionPreferenceChanged() {} 89 90bool 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_); 97} 98 99std::string AppListItem::ToDebugString() const { 100 return id_.substr(0, 8) + " '" + name_ + "'" 101 + " [" + position_.ToDebugString() + "]"; 102} 103 104// Protected methods 105 106void AppListItem::SetName(const std::string& name) { 107 if (name_ == name && (short_name_.empty() || short_name_ == name)) 108 return; 109 name_ = name; 110 short_name_.clear(); 111 FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemNameChanged()); 112} 113 114void AppListItem::SetNameAndShortName(const std::string& name, 115 const std::string& short_name) { 116 if (name_ == name && short_name_ == short_name) 117 return; 118 name_ = name; 119 short_name_ = short_name; 120 FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemNameChanged()); 121} 122 123} // namespace app_list 124