Chromium Code Reviews| 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..2d70b81fe2c9af178a3bf56ec3a4fdd602c942ca |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/arc_app_item.cc |
| @@ -0,0 +1,105 @@ |
| +// 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/gfx/color_utils.h" |
| +#include "ui/gfx/image/image_skia_operations.h" |
| + |
| +namespace { |
| + |
| +const int kIconDimension = 48; |
|
xiyuan
2015/11/11 22:15:50
Should we use app_list::kGridIconDimension instead
khmel1
2015/11/12 08:05:29
Yes. this is much better. I used extension icon as
|
| + |
| +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); |
| + |
| + icon_.reset(new ArcAppIcon(context_, id, kIconDimension, 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 { |
| + // TODO(khmel): Investigate how to integrate with extensions::AppSorting |
| + set_position(syncer::StringOrdinal("nq")); |
|
xiyuan
2015/11/11 22:15:50
Can we leave position unset instead of using a har
khmel1
2015/11/12 08:05:29
Done.
|
| + } |
| +} |
| + |
| +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()); |
| + DCHECK(app_info != nullptr); |
|
xiyuan
2015/11/11 22:15:50
nit: DCHECK_NE(app_info, nullptr)
khmel1
2015/11/12 08:05:29
Done. Added LOG(ERROR) below
|
| + if (!app_info) { |
| + 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 = icon_->image_skia(); |
| + if (!ready_) { |
| + icon = CreateDisabledIcon(icon); |
| + } |
| + |
| + SetIcon(icon); |
| +} |
| + |
| +void ArcAppItem::OnIconUpdated() { |
|
xiyuan
2015/11/11 22:15:50
ArcAppItem should observe its |icon_|. Otherwise,
khmel1
2015/11/12 08:05:30
Sorry, I don't understand clear you. When I create
xiyuan
2015/11/12 17:32:44
You are right. ArcAppItem is passed in |arc_app_ic
|
| + UpdateIcon(); |
| +} |