Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / ui / base / resource / resource_bundle_win.cc
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
3 // found in the LICENSE file.
4
5 #include "ui/base/resource/resource_bundle_win.h"
6
7 #include "base/logging.h"
8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/base/layout.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/base/resource/resource_data_dll_win.h"
13 #include "ui/gfx/win/dpi.h"
14
15 namespace ui {
16
17 namespace {
18
19 HINSTANCE resources_data_dll;
20
21 HINSTANCE GetCurrentResourceDLL() {
22   if (resources_data_dll)
23     return resources_data_dll;
24   return GetModuleHandle(NULL);
25 }
26
27 base::FilePath GetResourcesPakFilePath(const std::string& pak_name) {
28   base::FilePath path;
29   if (PathService::Get(base::DIR_MODULE, &path))
30     return path.AppendASCII(pak_name.c_str());
31
32   // Return just the name of the pack file.
33   return base::FilePath(base::ASCIIToUTF16(pak_name));
34 }
35
36 }  // namespace
37
38 void ResourceBundle::LoadCommonResources() {
39   // As a convenience, add the current resource module as a data packs.
40   data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL()));
41   AddDataPackFromPath(
42       GetResourcesPakFilePath("chrome_100_percent.pak"),
43       SCALE_FACTOR_100P);
44 }
45
46 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
47   // Flipped image is not used on Windows.
48   DCHECK_EQ(rtl, RTL_DISABLED);
49
50   // Windows only uses SkBitmap for gfx::Image, so this is the same as
51   // GetImageNamed.
52   return GetImageNamed(resource_id);
53 }
54
55 void SetResourcesDataDLL(HINSTANCE handle) {
56   resources_data_dll = handle;
57 }
58
59 HICON LoadThemeIconFromResourcesDataDLL(int icon_id) {
60   return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id));
61 }
62
63 }  // namespace ui;