OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 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 "chrome/browser/ui/app_list/arc_app_item.h" |
| 6 |
| 7 #include "chrome/browser/ui/app_list/arc_app_prefs.h" |
| 8 #include "components/arc/arc_bridge_service.h" |
| 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "ui/app_list/app_list_constants.h" |
| 11 #include "ui/gfx/color_utils.h" |
| 12 #include "ui/gfx/image/image_skia_operations.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 gfx::ImageSkia CreateDisabledIcon(const gfx::ImageSkia& icon) { |
| 17 const color_utils::HSL shift = {-1, 0, 0.6}; |
| 18 return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 // static |
| 24 const char ArcAppItem::kItemType[] = "ArcAppItem"; |
| 25 |
| 26 ArcAppItem::ArcAppItem( |
| 27 content::BrowserContext* context, |
| 28 const app_list::AppListSyncableService::SyncItem* sync_item, |
| 29 const std::string& id, |
| 30 const std::string& name, |
| 31 bool ready) |
| 32 : app_list::AppListItem(id), |
| 33 context_(context), |
| 34 ready_(ready) { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 36 |
| 37 arc_app_icon_.reset(new ArcAppIcon(context_, |
| 38 id, |
| 39 app_list::kGridIconDimension, |
| 40 this)); |
| 41 |
| 42 SetName(name); |
| 43 UpdateIcon(); |
| 44 |
| 45 if (sync_item && sync_item->item_ordinal.IsValid()) { |
| 46 // An existing synced position exists, use that. |
| 47 set_position(sync_item->item_ordinal); |
| 48 } else { |
| 49 // Use default position and new item will be added to the last if the item |
| 50 // does not have sync data. |
| 51 } |
| 52 } |
| 53 |
| 54 ArcAppItem::~ArcAppItem() { |
| 55 } |
| 56 |
| 57 const char* ArcAppItem::GetItemType() const { |
| 58 return ArcAppItem::kItemType; |
| 59 } |
| 60 |
| 61 void ArcAppItem::Activate(int event_flags) { |
| 62 DCHECK(ready_); |
| 63 |
| 64 ArcAppPrefs* prefs = ArcAppPrefs::Get(context_); |
| 65 scoped_ptr<ArcAppPrefs::AppInfo> app_info = prefs->GetApp(id()); |
| 66 if (!app_info) { |
| 67 LOG(ERROR) << "Cannot launch unavailable app:" << id() << "."; |
| 68 return; |
| 69 } |
| 70 |
| 71 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 72 if (!bridge_service || |
| 73 bridge_service->state() != arc::ArcBridgeService::State::READY) { |
| 74 LOG(ERROR) << "Cannot launch app: " << app_info->package |
| 75 << ". Bridge service is not ready."; |
| 76 return; |
| 77 } |
| 78 |
| 79 bridge_service->LaunchApp(app_info->package, app_info->activity); |
| 80 } |
| 81 |
| 82 void ArcAppItem::SetReady(bool ready) { |
| 83 if (ready_ == ready) { |
| 84 return; |
| 85 } |
| 86 ready_ = ready; |
| 87 UpdateIcon(); |
| 88 } |
| 89 |
| 90 void ArcAppItem::SetName(const std::string& name) { |
| 91 SetNameAndShortName(name, name); |
| 92 } |
| 93 |
| 94 void ArcAppItem::UpdateIcon() { |
| 95 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 96 |
| 97 gfx::ImageSkia icon = arc_app_icon_->image_skia(); |
| 98 if (!ready_) { |
| 99 icon = CreateDisabledIcon(icon); |
| 100 } |
| 101 |
| 102 SetIcon(icon); |
| 103 } |
| 104 |
| 105 void ArcAppItem::OnIconUpdated() { |
| 106 UpdateIcon(); |
| 107 } |
OLD | NEW |