| 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..4a5914e80f80a45248b830f76506f21f5fc842c8 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,37 @@ using WindowManagerConnectionPtr =
|
| base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr =
|
| LAZY_INSTANCE_INITIALIZER;
|
|
|
| +// Recursively finds the deepest visible window from |windows| that contains
|
| +// |screen_point|, when offsetting by the display origins from
|
| +// |display_origins|.
|
| +ui::Window* GetWindowFrom(const std::map<int64_t, gfx::Point>& display_origins,
|
| + const std::vector<ui::Window*>& windows,
|
| + const gfx::Point& screen_point) {
|
| + for (ui::Window* window : windows) {
|
| + if (!window->visible())
|
| + continue;
|
| +
|
| + auto it = display_origins.find(window->display_id());
|
| + if (it == display_origins.end())
|
| + continue;
|
| +
|
| + gfx::Rect bounds_in_screen = window->GetBoundsInRoot();
|
| + bounds_in_screen.Offset(it->second.x(), it->second.y());
|
| +
|
| + if (bounds_in_screen.Contains(screen_point)) {
|
| + if (!window->children().empty()) {
|
| + ui::Window* child =
|
| + GetWindowFrom(display_origins, window->children(), screen_point);
|
| + if (child)
|
| + return child;
|
| + }
|
| +
|
| + return window;
|
| + }
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| } // namespace
|
|
|
| WindowManagerConnection::~WindowManagerConnection() {
|
| @@ -167,6 +199,18 @@ gfx::Point WindowManagerConnection::GetCursorScreenPoint() {
|
| return client_->GetCursorScreenPoint();
|
| }
|
|
|
| +ui::Window* WindowManagerConnection::GetWindowAtScreenPoint(
|
| + const gfx::Point& point) {
|
| + std::map<int64_t, gfx::Point> display_origins;
|
| + for (display::Display& d : display::Screen::GetScreen()->GetAllDisplays())
|
| + display_origins[d.id()] = d.bounds().origin();
|
| +
|
| + const std::set<ui::Window*>& roots = GetRoots();
|
| + std::vector<ui::Window*> windows;
|
| + std::copy(roots.begin(), roots.end(), std::back_inserter(windows));
|
| + return GetWindowFrom(display_origins, windows, point);
|
| +}
|
| +
|
| std::unique_ptr<OSExchangeData::Provider>
|
| WindowManagerConnection::BuildProvider() {
|
| return base::MakeUnique<OSExchangeDataProviderMus>();
|
|
|