| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) |
| 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 metrics_relative_scale_factor = hwnd |
| 309 ? GetScaleFactorForHWND(hwnd) / primary_display.device_scale_factor() |
| 310 : 1.0f; |
| 311 return static_cast<int>(std::round( |
| 312 system_metrics_result * metrics_relative_scale_factor)); |
| 313 } |
| 314 |
| 298 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { | 315 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { |
| 299 NOTREACHED(); | 316 NOTREACHED(); |
| 300 return nullptr; | 317 return nullptr; |
| 301 } | 318 } |
| 302 | 319 |
| 303 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { | 320 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
| 304 NOTREACHED(); | 321 NOTREACHED(); |
| 305 return nullptr; | 322 return nullptr; |
| 306 } | 323 } |
| 307 | 324 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 429 |
| 413 MONITORINFOEX ScreenWin::MonitorInfoFromWindow(HWND hwnd, | 430 MONITORINFOEX ScreenWin::MonitorInfoFromWindow(HWND hwnd, |
| 414 DWORD default_options) const { | 431 DWORD default_options) const { |
| 415 return MonitorInfoFromHMONITOR(::MonitorFromWindow(hwnd, default_options)); | 432 return MonitorInfoFromHMONITOR(::MonitorFromWindow(hwnd, default_options)); |
| 416 } | 433 } |
| 417 | 434 |
| 418 HWND ScreenWin::GetRootWindow(HWND hwnd) const { | 435 HWND ScreenWin::GetRootWindow(HWND hwnd) const { |
| 419 return ::GetAncestor(hwnd, GA_ROOT); | 436 return ::GetAncestor(hwnd, GA_ROOT); |
| 420 } | 437 } |
| 421 | 438 |
| 439 int ScreenWin::GetSystemMetrics(int metric) const { |
| 440 return ::GetSystemMetrics(metric); |
| 441 } |
| 442 |
| 422 void ScreenWin::OnWndProc(HWND hwnd, | 443 void ScreenWin::OnWndProc(HWND hwnd, |
| 423 UINT message, | 444 UINT message, |
| 424 WPARAM wparam, | 445 WPARAM wparam, |
| 425 LPARAM lparam) { | 446 LPARAM lparam) { |
| 426 if (message != WM_DISPLAYCHANGE) | 447 if (message != WM_DISPLAYCHANGE) |
| 427 return; | 448 return; |
| 428 | 449 |
| 429 std::vector<display::Display> old_displays = GetAllDisplays(); | 450 std::vector<display::Display> old_displays = GetAllDisplays(); |
| 430 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); | 451 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); |
| 431 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays()); | 452 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, | 543 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, |
| 523 GetterType value) { | 544 GetterType value) { |
| 524 if (!g_screen_win_instance) | 545 if (!g_screen_win_instance) |
| 525 return ScreenWinDisplay(); | 546 return ScreenWinDisplay(); |
| 526 | 547 |
| 527 return (g_screen_win_instance->*getter)(value); | 548 return (g_screen_win_instance->*getter)(value); |
| 528 } | 549 } |
| 529 | 550 |
| 530 } // namespace win | 551 } // namespace win |
| 531 } // namespace display | 552 } // namespace display |
| OLD | NEW |