Index: chrome/browser/ui/app_list/arc_app_item.cc |
diff --git a/chrome/browser/ui/app_list/arc_app_item.cc b/chrome/browser/ui/app_list/arc_app_item.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..922117696dac7992361be25799380164eded17e3 |
--- /dev/null |
+++ b/chrome/browser/ui/app_list/arc_app_item.cc |
@@ -0,0 +1,107 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/app_list/arc_app_item.h" |
+ |
+#include "chrome/browser/ui/app_list/arc_app_prefs.h" |
+#include "components/arc/arc_bridge_service.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "ui/app_list/app_list_constants.h" |
+#include "ui/gfx/color_utils.h" |
+#include "ui/gfx/image/image_skia_operations.h" |
+ |
+namespace { |
+ |
+gfx::ImageSkia CreateDisabledIcon(const gfx::ImageSkia& icon) { |
+ const color_utils::HSL shift = {-1, 0, 0.6}; |
+ return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); |
+} |
+ |
+} // namespace |
+ |
+// static |
+const char ArcAppItem::kItemType[] = "ArcAppItem"; |
+ |
+ArcAppItem::ArcAppItem( |
+ content::BrowserContext* context, |
+ const app_list::AppListSyncableService::SyncItem* sync_item, |
+ const std::string& id, |
+ const std::string& name, |
+ bool ready) |
+ : app_list::AppListItem(id), |
+ context_(context), |
+ ready_(ready) { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ |
+ arc_app_icon_.reset(new ArcAppIcon(context_, |
+ id, |
+ app_list::kGridIconDimension, |
+ this)); |
+ |
+ SetName(name); |
+ UpdateIcon(); |
+ |
+ if (sync_item && sync_item->item_ordinal.IsValid()) { |
+ // An existing synced position exists, use that. |
+ set_position(sync_item->item_ordinal); |
+ } else { |
+ // Use default position and new item will be added to the last if the item |
+ // does not have sync data. |
+ } |
+} |
+ |
+ArcAppItem::~ArcAppItem() { |
+} |
+ |
+const char* ArcAppItem::GetItemType() const { |
+ return ArcAppItem::kItemType; |
+} |
+ |
+void ArcAppItem::Activate(int event_flags) { |
+ DCHECK(ready_); |
+ |
+ ArcAppPrefs* prefs = ArcAppPrefs::Get(context_); |
+ scoped_ptr<ArcAppPrefs::AppInfo> app_info = prefs->GetApp(id()); |
+ if (!app_info) { |
+ LOG(ERROR) << "Cannot launch unavailable app:" << id() << "."; |
+ return; |
+ } |
+ |
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
+ if (!bridge_service || |
+ bridge_service->state() != arc::ArcBridgeService::State::READY) { |
+ LOG(ERROR) << "Cannot launch app: " << app_info->package |
+ << ". Bridge service is not ready."; |
+ return; |
+ } |
+ |
+ bridge_service->LaunchApp(app_info->package, app_info->activity); |
+} |
+ |
+void ArcAppItem::SetReady(bool ready) { |
+ if (ready_ == ready) { |
+ return; |
+ } |
+ ready_ = ready; |
+ UpdateIcon(); |
+} |
+ |
+void ArcAppItem::SetName(const std::string& name) { |
+ SetNameAndShortName(name, name); |
+} |
+ |
+void ArcAppItem::UpdateIcon() { |
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ |
+ gfx::ImageSkia icon = arc_app_icon_->image_skia(); |
+ if (!ready_) { |
+ icon = CreateDisabledIcon(icon); |
+ } |
+ |
+ SetIcon(icon); |
+} |
+ |
+void ArcAppItem::OnIconUpdated() { |
+ UpdateIcon(); |
+} |