| 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 // GetSystemMetrics returns screen values based off of the primary monitor's |
| 325 // DPI. |
| 326 Display primary_display(g_screen_win_instance->GetPrimaryDisplay()); |
| 327 int system_metrics_result = g_screen_win_instance->GetSystemMetrics(metric); |
| 328 return static_cast<int>(std::round( |
| 329 system_metrics_result / primary_display.device_scale_factor())); |
| 330 } |
| 331 |
| 332 // static |
| 320 float ScreenWin::GetScaleFactorForHWND(HWND hwnd) { | 333 float ScreenWin::GetScaleFactorForHWND(HWND hwnd) { |
| 321 if (!g_screen_win_instance) | 334 if (!g_screen_win_instance) |
| 322 return ScreenWinDisplay().display().device_scale_factor(); | 335 return ScreenWinDisplay().display().device_scale_factor(); |
| 323 | 336 |
| 324 DCHECK(hwnd); | 337 DCHECK(hwnd); |
| 325 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); | 338 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); |
| 326 ScreenWinDisplay screen_win_display = | 339 ScreenWinDisplay screen_win_display = |
| 327 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); | 340 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); |
| 328 return screen_win_display.display().device_scale_factor(); | 341 return screen_win_display.display().device_scale_factor(); |
| 329 } | 342 } |
| (...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(), | 578 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), |
| 566 reported_scale) == unique_scale_factors.end()) { | 579 reported_scale) == unique_scale_factors.end()) { |
| 567 unique_scale_factors.push_back(reported_scale); | 580 unique_scale_factors.push_back(reported_scale); |
| 568 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | 581 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); |
| 569 } | 582 } |
| 570 } | 583 } |
| 571 } | 584 } |
| 572 | 585 |
| 573 } // namespace win | 586 } // namespace win |
| 574 } // namespace display | 587 } // namespace display |
| OLD | NEW |