| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 246 } |
| 247 | 247 |
| 248 // static | 248 // static |
| 249 gfx::Point ScreenWin::DIPToClientPoint(HWND hwnd, const gfx::Point& dip_point) { | 249 gfx::Point ScreenWin::DIPToClientPoint(HWND hwnd, const gfx::Point& dip_point) { |
| 250 float scale_factor = GetScaleFactorForHWND(hwnd); | 250 float scale_factor = GetScaleFactorForHWND(hwnd); |
| 251 return ScaleToFlooredPoint(dip_point, scale_factor); | 251 return ScaleToFlooredPoint(dip_point, scale_factor); |
| 252 } | 252 } |
| 253 | 253 |
| 254 // static | 254 // static |
| 255 gfx::Rect ScreenWin::ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) { | 255 gfx::Rect ScreenWin::ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) { |
| 256 float scale_factor = hwnd ? | 256 const ScreenWinDisplay screen_win_display = hwnd |
| 257 GetScaleFactorForHWND(hwnd) : | 257 ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd) |
| 258 GetScreenWinDisplayVia( | 258 : GetScreenWinDisplayVia( |
| 259 &ScreenWin::GetScreenWinDisplayNearestScreenRect, pixel_bounds). | 259 &ScreenWin::GetScreenWinDisplayNearestScreenRect, pixel_bounds); |
| 260 display().device_scale_factor(); | 260 float scale_factor = screen_win_display.display().device_scale_factor(); |
| 261 gfx::Rect dip_rect = ScaleToEnclosingRect(pixel_bounds, 1.0f / scale_factor); | 261 gfx::Rect dip_rect = ScaleToEnclosingRect(pixel_bounds, 1.0f / scale_factor); |
| 262 dip_rect.set_origin(ScreenToDIPPoint(pixel_bounds.origin())); | 262 const display::Display display = screen_win_display.display(); |
| 263 dip_rect.set_origin(ScalePointRelative( |
| 264 screen_win_display.pixel_bounds().origin(), |
| 265 display.bounds().origin(), |
| 266 1.0f / scale_factor, |
| 267 pixel_bounds.origin())); |
| 263 return dip_rect; | 268 return dip_rect; |
| 264 } | 269 } |
| 265 | 270 |
| 266 // static | 271 // static |
| 267 gfx::Rect ScreenWin::DIPToScreenRect(HWND hwnd, const gfx::Rect& dip_bounds) { | 272 gfx::Rect ScreenWin::DIPToScreenRect(HWND hwnd, const gfx::Rect& dip_bounds) { |
| 268 float scale_factor = hwnd ? | 273 const ScreenWinDisplay screen_win_display = hwnd |
| 269 GetScaleFactorForHWND(hwnd) : | 274 ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd) |
| 270 GetScreenWinDisplayVia( | 275 : GetScreenWinDisplayVia( |
| 271 &ScreenWin::GetScreenWinDisplayNearestDIPRect, dip_bounds).display(). | 276 &ScreenWin::GetScreenWinDisplayNearestDIPRect, dip_bounds); |
| 272 device_scale_factor(); | 277 float scale_factor = screen_win_display.display().device_scale_factor(); |
| 273 gfx::Rect screen_rect = ScaleToEnclosingRect(dip_bounds, scale_factor); | 278 gfx::Rect screen_rect = ScaleToEnclosingRect(dip_bounds, scale_factor); |
| 274 screen_rect.set_origin(DIPToScreenPoint(dip_bounds.origin())); | 279 const display::Display display = screen_win_display.display(); |
| 280 screen_rect.set_origin(ScalePointRelative( |
| 281 display.bounds().origin(), |
| 282 screen_win_display.pixel_bounds().origin(), |
| 283 scale_factor, |
| 284 dip_bounds.origin())); |
| 275 return screen_rect; | 285 return screen_rect; |
| 276 } | 286 } |
| 277 | 287 |
| 278 // static | 288 // static |
| 279 gfx::Rect ScreenWin::ClientToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) { | 289 gfx::Rect ScreenWin::ClientToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) { |
| 280 return ScaleToEnclosingRect(pixel_bounds, 1.0f / GetScaleFactorForHWND(hwnd)); | 290 return ScaleToEnclosingRect(pixel_bounds, 1.0f / GetScaleFactorForHWND(hwnd)); |
| 281 } | 291 } |
| 282 | 292 |
| 283 // static | 293 // static |
| 284 gfx::Rect ScreenWin::DIPToClientRect(HWND hwnd, const gfx::Rect& dip_bounds) { | 294 gfx::Rect ScreenWin::DIPToClientRect(HWND hwnd, const gfx::Rect& dip_bounds) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 return primary_screen_win_display; | 522 return primary_screen_win_display; |
| 513 } | 523 } |
| 514 | 524 |
| 515 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPRect( | 525 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPRect( |
| 516 const gfx::Rect& dip_rect) const { | 526 const gfx::Rect& dip_rect) const { |
| 517 ScreenWinDisplay closest_screen_win_display; | 527 ScreenWinDisplay closest_screen_win_display; |
| 518 int64_t closest_distance_squared = INT64_MAX; | 528 int64_t closest_distance_squared = INT64_MAX; |
| 519 for (const auto& screen_win_display : screen_win_displays_) { | 529 for (const auto& screen_win_display : screen_win_displays_) { |
| 520 display::Display display = screen_win_display.display(); | 530 display::Display display = screen_win_display.display(); |
| 521 gfx::Rect dip_bounds = display.bounds(); | 531 gfx::Rect dip_bounds = display.bounds(); |
| 532 if (dip_rect.Intersects(dip_bounds)) |
| 533 return screen_win_display; |
| 522 int64_t distance_squared = SquaredDistanceBetweenRects(dip_rect, | 534 int64_t distance_squared = SquaredDistanceBetweenRects(dip_rect, |
| 523 dip_bounds); | 535 dip_bounds); |
| 524 if (distance_squared == 0) { | 536 if (distance_squared < closest_distance_squared) { |
| 525 return screen_win_display; | |
| 526 } else if (distance_squared < closest_distance_squared) { | |
| 527 closest_distance_squared = distance_squared; | 537 closest_distance_squared = distance_squared; |
| 528 closest_screen_win_display = screen_win_display; | 538 closest_screen_win_display = screen_win_display; |
| 529 } | 539 } |
| 530 } | 540 } |
| 531 return closest_screen_win_display; | 541 return closest_screen_win_display; |
| 532 } | 542 } |
| 533 | 543 |
| 534 ScreenWinDisplay ScreenWin::GetPrimaryScreenWinDisplay() const { | 544 ScreenWinDisplay ScreenWin::GetPrimaryScreenWinDisplay() const { |
| 535 MONITORINFOEX monitor_info = MonitorInfoFromWindow(nullptr, | 545 MONITORINFOEX monitor_info = MonitorInfoFromWindow(nullptr, |
| 536 MONITOR_DEFAULTTOPRIMARY); | 546 MONITOR_DEFAULTTOPRIMARY); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), | 588 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), |
| 579 reported_scale) == unique_scale_factors.end()) { | 589 reported_scale) == unique_scale_factors.end()) { |
| 580 unique_scale_factors.push_back(reported_scale); | 590 unique_scale_factors.push_back(reported_scale); |
| 581 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | 591 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); |
| 582 } | 592 } |
| 583 } | 593 } |
| 584 } | 594 } |
| 585 | 595 |
| 586 } // namespace win | 596 } // namespace win |
| 587 } // namespace display | 597 } // namespace display |
| OLD | NEW |