15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/app_list/app_list_item.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/logging.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/app_list/app_list_item_observer.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace app_list { 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AppListItem::AppListItem(const std::string& id) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : id_(id), 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) has_shadow_(false), 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) highlighted_(false), 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_installing_(false), 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) percent_downloaded_(-1) { 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AppListItem::~AppListItem() { 2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemBeingDestroyed()); 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AppListItem::SetIcon(const gfx::ImageSkia& icon, bool has_shadow) { 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) icon_ = icon; 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) has_shadow_ = has_shadow; 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemIconChanged()); 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AppListItem::SetHighlighted(bool highlighted) { 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (highlighted_ == highlighted) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) highlighted_ = highlighted; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FOR_EACH_OBSERVER(AppListItemObserver, 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_, 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ItemHighlightedChanged()); 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AppListItem::SetIsInstalling(bool is_installing) { 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (is_installing_ == is_installing) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) is_installing_ = is_installing; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FOR_EACH_OBSERVER(AppListItemObserver, 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_, 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ItemIsInstallingChanged()); 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AppListItem::SetPercentDownloaded(int percent_downloaded) { 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (percent_downloaded_ == percent_downloaded) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) percent_downloaded_ = percent_downloaded; 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FOR_EACH_OBSERVER(AppListItemObserver, 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_, 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ItemPercentDownloadedChanged()); 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AppListItem::AddObserver(AppListItemObserver* observer) { 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_.AddObserver(observer); 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AppListItem::RemoveObserver(AppListItemObserver* observer) { 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observers_.RemoveObserver(observer); 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AppListItem::Activate(int event_flags) { 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const char* AppListItem::GetItemType() const { 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const char* app_type = ""; 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return app_type; 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ui::MenuModel* AppListItem::GetContextMenuModel() { 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NULL; 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AppListItem* AppListItem::FindChildItem(const std::string& id) { 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NULL; 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)size_t AppListItem::ChildItemCount() const { 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return 0; 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void AppListItem::OnExtensionPreferenceChanged() {} 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AppListItem::CompareForTest(const AppListItem* other) const { 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return id_ == other->id_ && 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) folder_id_ == other->folder_id_ && 93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) name_ == other->name_ && 94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) short_name_ == other->short_name_ && 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetItemType() == other->GetItemType() && 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) position_.Equals(other->position_); 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)std::string AppListItem::ToDebugString() const { 100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return id_.substr(0, 8) + " '" + name_ + "'" 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) + " [" + position_.ToDebugString() + "]"; 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Protected methods 105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void AppListItem::SetName(const std::string& name) { 107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (name_ == name && (short_name_.empty() || short_name_ == name)) 108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) name_ = name; 110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) short_name_.clear(); 111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemNameChanged()); 112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void AppListItem::SetNameAndShortName(const std::string& name, 115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string& short_name) { 116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (name_ == name && short_name_ == short_name) 117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) name_ = name; 119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) short_name_ = short_name; 120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FOR_EACH_OBSERVER(AppListItemObserver, observers_, ItemNameChanged()); 121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace app_list 124