Chromium Code Reviews| Index: chrome/browser/resource_delegate_mac.mm |
| diff --git a/chrome/browser/resource_delegate_mac.mm b/chrome/browser/resource_delegate_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f4d46803e412aeb4b3cb850162977d20da0305a |
| --- /dev/null |
| +++ b/chrome/browser/resource_delegate_mac.mm |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/resource_delegate_mac.h" |
| + |
| +#import <Cocoa/Cocoa.h> |
| + |
| +#include "ui/resources/grit/ui_resources.h" |
| +#include "ui/views/resources/grit/views_resources.h" |
| + |
| +namespace ui { |
| + |
| +namespace { |
| + |
| +enum IconSize { |
| + SMALL, // 16X16. |
| + BIG // 32X32. |
|
tapted
2016/01/18 04:15:42
`BIG` is unused. I think we want
const int kFolde
karandeepb
2016/01/18 09:25:40
Done. Have attached screenshots on the bug report.
|
| +}; |
| + |
| +// Returns the icon for the given hfs_type defined in Cocoa's IconsCore.h, as a |
| +// gfx::Image. In case the icon can't be retreived, an empty image is returned. |
|
tapted
2016/01/18 04:15:42
I don't think the "In case the icon..." part is ri
karandeepb
2016/01/18 09:25:40
Done.
|
| +gfx::Image ImageForHFSType(int hfs_type, IconSize icon_size) { |
|
tapted
2016/01/18 04:15:42
IconSize -> int
karandeepb
2016/01/18 09:25:40
Done.
|
| + NSImage* icon = [[[NSWorkspace sharedWorkspace] |
| + iconForFileType:NSFileTypeForHFSTypeCode(hfs_type)] retain]; |
|
karandeepb
2016/01/18 00:31:18
Can you check if calling retain here is ok? gfx::I
tapted
2016/01/18 04:15:42
ooh - yeah gfx::Image is weird. the return from ic
karandeepb
2016/01/18 09:25:40
Done.
|
| + NSSize desired_size; |
| + switch (icon_size) { |
| + case IconSize::SMALL: |
| + desired_size = NSMakeSize(16, 16); |
| + break; |
| + case IconSize::BIG: |
| + desired_size = NSMakeSize(32, 32); |
| + break; |
| + } |
| + [icon setSize:desired_size]; |
| + return gfx::Image(icon); |
| +} |
| + |
| +} // namespace |
| + |
| +MacResourceDelegate::MacResourceDelegate() {} |
| + |
| +MacResourceDelegate::~MacResourceDelegate() {} |
| + |
| +base::FilePath MacResourceDelegate::GetPathForResourcePack( |
| + const base::FilePath& pack_path, |
| + ui::ScaleFactor scale_factor) { |
| + return pack_path; |
| +}; |
| + |
| +base::FilePath MacResourceDelegate::GetPathForLocalePack( |
| + const base::FilePath& pack_path, |
| + const std::string& locale) { |
| + return pack_path; |
| +}; |
| + |
| +gfx::Image MacResourceDelegate::GetImageNamed(int resource_id) { |
| + return GetNativeImageNamed(resource_id, ui::ResourceBundle::RTL_DISABLED); |
| +}; |
| + |
| +gfx::Image MacResourceDelegate::GetNativeImageNamed( |
| + int resource_id, |
| + ui::ResourceBundle::ImageRTL rtl) { |
| + // Flipped images are not used on Mac. |
|
tapted
2016/01/18 04:15:42
I think it was only used for GTK and we can remove
karandeepb
2016/01/18 09:25:40
Will remove once the CL lands.
|
| + DCHECK_EQ(rtl, ui::ResourceBundle::RTL_DISABLED); |
| + |
| + switch (resource_id) { |
|
tapted
2016/01/18 04:15:42
Needs a comment about why this is correct re: the
karandeepb
2016/01/18 09:25:40
Done.
|
| + case IDR_FOLDER_OPEN: |
| + case IDR_FOLDER_OPEN_RTL: |
| + return ImageForHFSType(kOpenFolderIcon, IconSize::SMALL); |
| + break; |
|
tapted
2016/01/18 04:15:42
nit: no break required
karandeepb
2016/01/18 09:25:40
Done.
|
| + case IDR_FOLDER_CLOSED: |
| + case IDR_FOLDER_CLOSED_RTL: |
| + return ImageForHFSType(kGenericFolderIcon, IconSize::SMALL); |
| + break; |
|
tapted
2016/01/18 04:15:42
nit: no break
karandeepb
2016/01/18 09:25:40
Done.
|
| + } |
| + return gfx::Image(); |
| +}; |
| + |
| +base::RefCountedStaticMemory* MacResourceDelegate::LoadDataResourceBytes( |
| + int resource_id, |
| + ui::ScaleFactor scale_factor) { |
| + return nullptr; |
| +}; |
| + |
| +bool MacResourceDelegate::GetRawDataResource(int resource_id, |
| + ui::ScaleFactor scale_factor, |
| + base::StringPiece* value) { |
| + return false; |
| +}; |
| + |
| +bool MacResourceDelegate::GetLocalizedString(int message_id, |
| + base::string16* value) { |
| + return false; |
| +}; |
| + |
| +scoped_ptr<gfx::Font> MacResourceDelegate::GetFont( |
| + ui::ResourceBundle::FontStyle style) { |
| + return scoped_ptr<gfx::Font>(); |
| +}; |
| + |
| +} // namespace ui |