Chromium Code Reviews| 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. | |
|
jackhou1
2014/05/08 01:27:32
Might be worth linking the bug in this comment.
tapted
2014/05/08 02:55:21
Done.
| |
| 344 [folder_icon_image addRepresentation:ImageRepForResource(IDR_APPS_FOLDER_16)]; | |
| 345 [folder_icon_image addRepresentation:ImageRepForResource(IDR_APPS_FOLDER_32)]; | |
| 346 | |
| 347 // Brand larger folder assets with an embossed app launcher logo to conserve | |
| 348 // distro size and for better consistency with changing hue across OSX | |
| 349 // versions. The folder is textured, so compresses poorly without this. | |
| 329 const int kBrandResourceIds[] = { | 350 const int kBrandResourceIds[] = { |
| 330 IDR_APPS_FOLDER_OVERLAY_16, | |
| 331 IDR_APPS_FOLDER_OVERLAY_32, | |
| 332 IDR_APPS_FOLDER_OVERLAY_128, | 351 IDR_APPS_FOLDER_OVERLAY_128, |
| 333 IDR_APPS_FOLDER_OVERLAY_512, | 352 IDR_APPS_FOLDER_OVERLAY_512, |
| 334 }; | 353 }; |
| 335 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 336 NSImage* base_image = [NSImage imageNamed:NSImageNameFolder]; | 354 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) { | 355 for (size_t i = 0; i < arraysize(kBrandResourceIds); ++i) { |
| 339 gfx::Image& image_rep = rb.GetNativeImageNamed(kBrandResourceIds[i]); | 356 NSImageRep* with_overlay = |
| 340 NSArray* image_reps = [image_rep.AsNSImage() representations]; | 357 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); | 358 DCHECK(with_overlay); |
| 345 if (with_overlay) | 359 if (with_overlay) |
| 346 [folder_icon_image addRepresentation:with_overlay]; | 360 [folder_icon_image addRepresentation:with_overlay]; |
| 347 } | 361 } |
| 348 [[NSWorkspace sharedWorkspace] | 362 [[NSWorkspace sharedWorkspace] |
| 349 setIcon:folder_icon_image | 363 setIcon:folder_icon_image |
| 350 forFile:base::mac::FilePathToNSString(apps_directory) | 364 forFile:base::mac::FilePathToNSString(apps_directory) |
| 351 options:0]; | 365 options:0]; |
| 352 } | 366 } |
| 353 | 367 |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 web_app::UpdateShortcutInfoAndIconForApp( | 977 web_app::UpdateShortcutInfoAndIconForApp( |
| 964 app, | 978 app, |
| 965 profile, | 979 profile, |
| 966 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 980 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
| 967 profile, | 981 profile, |
| 968 app, | 982 app, |
| 969 close_callback)); | 983 close_callback)); |
| 970 } | 984 } |
| 971 | 985 |
| 972 } // namespace chrome | 986 } // namespace chrome |
| OLD | NEW |