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

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

Issue 2110313002: Add ScreenWin::GetSystemMetricsForHwnd (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self Review Fix Created 4 years, 5 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return ScaleToCeiledSize(size_in_pixels, 1.0f / GetScaleFactorForHWND(hwnd)); 288 return ScaleToCeiledSize(size_in_pixels, 1.0f / GetScaleFactorForHWND(hwnd));
289 } 289 }
290 290
291 // static 291 // static
292 gfx::Size ScreenWin::DIPToScreenSize(HWND hwnd, const gfx::Size& dip_size) { 292 gfx::Size ScreenWin::DIPToScreenSize(HWND hwnd, const gfx::Size& dip_size) {
293 float scale_factor = GetScaleFactorForHWND(hwnd); 293 float scale_factor = GetScaleFactorForHWND(hwnd);
294 // Always ceil sizes. Otherwise we may be leaving off part of the bounds. 294 // Always ceil sizes. Otherwise we may be leaving off part of the bounds.
295 return ScaleToCeiledSize(dip_size, scale_factor); 295 return ScaleToCeiledSize(dip_size, scale_factor);
296 } 296 }
297 297
298 // static
299 int ScreenWin::GetSystemMetricsForHwnd(HWND hwnd, int metric) {
300 // GetSystemMetrics returns screen values based off of the primary monitor's
301 // DPI. This will further scale based off of the DPI for |hwnd|.
302 if (!g_screen_win_instance)
oshima 2016/06/30 19:06:12 is this for unit test case?
robliao 2016/06/30 19:20:24 Yup. This is for the unit tests.
303 return ::GetSystemMetrics(metric);
304
305 Display primary_display(g_screen_win_instance->GetPrimaryDisplay());
306 int system_metrics_result = g_screen_win_instance->GetSystemMetrics(metric);
307
308 float scale_factor = hwnd
309 ? GetScaleFactorForHWND(hwnd) / primary_display.device_scale_factor()
oshima 2016/06/30 19:06:12 calling this "scale factor" is confusing. Can you
robliao 2016/06/30 19:20:24 I went with metrics_relative_scale_factor. How's t
310 : 1.0f;
311 return static_cast<int>(std::round(system_metrics_result * scale_factor));
312 }
313
298 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { 314 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const {
299 NOTREACHED(); 315 NOTREACHED();
300 return nullptr; 316 return nullptr;
301 } 317 }
302 318
303 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { 319 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const {
304 NOTREACHED(); 320 NOTREACHED();
305 return nullptr; 321 return nullptr;
306 } 322 }
307 323
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 428
413 MONITORINFOEX ScreenWin::MonitorInfoFromWindow(HWND hwnd, 429 MONITORINFOEX ScreenWin::MonitorInfoFromWindow(HWND hwnd,
414 DWORD default_options) const { 430 DWORD default_options) const {
415 return MonitorInfoFromHMONITOR(::MonitorFromWindow(hwnd, default_options)); 431 return MonitorInfoFromHMONITOR(::MonitorFromWindow(hwnd, default_options));
416 } 432 }
417 433
418 HWND ScreenWin::GetRootWindow(HWND hwnd) const { 434 HWND ScreenWin::GetRootWindow(HWND hwnd) const {
419 return ::GetAncestor(hwnd, GA_ROOT); 435 return ::GetAncestor(hwnd, GA_ROOT);
420 } 436 }
421 437
438 int ScreenWin::GetSystemMetrics(int metric) const {
439 return ::GetSystemMetrics(metric);
440 }
441
422 void ScreenWin::OnWndProc(HWND hwnd, 442 void ScreenWin::OnWndProc(HWND hwnd,
423 UINT message, 443 UINT message,
424 WPARAM wparam, 444 WPARAM wparam,
425 LPARAM lparam) { 445 LPARAM lparam) {
426 if (message != WM_DISPLAYCHANGE) 446 if (message != WM_DISPLAYCHANGE)
427 return; 447 return;
428 448
429 std::vector<display::Display> old_displays = GetAllDisplays(); 449 std::vector<display::Display> old_displays = GetAllDisplays();
430 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); 450 UpdateFromDisplayInfos(GetDisplayInfosFromSystem());
431 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays()); 451 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, 542 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter,
523 GetterType value) { 543 GetterType value) {
524 if (!g_screen_win_instance) 544 if (!g_screen_win_instance)
525 return ScreenWinDisplay(); 545 return ScreenWinDisplay();
526 546
527 return (g_screen_win_instance->*getter)(value); 547 return (g_screen_win_instance->*getter)(value);
528 } 548 }
529 549
530 } // namespace win 550 } // namespace win
531 } // namespace display 551 } // 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