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

Unified Diff: ui/display/win/screen_win.cc

Issue 2267123002: Scale Rect Origins Using the Specified HWND's Display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/display/win/screen_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/display/win/screen_win.cc
diff --git a/ui/display/win/screen_win.cc b/ui/display/win/screen_win.cc
index d9f85c364bfe6f3aa5cf6329878da36ed1fca2a1..3090a7d727c614cce0df5c434740db400bb68456 100644
--- a/ui/display/win/screen_win.cc
+++ b/ui/display/win/screen_win.cc
@@ -253,25 +253,35 @@ gfx::Point ScreenWin::DIPToClientPoint(HWND hwnd, const gfx::Point& dip_point) {
// static
gfx::Rect ScreenWin::ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
- float scale_factor = hwnd ?
- GetScaleFactorForHWND(hwnd) :
- GetScreenWinDisplayVia(
- &ScreenWin::GetScreenWinDisplayNearestScreenRect, pixel_bounds).
- display().device_scale_factor();
+ const ScreenWinDisplay screen_win_display = hwnd
+ ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd)
+ : GetScreenWinDisplayVia(
+ &ScreenWin::GetScreenWinDisplayNearestScreenRect, pixel_bounds);
+ float scale_factor = screen_win_display.display().device_scale_factor();
gfx::Rect dip_rect = ScaleToEnclosingRect(pixel_bounds, 1.0f / scale_factor);
- dip_rect.set_origin(ScreenToDIPPoint(pixel_bounds.origin()));
+ const display::Display display = screen_win_display.display();
+ dip_rect.set_origin(ScalePointRelative(
+ screen_win_display.pixel_bounds().origin(),
+ display.bounds().origin(),
+ 1.0f / scale_factor,
+ pixel_bounds.origin()));
return dip_rect;
}
// static
gfx::Rect ScreenWin::DIPToScreenRect(HWND hwnd, const gfx::Rect& dip_bounds) {
- float scale_factor = hwnd ?
- GetScaleFactorForHWND(hwnd) :
- GetScreenWinDisplayVia(
- &ScreenWin::GetScreenWinDisplayNearestDIPRect, dip_bounds).display().
- device_scale_factor();
+ const ScreenWinDisplay screen_win_display = hwnd
+ ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd)
+ : GetScreenWinDisplayVia(
+ &ScreenWin::GetScreenWinDisplayNearestDIPRect, dip_bounds);
+ float scale_factor = screen_win_display.display().device_scale_factor();
gfx::Rect screen_rect = ScaleToEnclosingRect(dip_bounds, scale_factor);
- screen_rect.set_origin(DIPToScreenPoint(dip_bounds.origin()));
+ const display::Display display = screen_win_display.display();
+ screen_rect.set_origin(ScalePointRelative(
+ display.bounds().origin(),
+ screen_win_display.pixel_bounds().origin(),
+ scale_factor,
+ dip_bounds.origin()));
return screen_rect;
}
@@ -519,11 +529,11 @@ ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPRect(
for (const auto& screen_win_display : screen_win_displays_) {
display::Display display = screen_win_display.display();
gfx::Rect dip_bounds = display.bounds();
+ if (dip_rect.Intersects(dip_bounds))
+ return screen_win_display;
int64_t distance_squared = SquaredDistanceBetweenRects(dip_rect,
dip_bounds);
- if (distance_squared == 0) {
- return screen_win_display;
- } else if (distance_squared < closest_distance_squared) {
+ if (distance_squared < closest_distance_squared) {
closest_distance_squared = distance_squared;
closest_screen_win_display = screen_win_display;
}
« no previous file with comments | « no previous file | ui/display/win/screen_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698