summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resource_delegate_mac.mm
blob: 8ff937daa851d2402639667ce0a98383fb229789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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 {

const int kFolderIconReportedSizeDIP = 16;

// Returns the icon for the given |hfs_type| defined in Cocoa's IconsCore.h, as
// a gfx::Image of dimensions |width| X |height|.
gfx::Image ImageForHFSType(int hfs_type, int width, int height) {
  NSImage* icon = [[NSWorkspace sharedWorkspace]
      iconForFileType:NSFileTypeForHFSTypeCode(hfs_type)];
  DCHECK(icon);
  [icon setSize:NSMakeSize(width, height)];
  return gfx::Image([icon retain]);
}

}  // 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);
}

gfx::Image MacResourceDelegate::GetNativeImageNamed(int resource_id) {
  switch (resource_id) {
    // On Mac, return the same assets for the _RTL resources. Consistent with,
    // e.g., Safari.
    case IDR_FOLDER_OPEN:
    case IDR_FOLDER_OPEN_RTL:
      return ImageForHFSType(kOpenFolderIcon, kFolderIconReportedSizeDIP,
                             kFolderIconReportedSizeDIP);
    case IDR_FOLDER_CLOSED:
    case IDR_FOLDER_CLOSED_RTL:
      return ImageForHFSType(kGenericFolderIcon, kFolderIconReportedSizeDIP,
                             kFolderIconReportedSizeDIP);
  }
  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;
}