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/display/win/screen_win.h" | 5 #include "ui/display/win/screen_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shellscalingapi.h> | 8 #include <shellscalingapi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 int system_metrics_result = g_screen_win_instance->GetSystemMetrics(metric); | 310 int system_metrics_result = g_screen_win_instance->GetSystemMetrics(metric); |
311 | 311 |
312 float metrics_relative_scale_factor = hwnd | 312 float metrics_relative_scale_factor = hwnd |
313 ? GetScaleFactorForHWND(hwnd) / primary_display.device_scale_factor() | 313 ? GetScaleFactorForHWND(hwnd) / primary_display.device_scale_factor() |
314 : 1.0f; | 314 : 1.0f; |
315 return static_cast<int>(std::round( | 315 return static_cast<int>(std::round( |
316 system_metrics_result * metrics_relative_scale_factor)); | 316 system_metrics_result * metrics_relative_scale_factor)); |
317 } | 317 } |
318 | 318 |
319 // static | 319 // static |
| 320 int ScreenWin::GetSystemMetricsInDIP(int metric) { |
| 321 if (!g_screen_win_instance) |
| 322 return ::GetSystemMetrics(metric); |
| 323 |
| 324 Display primary_display(g_screen_win_instance->GetPrimaryDisplay()); |
| 325 int system_metrics_result = g_screen_win_instance->GetSystemMetrics(metric); |
| 326 return static_cast<int>(std::round( |
| 327 system_metrics_result / primary_display.device_scale_factor())); |
| 328 } |
| 329 |
| 330 // static |
320 float ScreenWin::GetScaleFactorForHWND(HWND hwnd) { | 331 float ScreenWin::GetScaleFactorForHWND(HWND hwnd) { |
321 if (!g_screen_win_instance) | 332 if (!g_screen_win_instance) |
322 return ScreenWinDisplay().display().device_scale_factor(); | 333 return ScreenWinDisplay().display().device_scale_factor(); |
323 | 334 |
324 DCHECK(hwnd); | 335 DCHECK(hwnd); |
325 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); | 336 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); |
326 ScreenWinDisplay screen_win_display = | 337 ScreenWinDisplay screen_win_display = |
327 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); | 338 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); |
328 return screen_win_display.display().device_scale_factor(); | 339 return screen_win_display.display().device_scale_factor(); |
329 } | 340 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), | 576 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), |
566 reported_scale) == unique_scale_factors.end()) { | 577 reported_scale) == unique_scale_factors.end()) { |
567 unique_scale_factors.push_back(reported_scale); | 578 unique_scale_factors.push_back(reported_scale); |
568 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | 579 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); |
569 } | 580 } |
570 } | 581 } |
571 } | 582 } |
572 | 583 |
573 } // namespace win | 584 } // namespace win |
574 } // namespace display | 585 } // namespace display |
OLD | NEW |