OLD | NEW |
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 #import "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
6 | 6 |
7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "apps/app_shim/app_shim_mac.h" | 10 #include "apps/app_shim/app_shim_mac.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 [overlay drawInRect:NSMakeRect(0, 0, dimension, dimension) | 291 [overlay drawInRect:NSMakeRect(0, 0, dimension, dimension) |
292 fromRect:NSZeroRect | 292 fromRect:NSZeroRect |
293 operation:NSCompositeSourceOver | 293 operation:NSCompositeSourceOver |
294 fraction:1.0 | 294 fraction:1.0 |
295 respectFlipped:NO | 295 respectFlipped:NO |
296 hints:0]; | 296 hints:0]; |
297 [NSGraphicsContext restoreGraphicsState]; | 297 [NSGraphicsContext restoreGraphicsState]; |
298 return canvas.autorelease(); | 298 return canvas.autorelease(); |
299 } | 299 } |
300 | 300 |
| 301 // Helper function to extract the single NSImageRep held in a resource bundle |
| 302 // image. |
| 303 NSImageRep* ImageRepForResource(int resource_id) { |
| 304 gfx::Image& image = |
| 305 ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); |
| 306 NSArray* image_reps = [image.AsNSImage() representations]; |
| 307 DCHECK_EQ(1u, [image_reps count]); |
| 308 return [image_reps objectAtIndex:0]; |
| 309 } |
| 310 |
301 // Adds a localized strings file for the Chrome Apps directory using the current | 311 // Adds a localized strings file for the Chrome Apps directory using the current |
302 // locale. OSX will use this for the display name. | 312 // locale. OSX will use this for the display name. |
303 // + Chrome Apps.localized (|apps_directory|) | 313 // + Chrome Apps.localized (|apps_directory|) |
304 // | + .localized | 314 // | + .localized |
305 // | | en.strings | 315 // | | en.strings |
306 // | | de.strings | 316 // | | de.strings |
307 void UpdateAppShortcutsSubdirLocalizedName( | 317 void UpdateAppShortcutsSubdirLocalizedName( |
308 const base::FilePath& apps_directory) { | 318 const base::FilePath& apps_directory) { |
309 base::FilePath localized = apps_directory.Append(".localized"); | 319 base::FilePath localized = apps_directory.Append(".localized"); |
310 if (!base::CreateDirectory(localized)) | 320 if (!base::CreateDirectory(localized)) |
311 return; | 321 return; |
312 | 322 |
313 base::FilePath directory_name = apps_directory.BaseName().RemoveExtension(); | 323 base::FilePath directory_name = apps_directory.BaseName().RemoveExtension(); |
314 base::string16 localized_name = ShellIntegration::GetAppShortcutsSubdirName(); | 324 base::string16 localized_name = ShellIntegration::GetAppShortcutsSubdirName(); |
315 NSDictionary* strings_dict = @{ | 325 NSDictionary* strings_dict = @{ |
316 base::mac::FilePathToNSString(directory_name) : | 326 base::mac::FilePathToNSString(directory_name) : |
317 base::SysUTF16ToNSString(localized_name) | 327 base::SysUTF16ToNSString(localized_name) |
318 }; | 328 }; |
319 | 329 |
320 std::string locale = l10n_util::NormalizeLocale( | 330 std::string locale = l10n_util::NormalizeLocale( |
321 l10n_util::GetApplicationLocale(std::string())); | 331 l10n_util::GetApplicationLocale(std::string())); |
322 | 332 |
323 NSString* strings_path = base::mac::FilePathToNSString( | 333 NSString* strings_path = base::mac::FilePathToNSString( |
324 localized.Append(locale + ".strings")); | 334 localized.Append(locale + ".strings")); |
325 [strings_dict writeToFile:strings_path | 335 [strings_dict writeToFile:strings_path |
326 atomically:YES]; | 336 atomically:YES]; |
327 | 337 |
328 // Brand the folder with an embossed app launcher logo. | 338 base::scoped_nsobject<NSImage> folder_icon_image([[NSImage alloc] init]); |
| 339 |
| 340 // Use complete assets for the small icon sizes. -[NSWorkspace setIcon:] has a |
| 341 // bug when dealing with named NSImages where it incorrectly handles alpha |
| 342 // premultiplication. This is most noticable with small assets since the 1px |
| 343 // border is a much larger component of the small icons. |
| 344 // See http://crbug.com/305373 for details. |
| 345 [folder_icon_image addRepresentation:ImageRepForResource(IDR_APPS_FOLDER_16)]; |
| 346 [folder_icon_image addRepresentation:ImageRepForResource(IDR_APPS_FOLDER_32)]; |
| 347 |
| 348 // Brand larger folder assets with an embossed app launcher logo to conserve |
| 349 // distro size and for better consistency with changing hue across OSX |
| 350 // versions. The folder is textured, so compresses poorly without this. |
329 const int kBrandResourceIds[] = { | 351 const int kBrandResourceIds[] = { |
330 IDR_APPS_FOLDER_OVERLAY_16, | |
331 IDR_APPS_FOLDER_OVERLAY_32, | |
332 IDR_APPS_FOLDER_OVERLAY_128, | 352 IDR_APPS_FOLDER_OVERLAY_128, |
333 IDR_APPS_FOLDER_OVERLAY_512, | 353 IDR_APPS_FOLDER_OVERLAY_512, |
334 }; | 354 }; |
335 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
336 NSImage* base_image = [NSImage imageNamed:NSImageNameFolder]; | 355 NSImage* base_image = [NSImage imageNamed:NSImageNameFolder]; |
337 base::scoped_nsobject<NSImage> folder_icon_image([[NSImage alloc] init]); | |
338 for (size_t i = 0; i < arraysize(kBrandResourceIds); ++i) { | 356 for (size_t i = 0; i < arraysize(kBrandResourceIds); ++i) { |
339 gfx::Image& image_rep = rb.GetNativeImageNamed(kBrandResourceIds[i]); | 357 NSImageRep* with_overlay = |
340 NSArray* image_reps = [image_rep.AsNSImage() representations]; | 358 OverlayImageRep(base_image, ImageRepForResource(kBrandResourceIds[i])); |
341 DCHECK_EQ(1u, [image_reps count]); | |
342 NSImageRep* with_overlay = OverlayImageRep(base_image, | |
343 [image_reps objectAtIndex:0]); | |
344 DCHECK(with_overlay); | 359 DCHECK(with_overlay); |
345 if (with_overlay) | 360 if (with_overlay) |
346 [folder_icon_image addRepresentation:with_overlay]; | 361 [folder_icon_image addRepresentation:with_overlay]; |
347 } | 362 } |
348 [[NSWorkspace sharedWorkspace] | 363 [[NSWorkspace sharedWorkspace] |
349 setIcon:folder_icon_image | 364 setIcon:folder_icon_image |
350 forFile:base::mac::FilePathToNSString(apps_directory) | 365 forFile:base::mac::FilePathToNSString(apps_directory) |
351 options:0]; | 366 options:0]; |
352 } | 367 } |
353 | 368 |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 web_app::UpdateShortcutInfoAndIconForApp( | 978 web_app::UpdateShortcutInfoAndIconForApp( |
964 app, | 979 app, |
965 profile, | 980 profile, |
966 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 981 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
967 profile, | 982 profile, |
968 app, | 983 app, |
969 close_callback)); | 984 close_callback)); |
970 } | 985 } |
971 | 986 |
972 } // namespace chrome | 987 } // namespace chrome |
OLD | NEW |