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 #include "chrome/browser/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
14 #include "ui/gfx/image/image_skia_util_mac.h" | 14 #include "ui/gfx/image/image_skia_util_mac.h" |
15 | 15 |
16 void IconLoader::ReadIcon() { | 16 void IconLoader::ReadIcon(const IconGroupID& group) { |
17 NSString* group = base::SysUTF8ToNSString(group_); | 17 NSString* group = base::SysUTF8ToNSString(group); |
18 NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; | 18 NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; |
19 NSImage* icon = [workspace iconForFileType:group]; | 19 NSImage* icon = [workspace iconForFileType:group]; |
20 | 20 |
21 if (icon_size_ == ALL) { | 21 if (icon_size_ == ALL) { |
22 // The NSImage already has all sizes. | 22 // The NSImage already has all sizes. |
23 image_.reset(new gfx::Image([icon retain])); | 23 image_.reset(new gfx::Image([icon retain])); |
24 } else { | 24 } else { |
25 NSSize size = NSZeroSize; | 25 NSSize size = NSZeroSize; |
26 switch (icon_size_) { | 26 switch (icon_size_) { |
27 case IconLoader::SMALL: | 27 case IconLoader::SMALL: |
28 size = NSMakeSize(16, 16); | 28 size = NSMakeSize(16, 16); |
29 break; | 29 break; |
30 case IconLoader::NORMAL: | 30 case IconLoader::NORMAL: |
31 size = NSMakeSize(32, 32); | 31 size = NSMakeSize(32, 32); |
32 break; | 32 break; |
33 default: | 33 default: |
34 NOTREACHED(); | 34 NOTREACHED(); |
35 } | 35 } |
36 gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size)); | 36 gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size)); |
37 if (!image_skia.isNull()) { | 37 if (!image_skia.isNull()) { |
38 image_skia.MakeThreadSafe(); | 38 image_skia.MakeThreadSafe(); |
39 image_.reset(new gfx::Image(image_skia)); | 39 image_.reset(new gfx::Image(image_skia)); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 target_message_loop_->PostTask(FROM_HERE, | 43 target_message_loop_->PostTask(FROM_HERE, |
44 base::Bind(&IconLoader::NotifyDelegate, this)); | 44 base::Bind(&IconLoader::NotifyDelegate, this, group)); |
45 } | 45 } |
OLD | NEW |