Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(758)

Unified Diff: ui/base/resource/resource_bundle_win.cc

Issue 10082020: Metro/HiDPI: Use metro resource pak in metro mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« chrome/chrome_resources.gyp ('K') | « tools/gritsettings/resource_ids ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/resource/resource_bundle_win.cc
diff --git a/ui/base/resource/resource_bundle_win.cc b/ui/base/resource/resource_bundle_win.cc
index 79355d67eb6f506ec200aaf93ee6da593e1f528b..d5933f6b4ad8e48de33aa85c9077a89ac03ffc9a 100644
--- a/ui/base/resource/resource_bundle_win.cc
+++ b/ui/base/resource/resource_bundle_win.cc
@@ -1,76 +1,95 @@
-// Copyright (c) 2012 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 "ui/base/resource/resource_bundle_win.h"
-
-#include "base/logging.h"
-#include "base/path_service.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/base/resource/resource_data_dll_win.h"
-#include "ui/base/win/dpi.h"
-
-namespace ui {
-
-namespace {
-
-HINSTANCE resources_data_dll;
-
-HINSTANCE GetCurrentResourceDLL() {
- if (resources_data_dll)
- return resources_data_dll;
- return GetModuleHandle(NULL);
-}
-
-FilePath GetResourcesPakFilePath(const std::string& pak_name) {
- FilePath path;
- if (PathService::Get(base::DIR_MODULE, &path))
- return path.AppendASCII(pak_name.c_str());
- return FilePath();
-}
-
-} // end anonymous namespace
-
-void ResourceBundle::LoadCommonResources() {
- // As a convenience, add the current resource module as a data packs.
- data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL()));
-
- bool use_hidpi_pak = false;
-#if defined(ENABLE_HIDPI)
- // If we're running in HiDPI mode then use the 2x resource for DPI greater
- // than 1.5. Otherwise use the 1x resource.
- use_hidpi_pak = ui::GetDPIScale() > 1.5;
-#endif
-
- if (!use_hidpi_pak) {
- AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"));
- AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"));
- } else {
- AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak"));
- AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak"));
- }
-}
-
-void ResourceBundle::LoadTestResources(const FilePath& path) {
- // On Windows, the test resources are normally compiled into the binary
- // itself.
-}
-
-gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
- // Flipped image is not used on Windows.
- DCHECK_EQ(rtl, RTL_DISABLED);
-
- // Windows only uses SkBitmap for gfx::Image, so this is the same as
- // GetImageNamed.
- return GetImageNamed(resource_id);
-}
-
-void SetResourcesDataDLL(HINSTANCE handle) {
- resources_data_dll = handle;
-}
-
-HICON LoadThemeIconFromResourcesDataDLL(int icon_id) {
- return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id));
-}
-
-} // namespace ui;
+// Copyright (c) 2012 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 "ui/base/resource/resource_bundle_win.h"
+
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/resource/resource_data_dll_win.h"
+#include "ui/base/win/dpi.h"
+
+namespace ui {
+
+namespace {
+
+HINSTANCE resources_data_dll;
+
+HINSTANCE GetCurrentResourceDLL() {
+ if (resources_data_dll)
+ return resources_data_dll;
+ return GetModuleHandle(NULL);
+}
+
+FilePath GetResourcesPakFilePath(const std::string& pak_name) {
+ FilePath path;
+ if (PathService::Get(base::DIR_MODULE, &path))
+ return path.AppendASCII(pak_name.c_str());
+ return FilePath();
+}
+
+bool IsInMetroMode() {
+ const char* kMetroModeEnvVar = "CHROME_METRO_DLL";
sky 2012/04/13 22:56:15 Can you use base/win/metro.h?
sail 2012/04/18 15:46:40 Done.
+ char buffer[2];
+ if (!::GetEnvironmentVariableA(kMetroModeEnvVar, buffer, arraysize(buffer)))
+ return false;
+ return buffer == std::string("1");
+}
+
+} // end anonymous namespace
+
+void ResourceBundle::LoadCommonResources() {
+ // As a convenience, add the current resource module as a data packs.
+ data_packs_.push_back(new ResourceDataDLL(GetCurrentResourceDLL()));
+
+ bool use_hidpi_pak = false;
+#if defined(ENABLE_HIDPI)
+ // If we're running in HiDPI mode then use the 2x resource for DPI greater
+ // than 1.5. Otherwise use the 1x resource.
+ use_hidpi_pak = ui::GetDPIScale() > 1.5;
+#endif
+
+ bool use_metro_pak = false;
+#if defined(ENABLE_METRO)
+ use_metro_pak = IsInMetroMode();
+#endif
+
+ if (use_metro_pak) {
+ AddDataPack(GetResourcesPakFilePath("theme_resources_metro_1x.pak"));
+ } else if (use_hidpi_pak) {
+ AddDataPack(GetResourcesPakFilePath("theme_resources_2x.pak"));
+ } else {
+ AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"));
+ }
+
+ if (use_hidpi_pak) {
+ AddDataPack(GetResourcesPakFilePath("ui_resources_2x.pak"));
+ } else {
+ AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"));
+ }
+}
+
+void ResourceBundle::LoadTestResources(const FilePath& path) {
+ // On Windows, the test resources are normally compiled into the binary
+ // itself.
+}
+
+gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
+ // Flipped image is not used on Windows.
+ DCHECK_EQ(rtl, RTL_DISABLED);
+
+ // Windows only uses SkBitmap for gfx::Image, so this is the same as
+ // GetImageNamed.
+ return GetImageNamed(resource_id);
+}
+
+void SetResourcesDataDLL(HINSTANCE handle) {
+ resources_data_dll = handle;
+}
+
+HICON LoadThemeIconFromResourcesDataDLL(int icon_id) {
+ return ::LoadIcon(GetCurrentResourceDLL(), MAKEINTRESOURCE(icon_id));
+}
+
+} // namespace ui;
« chrome/chrome_resources.gyp ('K') | « tools/gritsettings/resource_ids ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698