Commit 955c37b9 authored by sail@chromium.org's avatar sail@chromium.org

Mac: Fix icons in download dom UI

Icons in the download DOM UI were very fuzzy.

This was a regression due to r76743.

The problem was that IconLoad was returning a multi-resolution image but callers weren't multi-resolution aware.

For example, the download DOM UI would encode the image to PNG but it would just pick the first bitmap which happened to be 16x16. This caused icons in the DOM UI to look fuzzy.

I think there are two fixes for this:
1. Change IconLoader so that callers no longer specify the icon size. Instead, callers must pick the right resolution when they get the icon loaded callback.
2. Have callers specify that they want all resolutions.

I went with 2 because always loading all icon sizes can be expensive.

BUG=84741
TEST=Ran and verified that the downloads UI looks good.


Review URL: http://codereview.chromium.org/6995068

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88406 0039d316-1c4b-4281-b951-d872f2087c98
parent 954bb26d
...@@ -40,7 +40,8 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> { ...@@ -40,7 +40,8 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
enum IconSize { enum IconSize {
SMALL = 0, // 16x16 SMALL = 0, // 16x16
NORMAL, // 32x32 NORMAL, // 32x32
LARGE LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
ALL, // All sizes available
}; };
class Delegate { class Delegate {
......
...@@ -16,12 +16,20 @@ ...@@ -16,12 +16,20 @@
#include "base/string_util.h" #include "base/string_util.h"
static int SizeToInt(IconLoader::IconSize size) { static int SizeToInt(IconLoader::IconSize size) {
int pixels = 48; int pixels = 0;
if (size == IconLoader::NORMAL) switch (size) {
pixels = 32; case IconLoader::SMALL:
else if (size == IconLoader::SMALL) pixels = 16;
pixels = 16; break;
case IconLoader::NORMAL:
pixels = 32;
break;
case IconLoader::LARGE:
pixels = 48;
break;
default:
NOTREACHED();
}
return pixels; return pixels;
} }
......
...@@ -17,9 +17,24 @@ void IconLoader::ReadIcon() { ...@@ -17,9 +17,24 @@ void IconLoader::ReadIcon() {
NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSImage* icon = [workspace iconForFileType:group]; NSImage* icon = [workspace iconForFileType:group];
// Mac will ignore the size because icons have multiple size representations if (icon_size_ == ALL) {
// and NSImage choses the best at draw-time. // The NSImage already has all sizes.
image_.reset(new gfx::Image([icon retain])); image_.reset(new gfx::Image([icon retain]));
} else {
NSSize size = NSZeroSize;
switch (icon_size_) {
case IconLoader::SMALL:
size = NSMakeSize(16, 16);
break;
case IconLoader::NORMAL:
size = NSMakeSize(32, 32);
break;
default:
NOTREACHED();
}
image_.reset(new gfx::Image(new SkBitmap(
gfx::NSImageToSkBitmap(icon, size, false))));
}
target_message_loop_->PostTask(FROM_HERE, target_message_loop_->PostTask(FROM_HERE,
NewRunnableMethod(this, &IconLoader::NotifyDelegate)); NewRunnableMethod(this, &IconLoader::NotifyDelegate));
......
...@@ -79,14 +79,14 @@ void DownloadItemMac::LoadIcon() { ...@@ -79,14 +79,14 @@ void DownloadItemMac::LoadIcon() {
// We may already have this particular image cached. // We may already have this particular image cached.
FilePath file = download_model_->download()->GetUserVerifiedFilePath(); FilePath file = download_model_->download()->GetUserVerifiedFilePath();
gfx::Image* icon = icon_manager->LookupIcon(file, IconLoader::SMALL); gfx::Image* icon = icon_manager->LookupIcon(file, IconLoader::ALL);
if (icon) { if (icon) {
[item_controller_ setIcon:*icon]; [item_controller_ setIcon:*icon];
return; return;
} }
// The icon isn't cached, load it asynchronously. // The icon isn't cached, load it asynchronously.
icon_manager->LoadIcon(file, IconLoader::SMALL, &icon_consumer_, icon_manager->LoadIcon(file, IconLoader::ALL, &icon_consumer_,
NewCallback(this, NewCallback(this,
&DownloadItemMac::OnExtractIconComplete)); &DownloadItemMac::OnExtractIconComplete));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment