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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 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/arc_app_item.h"
6
7 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
8 #include "components/arc/arc_bridge_service.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "extensions/browser/app_sorting.h"
11 #include "extensions/browser/extension_prefs.h"
12 #include "ui/app_list/app_list_constants.h"
13 #include "ui/gfx/color_utils.h"
14 #include "ui/gfx/image/image_skia_operations.h"
15
16 namespace {
17
18 gfx::ImageSkia CreateDisabledIcon(const gfx::ImageSkia& icon) {
19 const color_utils::HSL shift = {-1, 0, 0.6};
20 return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift);
21 }
22
23 extensions::AppSorting* GetAppSorting(content::BrowserContext* context) {
24 return extensions::ExtensionPrefs::Get(context)->app_sorting();
25 }
26
27 } // namespace
28
29 // static
30 const char ArcAppItem::kItemType[] = "ArcAppItem";
31
32 ArcAppItem::ArcAppItem(
33 content::BrowserContext* context,
34 const app_list::AppListSyncableService::SyncItem* sync_item,
35 const std::string& id,
36 const std::string& name,
37 bool ready)
38 : app_list::AppListItem(id),
39 context_(context),
40 ready_(ready) {
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
42
43 arc_app_icon_.reset(new ArcAppIcon(context_,
44 id,
45 app_list::kGridIconDimension,
46 this));
47
48 SetName(name);
49 UpdateIcon();
50
51 if (sync_item && sync_item->item_ordinal.IsValid()) {
52 // An existing synced position exists, use that.
53 set_position(sync_item->item_ordinal);
54 } else {
55 // There is an ExtensionAppItem that uses extension::AppSorting to order
56 // its element. There is no commonly available sorting mechanism for app
57 // ordering so use the only one available from extension subsystem.
58 // Page is is the earliest non-full page.
59 const syncer::StringOrdinal& page =
60 GetAppSorting(context_)->GetNaturalAppPageOrdinal();
61 // And get next available pos in this page.
62 const syncer::StringOrdinal& pos =
63 GetAppSorting(context_)->CreateNextAppLaunchOrdinal(page);
64 set_position(pos);
65 }
66 }
67
68 ArcAppItem::~ArcAppItem() {
69 }
70
71 const char* ArcAppItem::GetItemType() const {
72 return ArcAppItem::kItemType;
73 }
74
75 void ArcAppItem::Activate(int event_flags) {
76 DCHECK(ready_);
77
78 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(context_);
79 scoped_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(id());
80 if (!app_info) {
81 VLOG(2) << "Cannot launch unavailable app:" << id() << ".";
82 return;
83 }
84
85 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
86 if (!bridge_service ||
87 bridge_service->state() != arc::ArcBridgeService::State::READY) {
88 VLOG(2) << "Cannot launch app: " << app_info->package
89 << ". Bridge service is not ready.";
90 return;
91 }
92
93 bridge_service->LaunchApp(app_info->package, app_info->activity);
94 }
95
96 void ArcAppItem::SetReady(bool ready) {
97 if (ready_ == ready)
98 return;
99
100 ready_ = ready;
101 UpdateIcon();
102 }
103
104 void ArcAppItem::SetName(const std::string& name) {
105 SetNameAndShortName(name, name);
106 }
107
108 void ArcAppItem::UpdateIcon() {
109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
110
111 gfx::ImageSkia icon = arc_app_icon_->image_skia();
112 if (!ready_)
113 icon = CreateDisabledIcon(icon);
114
115 SetIcon(icon);
116 }
117
118 void ArcAppItem::OnIconUpdated() {
119 UpdateIcon();
120 }
OLDNEW
« 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