| 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 17 matching lines...) Expand all Loading... |
| 28 namespace display { | 28 namespace display { |
| 29 namespace win { | 29 namespace win { |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // TODO(robliao): http://crbug.com/615514 Remove when ScreenWin usage is | 32 // TODO(robliao): http://crbug.com/615514 Remove when ScreenWin usage is |
| 33 // resolved with Desktop Aura and WindowTreeHost. | 33 // resolved with Desktop Aura and WindowTreeHost. |
| 34 ScreenWin* g_screen_win_instance = nullptr; | 34 ScreenWin* g_screen_win_instance = nullptr; |
| 35 | 35 |
| 36 float GetMonitorScaleFactor(HMONITOR monitor) { | 36 float GetMonitorScaleFactor(HMONITOR monitor) { |
| 37 DCHECK(monitor); | 37 DCHECK(monitor); |
| 38 if (display::Display::HasForceDeviceScaleFactor()) | 38 if (Display::HasForceDeviceScaleFactor()) |
| 39 return display::Display::GetForcedDeviceScaleFactor(); | 39 return Display::GetForcedDeviceScaleFactor(); |
| 40 | 40 |
| 41 if (base::win::IsProcessPerMonitorDpiAware()) { | 41 if (base::win::IsProcessPerMonitorDpiAware()) { |
| 42 static auto get_dpi_for_monitor_func = [](){ | 42 static auto get_dpi_for_monitor_func = [](){ |
| 43 using GetDpiForMonitorPtr = decltype(::GetDpiForMonitor)*; | 43 using GetDpiForMonitorPtr = decltype(::GetDpiForMonitor)*; |
| 44 HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll"); | 44 HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll"); |
| 45 if (shcore_dll) { | 45 if (shcore_dll) { |
| 46 return reinterpret_cast<GetDpiForMonitorPtr>( | 46 return reinterpret_cast<GetDpiForMonitorPtr>( |
| 47 ::GetProcAddress(shcore_dll, "GetDpiForMonitor")); | 47 ::GetProcAddress(shcore_dll, "GetDpiForMonitor")); |
| 48 } | 48 } |
| 49 return static_cast<GetDpiForMonitorPtr>(nullptr); | 49 return static_cast<GetDpiForMonitorPtr>(nullptr); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 71 const DisplayInfo& display_info) { | 71 const DisplayInfo& display_info) { |
| 72 if (DisplayInfosTouch(ref_display_info, display_info)) { | 72 if (DisplayInfosTouch(ref_display_info, display_info)) { |
| 73 touching_display_infos.push_back(display_info); | 73 touching_display_infos.push_back(display_info); |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 return false; | 76 return false; |
| 77 }), display_infos->end()); | 77 }), display_infos->end()); |
| 78 return touching_display_infos; | 78 return touching_display_infos; |
| 79 } | 79 } |
| 80 | 80 |
| 81 display::Display CreateDisplayFromDisplayInfo(const DisplayInfo& display_info) { | 81 Display CreateDisplayFromDisplayInfo(const DisplayInfo& display_info) { |
| 82 display::Display display(display_info.id()); | 82 Display display(display_info.id()); |
| 83 float scale_factor = display_info.device_scale_factor(); | 83 float scale_factor = display_info.device_scale_factor(); |
| 84 display.set_device_scale_factor(scale_factor); | 84 display.set_device_scale_factor(scale_factor); |
| 85 display.set_work_area( | 85 display.set_work_area( |
| 86 gfx::ScaleToEnclosingRect(display_info.screen_work_rect(), | 86 gfx::ScaleToEnclosingRect(display_info.screen_work_rect(), |
| 87 1.0f / scale_factor)); | 87 1.0f / scale_factor)); |
| 88 display.set_bounds(gfx::ScaleToEnclosingRect(display_info.screen_rect(), | 88 display.set_bounds(gfx::ScaleToEnclosingRect(display_info.screen_rect(), |
| 89 1.0f / scale_factor)); | 89 1.0f / scale_factor)); |
| 90 display.set_rotation(display_info.rotation()); | 90 display.set_rotation(display_info.rotation()); |
| 91 return display; | 91 return display; |
| 92 } | 92 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 115 auto primary_display_iter = std::find_if( | 115 auto primary_display_iter = std::find_if( |
| 116 display_infos_remaining.begin(), display_infos_remaining.end(), []( | 116 display_infos_remaining.begin(), display_infos_remaining.end(), []( |
| 117 const DisplayInfo& display_info) { | 117 const DisplayInfo& display_info) { |
| 118 return display_info.screen_rect().origin().IsOrigin(); | 118 return display_info.screen_rect().origin().IsOrigin(); |
| 119 }); | 119 }); |
| 120 DCHECK(primary_display_iter != display_infos_remaining.end()) << | 120 DCHECK(primary_display_iter != display_infos_remaining.end()) << |
| 121 "Missing primary display."; | 121 "Missing primary display."; |
| 122 | 122 |
| 123 std::vector<DisplayInfo> available_parents; | 123 std::vector<DisplayInfo> available_parents; |
| 124 available_parents.push_back(*primary_display_iter); | 124 available_parents.push_back(*primary_display_iter); |
| 125 display::DisplayLayoutBuilder builder(primary_display_iter->id()); | 125 DisplayLayoutBuilder builder(primary_display_iter->id()); |
| 126 display_infos_remaining.erase(primary_display_iter); | 126 display_infos_remaining.erase(primary_display_iter); |
| 127 // Build the tree and determine DisplayPlacements along the way. | 127 // Build the tree and determine DisplayPlacements along the way. |
| 128 while (available_parents.size()) { | 128 while (available_parents.size()) { |
| 129 const DisplayInfo parent = available_parents.back(); | 129 const DisplayInfo parent = available_parents.back(); |
| 130 available_parents.pop_back(); | 130 available_parents.pop_back(); |
| 131 for (const auto& child : | 131 for (const auto& child : |
| 132 FindAndRemoveTouchingDisplayInfos(parent, &display_infos_remaining)) { | 132 FindAndRemoveTouchingDisplayInfos(parent, &display_infos_remaining)) { |
| 133 builder.AddDisplayPlacement(CalculateDisplayPlacement(parent, child)); | 133 builder.AddDisplayPlacement(CalculateDisplayPlacement(parent, child)); |
| 134 available_parents.push_back(child); | 134 available_parents.push_back(child); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Layout and create the ScreenWinDisplays. | 138 // Layout and create the ScreenWinDisplays. |
| 139 std::vector<display::Display> displays; | 139 std::vector<Display> displays; |
| 140 for (const auto& display_info : display_infos) | 140 for (const auto& display_info : display_infos) |
| 141 displays.push_back(CreateDisplayFromDisplayInfo(display_info)); | 141 displays.push_back(CreateDisplayFromDisplayInfo(display_info)); |
| 142 | 142 |
| 143 std::unique_ptr<display::DisplayLayout> layout(builder.Build()); | 143 std::unique_ptr<DisplayLayout> layout(builder.Build()); |
| 144 layout->ApplyToDisplayList(&displays, nullptr, 0); | 144 layout->ApplyToDisplayList(&displays, nullptr, 0); |
| 145 | 145 |
| 146 std::vector<ScreenWinDisplay> screen_win_displays; | 146 std::vector<ScreenWinDisplay> screen_win_displays; |
| 147 const size_t num_displays = display_infos.size(); | 147 const size_t num_displays = display_infos.size(); |
| 148 for (size_t i = 0; i < num_displays; ++i) | 148 for (size_t i = 0; i < num_displays; ++i) |
| 149 screen_win_displays.emplace_back(displays[i], display_infos[i]); | 149 screen_win_displays.emplace_back(displays[i], display_infos[i]); |
| 150 | 150 |
| 151 return screen_win_displays; | 151 return screen_win_displays; |
| 152 } | 152 } |
| 153 | 153 |
| 154 std::vector<display::Display> ScreenWinDisplaysToDisplays( | 154 std::vector<Display> ScreenWinDisplaysToDisplays( |
| 155 const std::vector<ScreenWinDisplay>& screen_win_displays) { | 155 const std::vector<ScreenWinDisplay>& screen_win_displays) { |
| 156 std::vector<display::Display> displays; | 156 std::vector<Display> displays; |
| 157 for (const auto& screen_win_display : screen_win_displays) | 157 for (const auto& screen_win_display : screen_win_displays) |
| 158 displays.push_back(screen_win_display.display()); | 158 displays.push_back(screen_win_display.display()); |
| 159 | 159 |
| 160 return displays; | 160 return displays; |
| 161 } | 161 } |
| 162 | 162 |
| 163 MONITORINFOEX MonitorInfoFromHMONITOR(HMONITOR monitor) { | 163 MONITORINFOEX MonitorInfoFromHMONITOR(HMONITOR monitor) { |
| 164 MONITORINFOEX monitor_info; | 164 MONITORINFOEX monitor_info; |
| 165 ::ZeroMemory(&monitor_info, sizeof(monitor_info)); | 165 ::ZeroMemory(&monitor_info, sizeof(monitor_info)); |
| 166 monitor_info.cbSize = sizeof(monitor_info); | 166 monitor_info.cbSize = sizeof(monitor_info); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 ScreenWin::~ScreenWin() { | 213 ScreenWin::~ScreenWin() { |
| 214 DCHECK_EQ(g_screen_win_instance, this); | 214 DCHECK_EQ(g_screen_win_instance, this); |
| 215 g_screen_win_instance = nullptr; | 215 g_screen_win_instance = nullptr; |
| 216 } | 216 } |
| 217 | 217 |
| 218 // static | 218 // static |
| 219 gfx::Point ScreenWin::ScreenToDIPPoint(const gfx::Point& pixel_point) { | 219 gfx::Point ScreenWin::ScreenToDIPPoint(const gfx::Point& pixel_point) { |
| 220 const ScreenWinDisplay screen_win_display = | 220 const ScreenWinDisplay screen_win_display = |
| 221 GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestScreenPoint, | 221 GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestScreenPoint, |
| 222 pixel_point); | 222 pixel_point); |
| 223 const display::Display display = screen_win_display.display(); | 223 const Display display = screen_win_display.display(); |
| 224 return ScalePointRelative(screen_win_display.pixel_bounds().origin(), | 224 return ScalePointRelative(screen_win_display.pixel_bounds().origin(), |
| 225 display.bounds().origin(), | 225 display.bounds().origin(), |
| 226 1.0f / display.device_scale_factor(), | 226 1.0f / display.device_scale_factor(), |
| 227 pixel_point); | 227 pixel_point); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // static | 230 // static |
| 231 gfx::Point ScreenWin::DIPToScreenPoint(const gfx::Point& dip_point) { | 231 gfx::Point ScreenWin::DIPToScreenPoint(const gfx::Point& dip_point) { |
| 232 const ScreenWinDisplay screen_win_display = | 232 const ScreenWinDisplay screen_win_display = |
| 233 GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestDIPPoint, | 233 GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestDIPPoint, |
| 234 dip_point); | 234 dip_point); |
| 235 const display::Display display = screen_win_display.display(); | 235 const Display display = screen_win_display.display(); |
| 236 return ScalePointRelative(display.bounds().origin(), | 236 return ScalePointRelative(display.bounds().origin(), |
| 237 screen_win_display.pixel_bounds().origin(), | 237 screen_win_display.pixel_bounds().origin(), |
| 238 display.device_scale_factor(), | 238 display.device_scale_factor(), |
| 239 dip_point); | 239 dip_point); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // static | 242 // static |
| 243 gfx::Point ScreenWin::ClientToDIPPoint(HWND hwnd, | 243 gfx::Point ScreenWin::ClientToDIPPoint(HWND hwnd, |
| 244 const gfx::Point& client_point) { | 244 const gfx::Point& client_point) { |
| 245 return ScaleToFlooredPoint(client_point, 1.0f / GetScaleFactorForHWND(hwnd)); | 245 return ScaleToFlooredPoint(client_point, 1.0f / GetScaleFactorForHWND(hwnd)); |
| 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 const ScreenWinDisplay screen_win_display = hwnd | 256 const ScreenWinDisplay screen_win_display = hwnd |
| 257 ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd) | 257 ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd) |
| 258 : GetScreenWinDisplayVia( | 258 : GetScreenWinDisplayVia( |
| 259 &ScreenWin::GetScreenWinDisplayNearestScreenRect, pixel_bounds); | 259 &ScreenWin::GetScreenWinDisplayNearestScreenRect, pixel_bounds); |
| 260 float scale_factor = screen_win_display.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 const display::Display display = screen_win_display.display(); | 262 const Display display = screen_win_display.display(); |
| 263 dip_rect.set_origin(ScalePointRelative( | 263 dip_rect.set_origin(ScalePointRelative( |
| 264 screen_win_display.pixel_bounds().origin(), | 264 screen_win_display.pixel_bounds().origin(), |
| 265 display.bounds().origin(), | 265 display.bounds().origin(), |
| 266 1.0f / scale_factor, | 266 1.0f / scale_factor, |
| 267 pixel_bounds.origin())); | 267 pixel_bounds.origin())); |
| 268 return dip_rect; | 268 return dip_rect; |
| 269 } | 269 } |
| 270 | 270 |
| 271 // static | 271 // static |
| 272 gfx::Rect ScreenWin::DIPToScreenRect(HWND hwnd, const gfx::Rect& dip_bounds) { | 272 gfx::Rect ScreenWin::DIPToScreenRect(HWND hwnd, const gfx::Rect& dip_bounds) { |
| 273 const ScreenWinDisplay screen_win_display = hwnd | 273 const ScreenWinDisplay screen_win_display = hwnd |
| 274 ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd) | 274 ? GetScreenWinDisplayVia(&ScreenWin::GetScreenWinDisplayNearestHWND, hwnd) |
| 275 : GetScreenWinDisplayVia( | 275 : GetScreenWinDisplayVia( |
| 276 &ScreenWin::GetScreenWinDisplayNearestDIPRect, dip_bounds); | 276 &ScreenWin::GetScreenWinDisplayNearestDIPRect, dip_bounds); |
| 277 float scale_factor = screen_win_display.display().device_scale_factor(); | 277 float scale_factor = screen_win_display.display().device_scale_factor(); |
| 278 gfx::Rect screen_rect = ScaleToEnclosingRect(dip_bounds, scale_factor); | 278 gfx::Rect screen_rect = ScaleToEnclosingRect(dip_bounds, scale_factor); |
| 279 const display::Display display = screen_win_display.display(); | 279 const Display display = screen_win_display.display(); |
| 280 screen_rect.set_origin(ScalePointRelative( | 280 screen_rect.set_origin(ScalePointRelative( |
| 281 display.bounds().origin(), | 281 display.bounds().origin(), |
| 282 screen_win_display.pixel_bounds().origin(), | 282 screen_win_display.pixel_bounds().origin(), |
| 283 scale_factor, | 283 scale_factor, |
| 284 dip_bounds.origin())); | 284 dip_bounds.origin())); |
| 285 return screen_rect; | 285 return screen_rect; |
| 286 } | 286 } |
| 287 | 287 |
| 288 // static | 288 // static |
| 289 gfx::Rect ScreenWin::ClientToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) { | 289 gfx::Rect ScreenWin::ClientToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) { |
| (...skipping 87 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 const std::vector<display::Display>& ScreenWin::GetAllDisplays() const { | 387 const std::vector<Display>& ScreenWin::GetAllDisplays() const { |
| 388 return displays_; | 388 return displays_; |
| 389 } | 389 } |
| 390 | 390 |
| 391 display::Display ScreenWin::GetDisplayNearestWindow( | 391 Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { |
| 392 gfx::NativeView window) const { | |
| 393 HWND window_hwnd = GetHWNDFromNativeView(window); | 392 HWND window_hwnd = GetHWNDFromNativeView(window); |
| 394 if (!window_hwnd) { | 393 if (!window_hwnd) { |
| 395 // When |window| isn't rooted to a display, we should just return the | 394 // 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 | 395 // default display so we get some correct display information like the |
| 397 // scaling factor. | 396 // scaling factor. |
| 398 return GetPrimaryDisplay(); | 397 return GetPrimaryDisplay(); |
| 399 } | 398 } |
| 400 ScreenWinDisplay screen_win_display = | 399 ScreenWinDisplay screen_win_display = |
| 401 GetScreenWinDisplayNearestHWND(window_hwnd); | 400 GetScreenWinDisplayNearestHWND(window_hwnd); |
| 402 return screen_win_display.display(); | 401 return screen_win_display.display(); |
| 403 } | 402 } |
| 404 | 403 |
| 405 Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { | 404 Display ScreenWin::GetDisplayNearestPoint(const gfx::Point& point) const { |
| 406 gfx::Point screen_point(DIPToScreenPoint(point)); | 405 gfx::Point screen_point(DIPToScreenPoint(point)); |
| 407 ScreenWinDisplay screen_win_display = | 406 ScreenWinDisplay screen_win_display = |
| 408 GetScreenWinDisplayNearestScreenPoint(screen_point); | 407 GetScreenWinDisplayNearestScreenPoint(screen_point); |
| 409 return screen_win_display.display(); | 408 return screen_win_display.display(); |
| 410 } | 409 } |
| 411 | 410 |
| 412 display::Display ScreenWin::GetDisplayMatching( | 411 Display ScreenWin::GetDisplayMatching(const gfx::Rect& match_rect) const { |
| 413 const gfx::Rect& match_rect) const { | |
| 414 ScreenWinDisplay screen_win_display = | 412 ScreenWinDisplay screen_win_display = |
| 415 GetScreenWinDisplayNearestScreenRect(match_rect); | 413 GetScreenWinDisplayNearestScreenRect(match_rect); |
| 416 return screen_win_display.display(); | 414 return screen_win_display.display(); |
| 417 } | 415 } |
| 418 | 416 |
| 419 display::Display ScreenWin::GetPrimaryDisplay() const { | 417 Display ScreenWin::GetPrimaryDisplay() const { |
| 420 return GetPrimaryScreenWinDisplay().display(); | 418 return GetPrimaryScreenWinDisplay().display(); |
| 421 } | 419 } |
| 422 | 420 |
| 423 void ScreenWin::AddObserver(display::DisplayObserver* observer) { | 421 void ScreenWin::AddObserver(DisplayObserver* observer) { |
| 424 change_notifier_.AddObserver(observer); | 422 change_notifier_.AddObserver(observer); |
| 425 } | 423 } |
| 426 | 424 |
| 427 void ScreenWin::RemoveObserver(display::DisplayObserver* observer) { | 425 void ScreenWin::RemoveObserver(DisplayObserver* observer) { |
| 428 change_notifier_.RemoveObserver(observer); | 426 change_notifier_.RemoveObserver(observer); |
| 429 } | 427 } |
| 430 | 428 |
| 431 gfx::Rect ScreenWin::ScreenToDIPRectInWindow( | 429 gfx::Rect ScreenWin::ScreenToDIPRectInWindow( |
| 432 gfx::NativeView view, const gfx::Rect& screen_rect) const { | 430 gfx::NativeView view, const gfx::Rect& screen_rect) const { |
| 433 HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr; | 431 HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr; |
| 434 return ScreenToDIPRect(hwnd, screen_rect); | 432 return ScreenToDIPRect(hwnd, screen_rect); |
| 435 } | 433 } |
| 436 | 434 |
| 437 gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeView view, | 435 gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeView view, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 return ::GetSystemMetrics(metric); | 479 return ::GetSystemMetrics(metric); |
| 482 } | 480 } |
| 483 | 481 |
| 484 void ScreenWin::OnWndProc(HWND hwnd, | 482 void ScreenWin::OnWndProc(HWND hwnd, |
| 485 UINT message, | 483 UINT message, |
| 486 WPARAM wparam, | 484 WPARAM wparam, |
| 487 LPARAM lparam) { | 485 LPARAM lparam) { |
| 488 if (message != WM_DISPLAYCHANGE) | 486 if (message != WM_DISPLAYCHANGE) |
| 489 return; | 487 return; |
| 490 | 488 |
| 491 std::vector<display::Display> old_displays = std::move(displays_); | 489 std::vector<Display> old_displays = std::move(displays_); |
| 492 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); | 490 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); |
| 493 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); | 491 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
| 494 } | 492 } |
| 495 | 493 |
| 496 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd) | 494 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestHWND(HWND hwnd) |
| 497 const { | 495 const { |
| 498 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd, | 496 return GetScreenWinDisplay(MonitorInfoFromWindow(hwnd, |
| 499 MONITOR_DEFAULTTONEAREST)); | 497 MONITOR_DEFAULTTONEAREST)); |
| 500 } | 498 } |
| 501 | 499 |
| 502 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenRect( | 500 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenRect( |
| 503 const gfx::Rect& screen_rect) const { | 501 const gfx::Rect& screen_rect) const { |
| 504 return GetScreenWinDisplay(MonitorInfoFromScreenRect(screen_rect)); | 502 return GetScreenWinDisplay(MonitorInfoFromScreenRect(screen_rect)); |
| 505 } | 503 } |
| 506 | 504 |
| 507 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenPoint( | 505 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestScreenPoint( |
| 508 const gfx::Point& screen_point) const { | 506 const gfx::Point& screen_point) const { |
| 509 return GetScreenWinDisplay(MonitorInfoFromScreenPoint(screen_point)); | 507 return GetScreenWinDisplay(MonitorInfoFromScreenPoint(screen_point)); |
| 510 } | 508 } |
| 511 | 509 |
| 512 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPPoint( | 510 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPPoint( |
| 513 const gfx::Point& dip_point) const { | 511 const gfx::Point& dip_point) const { |
| 514 ScreenWinDisplay primary_screen_win_display; | 512 ScreenWinDisplay primary_screen_win_display; |
| 515 for (const auto& screen_win_display : screen_win_displays_) { | 513 for (const auto& screen_win_display : screen_win_displays_) { |
| 516 display::Display display = screen_win_display.display(); | 514 Display display = screen_win_display.display(); |
| 517 const gfx::Rect dip_bounds = display.bounds(); | 515 const gfx::Rect dip_bounds = display.bounds(); |
| 518 if (dip_bounds.Contains(dip_point)) | 516 if (dip_bounds.Contains(dip_point)) |
| 519 return screen_win_display; | 517 return screen_win_display; |
| 520 else if (dip_bounds.origin().IsOrigin()) | 518 else if (dip_bounds.origin().IsOrigin()) |
| 521 primary_screen_win_display = screen_win_display; | 519 primary_screen_win_display = screen_win_display; |
| 522 } | 520 } |
| 523 return primary_screen_win_display; | 521 return primary_screen_win_display; |
| 524 } | 522 } |
| 525 | 523 |
| 526 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPRect( | 524 ScreenWinDisplay ScreenWin::GetScreenWinDisplayNearestDIPRect( |
| 527 const gfx::Rect& dip_rect) const { | 525 const gfx::Rect& dip_rect) const { |
| 528 ScreenWinDisplay closest_screen_win_display; | 526 ScreenWinDisplay closest_screen_win_display; |
| 529 int64_t closest_distance_squared = INT64_MAX; | 527 int64_t closest_distance_squared = INT64_MAX; |
| 530 for (const auto& screen_win_display : screen_win_displays_) { | 528 for (const auto& screen_win_display : screen_win_displays_) { |
| 531 display::Display display = screen_win_display.display(); | 529 Display display = screen_win_display.display(); |
| 532 gfx::Rect dip_bounds = display.bounds(); | 530 gfx::Rect dip_bounds = display.bounds(); |
| 533 if (dip_rect.Intersects(dip_bounds)) | 531 if (dip_rect.Intersects(dip_bounds)) |
| 534 return screen_win_display; | 532 return screen_win_display; |
| 535 int64_t distance_squared = SquaredDistanceBetweenRects(dip_rect, | 533 int64_t distance_squared = SquaredDistanceBetweenRects(dip_rect, |
| 536 dip_bounds); | 534 dip_bounds); |
| 537 if (distance_squared < closest_distance_squared) { | 535 if (distance_squared < closest_distance_squared) { |
| 538 closest_distance_squared = distance_squared; | 536 closest_distance_squared = distance_squared; |
| 539 closest_screen_win_display = screen_win_display; | 537 closest_screen_win_display = screen_win_display; |
| 540 } | 538 } |
| 541 } | 539 } |
| 542 return closest_screen_win_display; | 540 return closest_screen_win_display; |
| 543 } | 541 } |
| 544 | 542 |
| 545 ScreenWinDisplay ScreenWin::GetPrimaryScreenWinDisplay() const { | 543 ScreenWinDisplay ScreenWin::GetPrimaryScreenWinDisplay() const { |
| 546 MONITORINFOEX monitor_info = MonitorInfoFromWindow(nullptr, | 544 MONITORINFOEX monitor_info = MonitorInfoFromWindow(nullptr, |
| 547 MONITOR_DEFAULTTOPRIMARY); | 545 MONITOR_DEFAULTTOPRIMARY); |
| 548 ScreenWinDisplay screen_win_display = GetScreenWinDisplay(monitor_info); | 546 ScreenWinDisplay screen_win_display = GetScreenWinDisplay(monitor_info); |
| 549 display::Display display = screen_win_display.display(); | 547 Display display = screen_win_display.display(); |
| 550 // The Windows primary monitor is defined to have an origin of (0, 0). | 548 // The Windows primary monitor is defined to have an origin of (0, 0). |
| 551 DCHECK_EQ(0, display.bounds().origin().x()); | 549 DCHECK_EQ(0, display.bounds().origin().x()); |
| 552 DCHECK_EQ(0, display.bounds().origin().y()); | 550 DCHECK_EQ(0, display.bounds().origin().y()); |
| 553 return screen_win_display; | 551 return screen_win_display; |
| 554 } | 552 } |
| 555 | 553 |
| 556 ScreenWinDisplay ScreenWin::GetScreenWinDisplay( | 554 ScreenWinDisplay ScreenWin::GetScreenWinDisplay( |
| 557 const MONITORINFOEX& monitor_info) const { | 555 const MONITORINFOEX& monitor_info) const { |
| 558 int64_t id = DisplayInfo::DeviceIdFromDeviceName(monitor_info.szDevice); | 556 int64_t id = DisplayInfo::DeviceIdFromDeviceName(monitor_info.szDevice); |
| 559 for (const auto& screen_win_display : screen_win_displays_) { | 557 for (const auto& screen_win_display : screen_win_displays_) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 589 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), | 587 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), |
| 590 reported_scale) == unique_scale_factors.end()) { | 588 reported_scale) == unique_scale_factors.end()) { |
| 591 unique_scale_factors.push_back(reported_scale); | 589 unique_scale_factors.push_back(reported_scale); |
| 592 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | 590 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); |
| 593 } | 591 } |
| 594 } | 592 } |
| 595 } | 593 } |
| 596 | 594 |
| 597 } // namespace win | 595 } // namespace win |
| 598 } // namespace display | 596 } // namespace display |
| OLD | NEW |