Chromium Code Reviews| Index: ui/views/mus/window_manager_connection.cc |
| diff --git a/ui/views/mus/window_manager_connection.cc b/ui/views/mus/window_manager_connection.cc |
| index 8c4cf85d690d545d2fa9dd9e3da5723597200e45..e435d9451f765d30f2ea5491c0c64554b20f5f91 100644 |
| --- a/ui/views/mus/window_manager_connection.cc |
| +++ b/ui/views/mus/window_manager_connection.cc |
| @@ -4,6 +4,7 @@ |
| #include "ui/views/mus/window_manager_connection.h" |
| +#include <algorithm> |
| #include <set> |
| #include <utility> |
| @@ -39,6 +40,34 @@ using WindowManagerConnectionPtr = |
| base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = |
| LAZY_INSTANCE_INITIALIZER; |
| +ui::Window* GetWindowFrom(const std::vector<display::Display>& displays, |
| + const std::vector<ui::Window*>& windows, |
| + const gfx::Point& screen_point) { |
| + for (ui::Window* window : windows) { |
| + const int64_t window_display_id = window->GetRoot()->display_id(); |
|
sky
2016/10/06 21:23:42
Each window has a display id, so you should be abl
|
| + for (display::Display display : displays) { |
|
sky
2016/10/06 21:23:42
As you're going to be doing this in a loop every t
|
| + if (display.id() != window_display_id) |
| + continue; |
| + |
| + gfx::Point display_origin = display.bounds().origin(); |
| + gfx::Rect bounds_in_screen = window->GetBoundsInRoot(); |
| + bounds_in_screen.Offset(display_origin.x(), display_origin.y()); |
| + |
| + if (bounds_in_screen.Contains(screen_point)) { |
| + if (!window->children().empty()) { |
| + ui::Window* child = |
| + GetWindowFrom(displays, window->children(), screen_point); |
| + if (child) |
| + return child; |
| + } |
| + |
| + return window; |
| + } |
| + } |
| + } |
| + return nullptr; |
| +} |
| + |
| } // namespace |
| WindowManagerConnection::~WindowManagerConnection() { |
| @@ -167,6 +196,17 @@ gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
| return client_->GetCursorScreenPoint(); |
| } |
| +ui::Window* WindowManagerConnection::GetWindowAtScreenPoint( |
|
sky
2016/10/06 21:23:42
Please add test coverage of this.
|
| + const gfx::Point& point) { |
| + std::vector<display::Display> displays = |
| + display::Screen::GetScreen()->GetAllDisplays(); |
| + |
| + const std::set<ui::Window*>& roots = GetRoots(); |
| + std::vector<ui::Window*> windows; |
| + std::copy(roots.begin(), roots.end(), std::back_inserter(windows)); |
| + return GetWindowFrom(displays, windows, point); |
| +} |
| + |
| std::unique_ptr<OSExchangeData::Provider> |
| WindowManagerConnection::BuildProvider() { |
| return base::MakeUnique<OSExchangeDataProviderMus>(); |