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

Side by Side Diff: chrome/browser/ui/app_list/extension_app_item.cc

Issue 17038002: Separate the NTP app ordering from the app list app ordering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add sync test Created 7 years, 6 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/app_list/extension_app_item.h" 5 #include "chrome/browser/ui/app_list/extension_app_item.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/extensions/extension_prefs.h" 8 #include "chrome/browser/extensions/extension_prefs.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_sorting.h"
11 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/app_list/app_context_menu.h" 12 #include "chrome/browser/ui/app_list/app_context_menu.h"
14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
14 #include "chrome/browser/ui/app_list/app_list_extension_ordering.h"
15 #include "chrome/browser/ui/extensions/extension_enable_flow.h" 15 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
16 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 16 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/extensions/extension_icon_set.h" 19 #include "chrome/common/extensions/extension_icon_set.h"
20 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" 20 #include "chrome/common/extensions/manifest_handlers/icons_handler.h"
21 #include "chrome/common/extensions/manifest_url_handler.h" 21 #include "chrome/common/extensions/manifest_url_handler.h"
22 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
23 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
(...skipping 23 matching lines...) Expand all
48 const gfx::ImageSkia& overlay = *ui::ResourceBundle::GetSharedInstance(). 48 const gfx::ImageSkia& overlay = *ui::ResourceBundle::GetSharedInstance().
49 GetImageSkiaNamed(IDR_APP_LIST_TAB_OVERLAY); 49 GetImageSkiaNamed(IDR_APP_LIST_TAB_OVERLAY);
50 canvas->DrawImageInt(overlay, 0, icon_.height() - overlay.height()); 50 canvas->DrawImageInt(overlay, 0, icon_.height() - overlay.height());
51 } 51 }
52 52
53 gfx::ImageSkia icon_; 53 gfx::ImageSkia icon_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(ShortcutOverlayImageSource); 55 DISALLOW_COPY_AND_ASSIGN(ShortcutOverlayImageSource);
56 }; 56 };
57 57
58 ExtensionSorting* GetExtensionSorting(Profile* profile) { 58 AppListExtensionOrdering* GetExtensionOrdering(Profile* profile) {
59 ExtensionService* service = 59 ExtensionService* service =
60 extensions::ExtensionSystem::Get(profile)->extension_service(); 60 extensions::ExtensionSystem::Get(profile)->extension_service();
61 return service->extension_prefs()->extension_sorting(); 61 return service->extension_prefs()->app_list_extension_ordering();
62 } 62 }
63 63
64 const color_utils::HSL shift = {-1, 0, 0.6}; 64 const color_utils::HSL shift = {-1, 0, 0.6};
65 65
66 } // namespace 66 } // namespace
67 67
68 ExtensionAppItem::ExtensionAppItem(Profile* profile, 68 ExtensionAppItem::ExtensionAppItem(Profile* profile,
69 const std::string& extension_id, 69 const std::string& extension_id,
70 AppListControllerDelegate* controller, 70 AppListControllerDelegate* controller,
71 const std::string& extension_name, 71 const std::string& extension_name,
72 const gfx::ImageSkia& installing_icon, 72 const gfx::ImageSkia& installing_icon,
73 bool is_platform_app) 73 bool is_platform_app)
74 : ChromeAppListItem(TYPE_APP), 74 : ChromeAppListItem(TYPE_APP),
75 profile_(profile), 75 profile_(profile),
76 extension_id_(extension_id), 76 extension_id_(extension_id),
77 controller_(controller), 77 controller_(controller),
78 extension_name_(extension_name), 78 extension_name_(extension_name),
79 installing_icon_( 79 installing_icon_(
80 gfx::ImageSkiaOperations::CreateHSLShiftedImage(installing_icon, 80 gfx::ImageSkiaOperations::CreateHSLShiftedImage(installing_icon,
81 shift)), 81 shift)),
82 is_platform_app_(is_platform_app) { 82 is_platform_app_(is_platform_app) {
83 Reload(); 83 Reload();
84 GetExtensionSorting(profile_)->EnsureValidOrdinals(extension_id_, 84 AppListExtensionOrdering* ordering = GetExtensionOrdering(profile_);
85 syncer::StringOrdinal()); 85 if (!ordering->Contains(extension_id_))
86 ordering->InsertAtNextAvailable(extension_id_);
86 } 87 }
87 88
88 ExtensionAppItem::~ExtensionAppItem() { 89 ExtensionAppItem::~ExtensionAppItem() {
89 } 90 }
90 91
91 bool ExtensionAppItem::HasOverlay() const { 92 bool ExtensionAppItem::HasOverlay() const {
92 #if defined(OS_CHROMEOS) 93 #if defined(OS_CHROMEOS)
93 return false; 94 return false;
94 #else 95 #else
95 return !is_platform_app_ && extension_id_ != extension_misc::kChromeAppId; 96 return !is_platform_app_ && extension_id_ != extension_misc::kChromeAppId;
96 #endif 97 #endif
97 } 98 }
98 99
100 bool ExtensionAppItem::Precedes(const ExtensionAppItem* item) const {
101 return GetExtensionOrdering(profile_)->ExtensionPrecedes(
102 extension_id(), item->extension_id());
103 }
104
99 void ExtensionAppItem::Reload() { 105 void ExtensionAppItem::Reload() {
100 const Extension* extension = GetExtension(); 106 const Extension* extension = GetExtension();
101 bool is_installing = !extension; 107 bool is_installing = !extension;
102 SetIsInstalling(is_installing); 108 SetIsInstalling(is_installing);
103 set_app_id(extension_id_); 109 set_app_id(extension_id_);
104 if (is_installing) { 110 if (is_installing) {
105 SetTitle(extension_name_); 111 SetTitle(extension_name_);
106 UpdateIcon(); 112 UpdateIcon();
107 return; 113 return;
108 } 114 }
109 SetTitle(extension->name()); 115 SetTitle(extension->name());
110 LoadImage(extension); 116 LoadImage(extension);
111 } 117 }
112 118
113 syncer::StringOrdinal ExtensionAppItem::GetPageOrdinal() const {
114 return GetExtensionSorting(profile_)->GetPageOrdinal(extension_id_);
115 }
116
117 syncer::StringOrdinal ExtensionAppItem::GetAppLaunchOrdinal() const {
118 return GetExtensionSorting(profile_)->GetAppLaunchOrdinal(extension_id_);
119 }
120
121 void ExtensionAppItem::Move(const ExtensionAppItem* prev, 119 void ExtensionAppItem::Move(const ExtensionAppItem* prev,
122 const ExtensionAppItem* next) { 120 const ExtensionAppItem* next) {
123 // Does nothing if no predecessor nor successor. 121 // Does nothing if no predecessor nor successor.
124 if (!prev && !next) 122 if (!prev && !next)
125 return; 123 return;
126 124
127 ExtensionService* service = 125 ExtensionService* service =
128 extensions::ExtensionSystem::Get(profile_)->extension_service(); 126 extensions::ExtensionSystem::Get(profile_)->extension_service();
129 service->extension_prefs()->SetAppDraggedByUser(extension_id_); 127 service->extension_prefs()->SetAppDraggedByUser(extension_id_);
128 AppListExtensionOrdering* ordering = GetExtensionOrdering(profile_);
130 129
131 // Handles only predecessor or only successor case. 130 // Handles only predecessor or only successor case.
132 if (!prev || !next) { 131 GetExtensionOrdering(profile_)->OnExtensionMoved(
133 syncer::StringOrdinal page = prev ? prev->GetPageOrdinal() : 132 extension_id_,
134 next->GetPageOrdinal(); 133 prev ? prev->extension_id() : std::string(),
135 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, page); 134 next ? next->extension_id() : std::string());
136 service->OnExtensionMoved(extension_id_,
137 prev ? prev->extension_id() : std::string(),
138 next ? next->extension_id() : std::string());
139 return;
140 }
141
142 // Handles both predecessor and successor are on the same page.
143 syncer::StringOrdinal prev_page = prev->GetPageOrdinal();
144 syncer::StringOrdinal next_page = next->GetPageOrdinal();
145 if (prev_page.Equals(next_page)) {
146 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page);
147 service->OnExtensionMoved(extension_id_,
148 prev->extension_id(),
149 next->extension_id());
150 return;
151 }
152
153 // Otherwise, go with |next|. This is okay because app list does not split
154 // page based ntp page ordinal.
155 // TODO(xiyuan): Revisit this when implementing paging support.
156 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page);
157 service->OnExtensionMoved(extension_id_,
158 prev->extension_id(),
159 std::string());
160 } 135 }
161 136
162 void ExtensionAppItem::UpdateIcon() { 137 void ExtensionAppItem::UpdateIcon() {
163 if (!GetExtension()) { 138 if (!GetExtension()) {
164 gfx::ImageSkia icon = installing_icon_; 139 gfx::ImageSkia icon = installing_icon_;
165 if (HasOverlay()) 140 if (HasOverlay())
166 icon = gfx::ImageSkia(new ShortcutOverlayImageSource(icon), icon.size()); 141 icon = gfx::ImageSkia(new ShortcutOverlayImageSource(icon), icon.size());
167 SetIcon(icon, !HasOverlay()); 142 SetIcon(icon, !HasOverlay());
168 return; 143 return;
169 } 144 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 context_menu_.reset(new app_list::AppContextMenu( 242 context_menu_.reset(new app_list::AppContextMenu(
268 this, profile_, extension_id_, controller_, is_platform_app_)); 243 this, profile_, extension_id_, controller_, is_platform_app_));
269 } 244 }
270 245
271 return context_menu_->GetMenuModel(); 246 return context_menu_->GetMenuModel();
272 } 247 }
273 248
274 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) { 249 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) {
275 Launch(event_flags); 250 Launch(event_flags);
276 } 251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698