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

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

Issue 13813004: Add new overlay for v1 apps in the launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 years, 8 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
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/extensions/context_menu_matcher.h" 9 #include "chrome/browser/extensions/context_menu_matcher.h"
10 #include "chrome/browser/extensions/extension_prefs.h" 10 #include "chrome/browser/extensions/extension_prefs.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 110 }
111 111
112 Profile* profile_; 112 Profile* profile_;
113 std::string extension_id_; 113 std::string extension_id_;
114 AppListControllerDelegate* controller_; 114 AppListControllerDelegate* controller_;
115 scoped_ptr<ExtensionUninstallDialog> dialog_; 115 scoped_ptr<ExtensionUninstallDialog> dialog_;
116 116
117 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstaller); 117 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstaller);
118 }; 118 };
119 119
120 class TabOverlayImageSource : public gfx::CanvasImageSource { 120 // Overlays a shortcut icon over the bottom left corner of a given image.
121 class ShortcutOverlayImageSource : public gfx::CanvasImageSource {
121 public: 122 public:
122 TabOverlayImageSource(const gfx::ImageSkia& icon, const gfx::Size& size) 123 explicit ShortcutOverlayImageSource(const gfx::ImageSkia& icon)
123 : gfx::CanvasImageSource(size, false), 124 : gfx::CanvasImageSource(icon.size(), false),
124 icon_(icon) { 125 icon_(icon) {
125 if (!icon_.isNull()) {
126 DCHECK_EQ(extension_misc::EXTENSION_ICON_SMALL, icon_.width());
127 DCHECK_EQ(extension_misc::EXTENSION_ICON_SMALL, icon_.height());
128 }
129 } 126 }
130 virtual ~TabOverlayImageSource() {} 127 virtual ~ShortcutOverlayImageSource() {}
131 128
132 private: 129 private:
133 // gfx::CanvasImageSource overrides: 130 // gfx::CanvasImageSource overrides:
134 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { 131 virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
135 using extension_misc::EXTENSION_ICON_SMALL; 132 canvas->DrawImageInt(icon_, 0, 0);
136 using extension_misc::EXTENSION_ICON_MEDIUM;
137 133
138 const int kIconOffset = (EXTENSION_ICON_MEDIUM - EXTENSION_ICON_SMALL) / 2; 134 // Draw the overlay in the bottom left corner of the icon.
139 135 const gfx::ImageSkia& overlay = *ui::ResourceBundle::GetSharedInstance().
140 // The tab overlay is not vertically symmetric, to position the app in the 136 GetImageSkiaNamed(IDR_APP_LIST_TAB_OVERLAY);
141 // middle of the overlay we need a slight adjustment. 137 canvas->DrawImageInt(overlay, 0, icon_.height() - overlay.height());
142 const int kVerticalAdjust = 4;
143 canvas->DrawImageInt(
144 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
145 IDR_APP_LIST_TAB_OVERLAY),
146 0, 0);
147 canvas->DrawImageInt(icon_, kIconOffset, kIconOffset + kVerticalAdjust);
148 } 138 }
149 139
150 gfx::ImageSkia icon_; 140 gfx::ImageSkia icon_;
151 141
152 DISALLOW_COPY_AND_ASSIGN(TabOverlayImageSource); 142 DISALLOW_COPY_AND_ASSIGN(ShortcutOverlayImageSource);
153 }; 143 };
154 144
155 extensions::ExtensionPrefs::LaunchType GetExtensionLaunchType( 145 extensions::ExtensionPrefs::LaunchType GetExtensionLaunchType(
156 Profile* profile, 146 Profile* profile,
157 const Extension* extension) { 147 const Extension* extension) {
158 ExtensionService* service = 148 ExtensionService* service =
159 extensions::ExtensionSystem::Get(profile)->extension_service(); 149 extensions::ExtensionSystem::Get(profile)->extension_service();
160 return service->extension_prefs()-> 150 return service->extension_prefs()->
161 GetLaunchType(extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT); 151 GetLaunchType(extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT);
162 } 152 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // TODO(xiyuan): Revisit this when implementing paging support. 263 // TODO(xiyuan): Revisit this when implementing paging support.
274 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page); 264 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page);
275 service->OnExtensionMoved(extension_id_, 265 service->OnExtensionMoved(extension_id_,
276 prev->extension_id(), 266 prev->extension_id(),
277 std::string()); 267 std::string());
278 } 268 }
279 269
280 void ExtensionAppItem::UpdateIcon() { 270 void ExtensionAppItem::UpdateIcon() {
281 if (!GetExtension()) { 271 if (!GetExtension()) {
282 gfx::ImageSkia icon = installing_icon_; 272 gfx::ImageSkia icon = installing_icon_;
283 if (HasOverlay()) { 273 if (HasOverlay())
284 // The tab overlay requires icons of a certain size. 274 icon = gfx::ImageSkia(new ShortcutOverlayImageSource(icon), icon.size());
285 gfx::Size small_size(extension_misc::EXTENSION_ICON_SMALL,
286 extension_misc::EXTENSION_ICON_SMALL);
287 icon = gfx::ImageSkiaOperations::CreateResizedImage(
288 icon, skia::ImageOperations::RESIZE_GOOD, small_size);
289
290 gfx::Size size(extension_misc::EXTENSION_ICON_MEDIUM,
291 extension_misc::EXTENSION_ICON_MEDIUM);
292 icon = gfx::ImageSkia(new TabOverlayImageSource(icon, size), size);
293 }
294 SetIcon(icon, !HasOverlay()); 275 SetIcon(icon, !HasOverlay());
295 return; 276 return;
296 } 277 }
297 gfx::ImageSkia icon = icon_->image_skia(); 278 gfx::ImageSkia icon = icon_->image_skia();
298 279
299 const ExtensionService* service = 280 const ExtensionService* service =
300 extensions::ExtensionSystem::Get(profile_)->extension_service(); 281 extensions::ExtensionSystem::Get(profile_)->extension_service();
301 const bool enabled = service->IsExtensionEnabledForLauncher(extension_id_); 282 const bool enabled = service->IsExtensionEnabledForLauncher(extension_id_);
302 if (!enabled) { 283 if (!enabled) {
303 const color_utils::HSL shift = {-1, 0, 0.6}; 284 const color_utils::HSL shift = {-1, 0, 0.6};
304 icon = gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); 285 icon = gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift);
305 } 286 }
306 287
307 if (HasOverlay()) { 288 if (HasOverlay())
308 const gfx::Size size(extension_misc::EXTENSION_ICON_MEDIUM, 289 icon = gfx::ImageSkia(new ShortcutOverlayImageSource(icon), icon.size());
309 extension_misc::EXTENSION_ICON_MEDIUM);
310 icon = gfx::ImageSkia(new TabOverlayImageSource(icon, size), size);
311 }
312 290
313 SetIcon(icon, !HasOverlay()); 291 SetIcon(icon, !HasOverlay());
314 } 292 }
315 293
316 const Extension* ExtensionAppItem::GetExtension() const { 294 const Extension* ExtensionAppItem::GetExtension() const {
317 const ExtensionService* service = 295 const ExtensionService* service =
318 extensions::ExtensionSystem::Get(profile_)->extension_service(); 296 extensions::ExtensionSystem::Get(profile_)->extension_service();
319 const Extension* extension = service->GetInstalledExtension(extension_id_); 297 const Extension* extension = service->GetInstalledExtension(extension_id_);
320 return extension; 298 return extension;
321 } 299 }
322 300
323 void ExtensionAppItem::LoadImage(const Extension* extension) { 301 void ExtensionAppItem::LoadImage(const Extension* extension) {
324 int icon_size = extension_misc::EXTENSION_ICON_MEDIUM; 302 int icon_size = extension_misc::EXTENSION_ICON_MEDIUM;
xiyuan 2013/04/09 18:06:27 nit: get rid of |icon_size| and use extension_misc
koz (OOO until 15th September) 2013/04/09 18:09:32 Done.
325 if (HasOverlay())
326 icon_size = extension_misc::EXTENSION_ICON_SMALL;
327
328 icon_.reset(new extensions::IconImage( 303 icon_.reset(new extensions::IconImage(
329 profile_, 304 profile_,
330 extension, 305 extension,
331 extensions::IconsInfo::GetIcons(extension), 306 extensions::IconsInfo::GetIcons(extension),
332 icon_size, 307 icon_size,
333 extensions::IconsInfo::GetDefaultAppIcon(), 308 extensions::IconsInfo::GetDefaultAppIcon(),
334 this)); 309 this));
335 UpdateIcon(); 310 UpdateIcon();
336 } 311 }
337 312
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 context_menu_model_->AddItemWithStringId(DETAILS, 581 context_menu_model_->AddItemWithStringId(DETAILS,
607 IDS_NEW_TAB_APP_DETAILS); 582 IDS_NEW_TAB_APP_DETAILS);
608 context_menu_model_->AddItemWithStringId(UNINSTALL, 583 context_menu_model_->AddItemWithStringId(UNINSTALL,
609 is_platform_app_ ? 584 is_platform_app_ ?
610 IDS_APP_LIST_UNINSTALL_ITEM : 585 IDS_APP_LIST_UNINSTALL_ITEM :
611 IDS_EXTENSIONS_UNINSTALL); 586 IDS_EXTENSIONS_UNINSTALL);
612 } 587 }
613 588
614 return context_menu_model_.get(); 589 return context_menu_model_.get();
615 } 590 }
OLDNEW
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698