| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/win/dpi.h" | 5 #include "ui/base/win/dpi.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/win/scoped_hdc.h" | 9 #include "base/win/scoped_hdc.h" |
| 10 #include "ui/base/layout.h" | 10 #include "ui/base/layout.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { | 108 gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { |
| 109 return gfx::ToFlooredSize( | 109 return gfx::ToFlooredSize( |
| 110 gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); | 110 gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); |
| 111 } | 111 } |
| 112 | 112 |
| 113 gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { | 113 gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { |
| 114 return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); | 114 return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); |
| 115 } | 115 } |
| 116 | 116 |
| 117 int GetSystemMetricsInDIP(int metric) { |
| 118 return static_cast<int>(GetSystemMetrics(metric) / |
| 119 GetDeviceScaleFactor() + 0.5); |
| 120 } |
| 121 |
| 117 double GetUndocumentedDPIScale() { | 122 double GetUndocumentedDPIScale() { |
| 118 // TODO(girard): Remove this code when chrome is DPIAware. | 123 // TODO(girard): Remove this code when chrome is DPIAware. |
| 119 static double scale = -1.0; | 124 static double scale = -1.0; |
| 120 if (scale == -1.0) { | 125 if (scale == -1.0) { |
| 121 scale = 1.0; | 126 scale = 1.0; |
| 122 if (!IsProcessDPIAwareWrapper()) { | 127 if (!IsProcessDPIAwareWrapper()) { |
| 123 base::win::RegKey key(HKEY_CURRENT_USER, | 128 base::win::RegKey key(HKEY_CURRENT_USER, |
| 124 L"Control Panel\\Desktop\\WindowMetrics", | 129 L"Control Panel\\Desktop\\WindowMetrics", |
| 125 KEY_QUERY_VALUE); | 130 KEY_QUERY_VALUE); |
| 126 if (key.Valid()) { | 131 if (key.Valid()) { |
| 127 DWORD value = 0; | 132 DWORD value = 0; |
| 128 if (key.ReadValueDW(L"AppliedDPI", &value) == ERROR_SUCCESS) { | 133 if (key.ReadValueDW(L"AppliedDPI", &value) == ERROR_SUCCESS) { |
| 129 scale = static_cast<double>(value) / kDefaultDPIX; | 134 scale = static_cast<double>(value) / kDefaultDPIX; |
| 130 } | 135 } |
| 131 } | 136 } |
| 132 } | 137 } |
| 133 } | 138 } |
| 134 return scale; | 139 return scale; |
| 135 } | 140 } |
| 136 | 141 |
| 137 } // namespace win | 142 } // namespace win |
| 138 | 143 |
| 139 } // namespace ui | 144 } // namespace ui |
| OLD | NEW |