Chromium Code Reviews| Index: ui/base/win/dpi.cc |
| diff --git a/ui/base/win/dpi.cc b/ui/base/win/dpi.cc |
| index b618df91715c9b9105b9f8c064647673c96011cc..cc713319882f67ccd6620d6b647866af5e68c80c 100644 |
| --- a/ui/base/win/dpi.cc |
| +++ b/ui/base/win/dpi.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/win/scoped_hdc.h" |
| #include "ui/base/layout.h" |
| +#include "base/win/registry.h" |
| #include "ui/gfx/display.h" |
| #include "ui/gfx/point_conversions.h" |
| #include "ui/gfx/rect_conversions.h" |
| @@ -30,6 +31,24 @@ float GetDeviceScaleFactorImpl() { |
| #endif |
| } |
| +FARPROC GetProcAddressWrapper(LPCSTR module_name, LPCSTR proc_name) { |
| + HMODULE module = ::GetModuleHandleA(module_name); |
| + if (module) { |
| + return ::GetProcAddress(module, proc_name); |
| + } |
| + return NULL; |
| +} |
| + |
| +BOOL IsProcessDPIAwareWrapper() { |
| + typedef BOOL(WINAPI *IsProcessDPIAwarePtr)(VOID); |
| + IsProcessDPIAwarePtr is_process_dpi_aware_func = |
| + reinterpret_cast<IsProcessDPIAwarePtr>( |
| + GetProcAddressWrapper("user32.dll", "IsProcessDPIAware")); |
| + if (is_process_dpi_aware_func) |
| + return is_process_dpi_aware_func(); |
| + return FALSE; |
| +} |
| + |
| } // namespace |
| namespace ui { |
| @@ -65,7 +84,7 @@ void EnableHighDPISupport() { |
| typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); |
| SetProcessDPIAwarePtr set_process_dpi_aware_func = |
| reinterpret_cast<SetProcessDPIAwarePtr>( |
| - GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware")); |
| + GetProcAddressWrapper("user32.dll", "SetProcessDPIAware")); |
| if (set_process_dpi_aware_func) |
| set_process_dpi_aware_func(); |
| } |
| @@ -103,6 +122,33 @@ gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { |
| return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); |
| } |
| +double GetDPIScaleFromRegistry() { |
| + static double scale = -1.0; |
| + if (scale == -1.0) { |
| + double result = 1.0; |
| + if (!IsProcessDPIAwareWrapper()) { |
| + //HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI |
|
Ryan Sleevi
2013/03/05 18:32:56
nit: space between //
|
| + base::win::RegKey key(HKEY_CURRENT_USER, |
| + L"Control Panel\\Desktop\\WindowMetrics", |
| + KEY_QUERY_VALUE); |
| + |
| + if (key.Valid()) { |
| + DWORD value = 0; |
| + if (key.ReadValueDW(L"AppliedDPI", &value) == ERROR_SUCCESS) { |
| + result = ((double)value) / kDefaultDPIX; |
|
Ryan Sleevi
2013/03/05 18:32:56
style: Don't do C-casts
|
| + } |
| + } |
| + } |
| + scale = result; |
| + } |
| + |
| + // Safety test to ignore invalid settings. |
| + if (scale <= 0.0) |
| + scale = 1.0; |
| + |
| + return scale; |
| +} |
| + |
| } // namespace win |
| } // namespace ui |