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

Side by Side Diff: ui/display/win/screen_win.cc

Issue 2186163002: Create ScreenWin::GetSystemMetricsInDIP and Correctly Deprecate display::win::GetSystemMetricsInDIP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « ui/display/win/screen_win.h ('k') | ui/display/win/screen_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « ui/display/win/screen_win.h ('k') | ui/display/win/screen_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698