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

Unified Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 9586018: Add support for multiple icon sizes for Mac platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/web_applications/web_app_mac.mm
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index 2bdfe1a0af4bf2a84ee6af71f159fa6968fe672a..021d0596392051d44d7f08d07dc0c9e3190d324f 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -33,6 +33,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
@@ -123,26 +165,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");
« no previous file with comments | « chrome/browser/ui/webui/ntp/favicon_webui_handler.cc ('k') | chrome/browser/web_applications/web_app_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698