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

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

Issue 2510793002: Use actual value of display scale factor from GetMonitorScaleFactor().
Patch Set: Created 4 years, 1 month 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/views/win/hwnd_message_handler.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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr; 433 HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr;
434 return ScreenToDIPRect(hwnd, screen_rect); 434 return ScreenToDIPRect(hwnd, screen_rect);
435 } 435 }
436 436
437 gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeView view, 437 gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeView view,
438 const gfx::Rect& dip_rect) const { 438 const gfx::Rect& dip_rect) const {
439 HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr; 439 HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr;
440 return DIPToScreenRect(hwnd, dip_rect); 440 return DIPToScreenRect(hwnd, dip_rect);
441 } 441 }
442 442
443 float ScreenWin::GetScaleFactorForWindow(gfx::NativeView view) const {
444 HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr;
445 return GetMonitorScaleFactor(
Andrey Kraynov 2016/11/16 18:33:47 Another possible and simple way to fix this issue
sadrul 2016/11/16 20:38:17 I think that would make sense, yeah. Is that possi
robliao 2016/11/16 20:56:17 WM_DPICHANGED is fired when an HWND is associated
446 ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY));
447 }
448
443 void ScreenWin::UpdateFromDisplayInfos( 449 void ScreenWin::UpdateFromDisplayInfos(
444 const std::vector<DisplayInfo>& display_infos) { 450 const std::vector<DisplayInfo>& display_infos) {
445 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos); 451 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos);
446 } 452 }
447 453
448 void ScreenWin::Initialize() { 454 void ScreenWin::Initialize() {
449 singleton_hwnd_observer_.reset( 455 singleton_hwnd_observer_.reset(
450 new gfx::SingletonHwndObserver( 456 new gfx::SingletonHwndObserver(
451 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this)))); 457 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this))));
452 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); 458 UpdateFromDisplayInfos(GetDisplayInfosFromSystem());
(...skipping 27 matching lines...) Expand all
480 return ::GetSystemMetrics(metric); 486 return ::GetSystemMetrics(metric);
481 } 487 }
482 488
483 void ScreenWin::OnWndProc(HWND hwnd, 489 void ScreenWin::OnWndProc(HWND hwnd,
484 UINT message, 490 UINT message,
485 WPARAM wparam, 491 WPARAM wparam,
486 LPARAM lparam) { 492 LPARAM lparam) {
487 if (message != WM_DISPLAYCHANGE) 493 if (message != WM_DISPLAYCHANGE)
488 return; 494 return;
489 495
496 LOG(ERROR) << "ScreenWin::OnWndProc(WM_DISPLAYCHANGE)";
490 std::vector<display::Display> old_displays = GetAllDisplays(); 497 std::vector<display::Display> old_displays = GetAllDisplays();
491 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); 498 UpdateFromDisplayInfos(GetDisplayInfosFromSystem());
492 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays()); 499 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays());
493 } 500 }
494 501
495 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd) 502 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd)
496 const { 503 const {
497 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd, 504 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd,
498 MONITOR_DEFAULTTONEAREST)); 505 MONITOR_DEFAULTTONEAREST));
499 } 506 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), 595 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(),
589 reported_scale) == unique_scale_factors.end()) { 596 reported_scale) == unique_scale_factors.end()) {
590 unique_scale_factors.push_back(reported_scale); 597 unique_scale_factors.push_back(reported_scale);
591 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); 598 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale);
592 } 599 }
593 } 600 }
594 } 601 }
595 602
596 } // namespace win 603 } // namespace win
597 } // namespace display 604 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/win/screen_win.h ('k') | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698