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