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

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

Issue 135533006: Round app icon corners for bookmark apps in the launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reattempt_icon_generation
Patch Set: Created 6 years, 10 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 | « no previous file | 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/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_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 DISALLOW_COPY_AND_ASSIGN(ShortcutOverlayImageSource); 60 DISALLOW_COPY_AND_ASSIGN(ShortcutOverlayImageSource);
61 }; 61 };
62 62
63 extensions::AppSorting* GetAppSorting(Profile* profile) { 63 extensions::AppSorting* GetAppSorting(Profile* profile) {
64 ExtensionService* service = 64 ExtensionService* service =
65 extensions::ExtensionSystem::Get(profile)->extension_service(); 65 extensions::ExtensionSystem::Get(profile)->extension_service();
66 return service->extension_prefs()->app_sorting(); 66 return service->extension_prefs()->app_sorting();
67 } 67 }
68 68
69 // Returns the given |icon| with rounded corners.
70 gfx::ImageSkia GetRoundedIcon(gfx::ImageSkia icon) {
71 // The radius used to round the app icon.
72 const size_t kRoundingRadius = 2;
73
74 scoped_ptr<SkCanvas> canvas(
75 skia::CreateBitmapCanvas(icon.width(), icon.height(), false));
76 DCHECK(canvas);
77 canvas->drawBitmap(*icon.bitmap(), 0, 0);
78
79 scoped_ptr<SkCanvas> masking_canvas(
80 skia::CreateBitmapCanvas(icon.width(), icon.height(), false));
81 DCHECK(masking_canvas);
82
83 SkPaint opaque_paint;
84 opaque_paint.setColor(SK_ColorWHITE);
85 opaque_paint.setFlags(SkPaint::kAntiAlias_Flag);
86 masking_canvas->drawRoundRect(
87 SkRect::MakeWH(icon.width(), icon.height()),
88 kRoundingRadius, kRoundingRadius, opaque_paint);
89
90 SkPaint masking_paint;
91 masking_paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
92 canvas->drawBitmap(
93 masking_canvas->getDevice()->accessBitmap(false), 0, 0, &masking_paint);
94
95 return gfx::ImageSkia::CreateFrom1xBitmap(
96 canvas->getDevice()->accessBitmap(false));
97 }
98
69 const color_utils::HSL shift = {-1, 0, 0.6}; 99 const color_utils::HSL shift = {-1, 0, 0.6};
70 100
71 } // namespace 101 } // namespace
72 102
73 ExtensionAppItem::ExtensionAppItem( 103 ExtensionAppItem::ExtensionAppItem(
74 Profile* profile, 104 Profile* profile,
75 const app_list::AppListSyncableService::SyncItem* sync_item, 105 const app_list::AppListSyncableService::SyncItem* sync_item,
76 const std::string& extension_id, 106 const std::string& extension_id,
77 const std::string& extension_name, 107 const std::string& extension_name,
78 const gfx::ImageSkia& installing_icon, 108 const gfx::ImageSkia& installing_icon,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 gfx::ImageSkia icon = icon_->image_skia(); 162 gfx::ImageSkia icon = icon_->image_skia();
133 163
134 const ExtensionService* service = 164 const ExtensionService* service =
135 extensions::ExtensionSystem::Get(profile_)->extension_service(); 165 extensions::ExtensionSystem::Get(profile_)->extension_service();
136 const bool enabled = extension_util::IsAppLaunchable(extension_id_, service); 166 const bool enabled = extension_util::IsAppLaunchable(extension_id_, service);
137 if (!enabled) { 167 if (!enabled) {
138 const color_utils::HSL shift = {-1, 0, 0.6}; 168 const color_utils::HSL shift = {-1, 0, 0.6};
139 icon = gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); 169 icon = gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift);
140 } 170 }
141 171
172 if (GetExtension()->from_bookmark())
173 icon = GetRoundedIcon(icon);
174
142 if (HasOverlay()) 175 if (HasOverlay())
143 icon = gfx::ImageSkia(new ShortcutOverlayImageSource(icon), icon.size()); 176 icon = gfx::ImageSkia(new ShortcutOverlayImageSource(icon), icon.size());
144 177
145 SetIcon(icon, !HasOverlay()); 178 SetIcon(icon, !HasOverlay());
146 } 179 }
147 180
148 void ExtensionAppItem::Move(const ExtensionAppItem* prev, 181 void ExtensionAppItem::Move(const ExtensionAppItem* prev,
149 const ExtensionAppItem* next) { 182 const ExtensionAppItem* next) {
150 if (!prev && !next) 183 if (!prev && !next)
151 return; // No reordering necessary 184 return; // No reordering necessary
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 const syncer::StringOrdinal& launch = 324 const syncer::StringOrdinal& launch =
292 GetAppSorting(profile_)->GetAppLaunchOrdinal(extension_id_); 325 GetAppSorting(profile_)->GetAppLaunchOrdinal(extension_id_);
293 set_position(syncer::StringOrdinal( 326 set_position(syncer::StringOrdinal(
294 page.ToInternalValue() + launch.ToInternalValue())); 327 page.ToInternalValue() + launch.ToInternalValue()));
295 } 328 }
296 329
297 AppListControllerDelegate* ExtensionAppItem::GetController() { 330 AppListControllerDelegate* ExtensionAppItem::GetController() {
298 return AppListService::Get(chrome::GetActiveDesktop())-> 331 return AppListService::Get(chrome::GetActiveDesktop())->
299 GetControllerDelegate(); 332 GetControllerDelegate();
300 } 333 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698