Chromium Code Reviews| Index: chrome/browser/ui/app_list/chrome_app_list_item.cc |
| diff --git a/chrome/browser/ui/app_list/chrome_app_list_item.cc b/chrome/browser/ui/app_list/chrome_app_list_item.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..24ca68d674c4793b73137a6363e6fbc3398fc5ae |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/chrome_app_list_item.cc |
| @@ -0,0 +1,61 @@ |
| +// 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/chrome_app_list_item.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/app_list/app_list_service.h" |
| +#include "chrome/browser/ui/host_desktop.h" |
| +#include "extensions/browser/app_sorting.h" |
| +#include "extensions/browser/extension_system.h" |
| +#include "ui/gfx/color_utils.h" |
| +#include "ui/gfx/image/image_skia_operations.h" |
| + |
| +// static |
| +gfx::ImageSkia ChromeAppListItem::CreateDisabledIcon( |
| + const gfx::ImageSkia& icon) { |
| + const color_utils::HSL shift = {-1, 0, 0.6}; |
| + return gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); |
| +} |
| + |
| +ChromeAppListItem::ChromeAppListItem(Profile* profile, |
| + const std::string& app_id) |
| + : app_list::AppListItem(app_id), |
| + profile_(profile) { |
| +} |
| + |
| +ChromeAppListItem::~ChromeAppListItem() { |
| +} |
| + |
| +extensions::AppSorting* ChromeAppListItem::GetAppSorting() { |
| + return extensions::ExtensionSystem::Get(profile())->app_sorting(); |
| +} |
| + |
| +void ChromeAppListItem::UpdateFromSync( |
| + const app_list::AppListSyncableService::SyncItem* sync_item) { |
| + if (sync_item && sync_item->item_ordinal.IsValid()) { |
| + // An existing synced position exists, use that. |
| + set_position(sync_item->item_ordinal); |
| + // Only set the name from the sync item if it is empty. |
| + if (name().empty()) |
| + SetName(sync_item->item_name); |
| + } else { |
| + GetAppSorting()->EnsureValidOrdinals(id(), syncer::StringOrdinal()); |
|
xiyuan
2015/12/10 05:21:13
EnsureValidOrdinals() has side effects of updating
khmel1
2015/12/10 09:07:31
Yes, I see that is important. Reverted to original
|
| + UpdatePositionFromOrdering(); |
| + } |
| +} |
| + |
| +void ChromeAppListItem::UpdatePositionFromOrdering() { |
| + const syncer::StringOrdinal& page = |
| + GetAppSorting()->GetPageOrdinal(id()); |
| + const syncer::StringOrdinal& launch = |
| + GetAppSorting()->GetAppLaunchOrdinal(id()); |
| + set_position(syncer::StringOrdinal( |
| + page.ToInternalValue() + launch.ToInternalValue())); |
| +} |
| + |
| +AppListControllerDelegate* ChromeAppListItem::GetController() { |
| + return AppListService::Get(chrome::GetActiveDesktop())-> |
| + GetControllerDelegate(); |
| +} |