Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2745)

Unified Diff: chrome/browser/ui/app_list/arc/arc_app_item.cc

Issue 1413153007: arc-app-launcher: Minimal support for ARC app launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing links to BUILD.gn Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_item.h ('k') | chrome/browser/ui/app_list/arc/arc_app_list_prefs.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/app_list/arc/arc_app_item.cc
diff --git a/chrome/browser/ui/app_list/arc/arc_app_item.cc b/chrome/browser/ui/app_list/arc/arc_app_item.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2e1a312772dc77c5408d562880f36fa72fe8eb8b
--- /dev/null
+++ b/chrome/browser/ui/app_list/arc/arc_app_item.cc
@@ -0,0 +1,120 @@
+// Copyright 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/arc_app_item.h"
+
+#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
+#include "components/arc/arc_bridge_service.h"
+#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/app_sorting.h"
+#include "extensions/browser/extension_prefs.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);
+}
+
+extensions::AppSorting* GetAppSorting(content::BrowserContext* context) {
+ return extensions::ExtensionPrefs::Get(context)->app_sorting();
+}
+
+} // 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 {
+ // There is an ExtensionAppItem that uses extension::AppSorting to order
+ // its element. There is no commonly available sorting mechanism for app
+ // ordering so use the only one available from extension subsystem.
+ // Page is is the earliest non-full page.
+ const syncer::StringOrdinal& page =
+ GetAppSorting(context_)->GetNaturalAppPageOrdinal();
+ // And get next available pos in this page.
+ const syncer::StringOrdinal& pos =
+ GetAppSorting(context_)->CreateNextAppLaunchOrdinal(page);
+ set_position(pos);
+ }
+}
+
+ArcAppItem::~ArcAppItem() {
+}
+
+const char* ArcAppItem::GetItemType() const {
+ return ArcAppItem::kItemType;
+}
+
+void ArcAppItem::Activate(int event_flags) {
+ DCHECK(ready_);
+
+ ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_);
+ scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id());
+ if (!app_info) {
+ VLOG(2) << "Cannot launch unavailable app:" << id() << ".";
+ return;
+ }
+
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
+ if (!bridge_service ||
+ bridge_service->state() != arc::ArcBridgeService::State::READY) {
+ VLOG(2) << "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();
+}
« no previous file with comments | « chrome/browser/ui/app_list/arc/arc_app_item.h ('k') | chrome/browser/ui/app_list/arc/arc_app_list_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698