diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-03 19:58:06 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-03 19:58:06 +0000 |
commit | bdd6eec2dbd37b2fdc38d32cd69f467bbc2d69cc (patch) | |
tree | e99d5669185f6ac8ccd441baa70b69a65a0331c2 /chrome/browser/web_applications/web_app_mac.mm | |
parent | 04f050b37f95b156b4b60c9e05e5672bc3388f0f (diff) | |
download | chromium_src-bdd6eec2dbd37b2fdc38d32cd69f467bbc2d69cc.zip chromium_src-bdd6eec2dbd37b2fdc38d32cd69f467bbc2d69cc.tar.gz chromium_src-bdd6eec2dbd37b2fdc38d32cd69f467bbc2d69cc.tar.bz2 |
Add support for multiple icon sizes for Mac platform apps
This is the combined version of the following CLs:
http://codereview.chromium.org/9428025/
http://codereview.chromium.org/9500007/
http://codereview.chromium.org/9535002/
BUG=112651
TEST=
Review URL: https://chromiumcodereview.appspot.com/9586018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124875 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_applications/web_app_mac.mm')
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.mm | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm index 004f8d4..9cc1931 100644 --- a/chrome/browser/web_applications/web_app_mac.mm +++ b/chrome/browser/web_applications/web_app_mac.mm @@ -35,6 +35,48 @@ NSBitmapImageRep* SkBitmapToImageRep(const SkBitmap& bitmap) { [[image representations] lastObject]); } +// Adds |image_rep| to |icon_family|. Returns true on success, false on failure. +bool AddBitmapImageRepToIconFamily(IconFamily* icon_family, + NSBitmapImageRep* image_rep) { + NSSize size = [image_rep size]; + if (size.width != size.height) + return false; + + switch (static_cast<int>(size.width)) { + case 512: + return [icon_family setIconFamilyElement:kIconServices512PixelDataARGB + fromBitmapImageRep:image_rep]; + case 256: + return [icon_family setIconFamilyElement:kIconServices256PixelDataARGB + fromBitmapImageRep:image_rep]; + case 128: + return [icon_family setIconFamilyElement:kThumbnail32BitData + fromBitmapImageRep:image_rep] && + [icon_family setIconFamilyElement:kThumbnail8BitMask + fromBitmapImageRep:image_rep]; + case 32: + return [icon_family setIconFamilyElement:kLarge32BitData + fromBitmapImageRep:image_rep] && + [icon_family setIconFamilyElement:kLarge8BitData + fromBitmapImageRep:image_rep] && + [icon_family setIconFamilyElement:kLarge8BitMask + fromBitmapImageRep:image_rep] && + [icon_family setIconFamilyElement:kLarge1BitMask + fromBitmapImageRep:image_rep]; + case 16: + return [icon_family setIconFamilyElement:kSmall32BitData + fromBitmapImageRep:image_rep] && + [icon_family setIconFamilyElement:kSmall8BitData + fromBitmapImageRep:image_rep] && + [icon_family setIconFamilyElement:kSmall8BitMask + fromBitmapImageRep:image_rep] && + [icon_family setIconFamilyElement:kSmall1BitMask + fromBitmapImageRep:image_rep]; + default: + return false; + } +} + } // namespace @@ -150,26 +192,26 @@ bool WebAppShortcutCreator::UpdatePlist(const FilePath& app_path) const { } bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { - // TODO(sail): Add support for multiple icon sizes. - if (info_.favicon.empty() || info_.favicon.width() != 32 || - info_.favicon.height() != 32) { + if (info_.favicon.IsEmpty()) return true; - } - - NSBitmapImageRep* image_rep = SkBitmapToImageRep(info_.favicon); - if (!image_rep) - return false; scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); - bool success = [icon_family setIconFamilyElement:kLarge32BitData - fromBitmapImageRep:image_rep] && - [icon_family setIconFamilyElement:kLarge8BitData - fromBitmapImageRep:image_rep] && - [icon_family setIconFamilyElement:kLarge8BitMask - fromBitmapImageRep:image_rep] && - [icon_family setIconFamilyElement:kLarge1BitMask - fromBitmapImageRep:image_rep]; - if (!success) + bool image_added = false; + for (size_t i = 0; i < info_.favicon.GetNumberOfSkBitmaps(); ++i) { + NSBitmapImageRep* image_rep = + SkBitmapToImageRep(*info_.favicon.GetSkBitmapAtIndex(i)); + if (!image_rep) + continue; + + // Missing an icon size is not fatal so don't fail if adding the bitmap + // doesn't work. + if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) + continue; + + image_added = true; + } + + if (!image_added) return false; FilePath resources_path = app_path.Append("Contents").Append("Resources"); |