Home | History | Annotate | Download | only in app_list
      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 
     10 namespace app_list {
     11 
     12 AppListItem::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 
     20 AppListItem::~AppListItem() {
     21 }
     22 
     23 void 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 
     29 void 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 
     39 void 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 
     49 void 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 
     59 void AppListItem::AddObserver(AppListItemObserver* observer) {
     60   observers_.AddObserver(observer);
     61 }
     62 
     63 void AppListItem::RemoveObserver(AppListItemObserver* observer) {
     64   observers_.RemoveObserver(observer);
     65 }
     66 
     67 void AppListItem::Activate(int event_flags) {
     68 }
     69 
     70 const char* AppListItem::GetItemType() const {
     71   static const char* app_type = "";
     72   return app_type;
     73 }
     74 
     75 ui::MenuModel* AppListItem::GetContextMenuModel() {
     76   return NULL;
     77 }
     78 
     79 AppListItem* AppListItem::FindChildItem(const std::string& id) {
     80   return NULL;
     81 }
     82 
     83 size_t AppListItem::ChildItemCount() const {
     84   return 0;
     85 }
     86 
     87 void AppListItem::OnExtensionPreferenceChanged() {}
     88 
     89 bool 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 
     98 std::string AppListItem::ToDebugString() const {
     99   return id_.substr(0, 8) + " '" + name_ + "'"
    100       + " [" + position_.ToDebugString() + "]";
    101 }
    102 
    103 // Protected methods
    104 
    105 void 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 
    113 void 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