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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 | 377 |
378 gfx::NativeWindow ScreenWin::GetWindowAtScreenPoint(const gfx::Point& point) { | 378 gfx::NativeWindow ScreenWin::GetWindowAtScreenPoint(const gfx::Point& point) { |
379 gfx::Point point_in_pixels = DIPToScreenPoint(point); | 379 gfx::Point point_in_pixels = DIPToScreenPoint(point); |
380 return GetNativeWindowFromHWND(WindowFromPoint(point_in_pixels.ToPOINT())); | 380 return GetNativeWindowFromHWND(WindowFromPoint(point_in_pixels.ToPOINT())); |
381 } | 381 } |
382 | 382 |
383 int ScreenWin::GetNumDisplays() const { | 383 int ScreenWin::GetNumDisplays() const { |
384 return static_cast<int>(screen_win_displays_.size()); | 384 return static_cast<int>(screen_win_displays_.size()); |
385 } | 385 } |
386 | 386 |
387 std::vector<display::Display> ScreenWin::GetAllDisplays() const { | 387 const std::vector<display::Display>& ScreenWin::GetAllDisplays() const { |
388 return ScreenWinDisplaysToDisplays(screen_win_displays_); | 388 return displays_; |
389 } | 389 } |
390 | 390 |
391 display::Display ScreenWin::GetDisplayNearestWindow( | 391 display::Display ScreenWin::GetDisplayNearestWindow( |
392 gfx::NativeView window) const { | 392 gfx::NativeView window) const { |
393 HWND window_hwnd = GetHWNDFromNativeView(window); | 393 HWND window_hwnd = GetHWNDFromNativeView(window); |
394 if (!window_hwnd) { | 394 if (!window_hwnd) { |
395 // When |window| isn't rooted to a display, we should just return the | 395 // When |window| isn't rooted to a display, we should just return the |
396 // default display so we get some correct display information like the | 396 // default display so we get some correct display information like the |
397 // scaling factor. | 397 // scaling factor. |
398 return GetPrimaryDisplay(); | 398 return GetPrimaryDisplay(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 void ScreenWin::UpdateFromDisplayInfos( | 443 void ScreenWin::UpdateFromDisplayInfos( |
444 const std::vector<DisplayInfo>& display_infos) { | 444 const std::vector<DisplayInfo>& display_infos) { |
445 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos); | 445 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos); |
446 displays_ = ScreenWinDisplaysToDisplays(screen_win_displays_); | |
446 } | 447 } |
447 | 448 |
448 void ScreenWin::Initialize() { | 449 void ScreenWin::Initialize() { |
449 singleton_hwnd_observer_.reset( | 450 singleton_hwnd_observer_.reset( |
450 new gfx::SingletonHwndObserver( | 451 new gfx::SingletonHwndObserver( |
451 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this)))); | 452 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this)))); |
452 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); | 453 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); |
453 RecordDisplayScaleFactors(); | 454 RecordDisplayScaleFactors(); |
454 } | 455 } |
455 | 456 |
(...skipping 24 matching lines...) Expand all Loading... | |
480 return ::GetSystemMetrics(metric); | 481 return ::GetSystemMetrics(metric); |
481 } | 482 } |
482 | 483 |
483 void ScreenWin::OnWndProc(HWND hwnd, | 484 void ScreenWin::OnWndProc(HWND hwnd, |
484 UINT message, | 485 UINT message, |
485 WPARAM wparam, | 486 WPARAM wparam, |
486 LPARAM lparam) { | 487 LPARAM lparam) { |
487 if (message != WM_DISPLAYCHANGE) | 488 if (message != WM_DISPLAYCHANGE) |
488 return; | 489 return; |
489 | 490 |
490 std::vector<display::Display> old_displays = GetAllDisplays(); | 491 const std::vector<display::Display>& old_displays = GetAllDisplays(); |
sadrul
2016/11/12 02:43:00
This looks a bit tricky. Since |displays_| is gett
robliao
2016/11/12 07:07:00
Nice catch. Agreed on this point. Now that I think
riajiang
2016/11/15 20:08:13
Good point! Done.
riajiang
2016/11/15 20:08:13
We are changing GetAllDisplays() to return a const
| |
491 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); | 492 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); |
492 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays()); | 493 change_notifier_.NotifyDisplaysChanged(old_displays, GetAllDisplays()); |
493 } | 494 } |
494 | 495 |
495 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd) | 496 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd) |
496 const { | 497 const { |
497 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd, | 498 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd, |
498 MONITOR_DEFAULTTONEAREST)); | 499 MONITOR_DEFAULTTONEAREST)); |
499 } | 500 } |
500 | 501 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), | 589 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), |
589 reported_scale) == unique_scale_factors.end()) { | 590 reported_scale) == unique_scale_factors.end()) { |
590 unique_scale_factors.push_back(reported_scale); | 591 unique_scale_factors.push_back(reported_scale); |
591 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | 592 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); |
592 } | 593 } |
593 } | 594 } |
594 } | 595 } |
595 | 596 |
596 } // namespace win | 597 } // namespace win |
597 } // namespace display | 598 } // namespace display |
OLD | NEW |