summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 15:01:06 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 15:01:06 +0000
commit74645fcb7cea93f471bd0f8adfe9fa1c735c818c (patch)
treed52f6a7dbaba72940ec39c3732b844621a2383a9 /chrome/browser
parent0f8c6a140681025c7a97b0f5d8c37cf6a80b85f9 (diff)
downloadchromium_src-74645fcb7cea93f471bd0f8adfe9fa1c735c818c.zip
chromium_src-74645fcb7cea93f471bd0f8adfe9fa1c735c818c.tar.gz
chromium_src-74645fcb7cea93f471bd0f8adfe9fa1c735c818c.tar.bz2
Switch to getting theme images via SkBitmap.
BUG=none TEST=none Review URL: http://codereview.chromium.org/151104 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19729 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_theme_provider_mac.mm50
1 files changed, 32 insertions, 18 deletions
diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm
index a1709f9..4c52fe1 100644
--- a/chrome/browser/browser_theme_provider_mac.mm
+++ b/chrome/browser/browser_theme_provider_mac.mm
@@ -7,35 +7,49 @@
#import <Cocoa/Cocoa.h>
#include "base/logging.h"
+#include "skia/ext/skia_utils_mac.h"
NSImage* BrowserThemeProvider::GetNSImageNamed(int id) {
DCHECK(CalledOnValidThread());
+ if (!HasCustomImage(id))
+ return nil;
+
// Check to see if we already have the image in the cache.
NSImageMap::const_iterator found = nsimage_cache_.find(id);
if (found != nsimage_cache_.end())
return found->second;
- // Why do we load the file directly into the image rather than doing the whole
- // SkBitmap > native conversion that others do? Going direct means:
- // - we use the color profiles and other embedded info in the image file
- // - we don't fall back to the default resources which we don't use on the Mac
- std::vector<unsigned char> raw_data;
- if (ReadThemeFileData(id, &raw_data)) {
- NSData* ns_data = [NSData dataWithBytes:&raw_data.front()
- length:raw_data.size()];
- if (ns_data) {
- NSImage* nsimage = [[NSImage alloc] initWithData:ns_data];
-
- // We loaded successfully. Cache the image.
- if (nsimage) {
- nsimage_cache_[id] = nsimage;
- return nsimage;
- }
- }
+ // Why don't we load the file directly into the image instead of the whole
+ // SkBitmap > native conversion?
+ // - For consistency with other platforms.
+ // - To get the generated tinted images.
+ SkBitmap* bitmap = GetBitmapNamed(id);
+ NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap);
+
+ // We loaded successfully. Cache the image.
+ if (nsimage) {
+ nsimage_cache_[id] = [nsimage retain];
+ return nsimage;
+ }
+
+ // We failed to retrieve the bitmap, show a debugging red square.
+ LOG(WARNING) << "Unable to load NSImage with id " << id;
+ NOTREACHED(); // Want to assert in debug mode.
+
+ static NSImage* empty_image = NULL;
+ if (!empty_image) {
+ // The placeholder image is bright red so people notice the problem. This
+ // image will be leaked, but this code should never be hit.
+ NSRect image_rect = NSMakeRect(0, 0, 32, 32);
+ empty_image = [[NSImage alloc] initWithSize:image_rect.size];
+ [empty_image lockFocus];
+ [[NSColor redColor] set];
+ NSRectFill(image_rect);
+ [empty_image unlockFocus];
}
- return nil;
+ return empty_image;
}
void BrowserThemeProvider::FreePlatformImages() {