blob: 9acc365e582a961750f314467fa4e52af85e8693 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
#include <stddef.h>
#include <vector>
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
namespace views {
X11TopmostWindowFinder::X11TopmostWindowFinder() = default;
X11TopmostWindowFinder::~X11TopmostWindowFinder() = default;
aura::Window* X11TopmostWindowFinder::FindLocalProcessWindowAt(
const gfx::Point& screen_loc_in_pixels,
const std::set<aura::Window*>& ignore) {
screen_loc_in_pixels_ = screen_loc_in_pixels;
ignore_ = ignore;
std::vector<aura::Window*> local_process_windows =
DesktopWindowTreeHostLinux::GetAllOpenWindows();
if (std::none_of(local_process_windows.cbegin(), local_process_windows.cend(),
[this](auto* window) {
return ShouldStopIteratingAtLocalProcessWindow(window);
}))
return nullptr;
ui::EnumerateTopLevelWindows(this);
return DesktopWindowTreeHostLinux::GetContentWindowForWidget(
static_cast<gfx::AcceleratedWidget>(toplevel_));
}
XID X11TopmostWindowFinder::FindWindowAt(
const gfx::Point& screen_loc_in_pixels) {
screen_loc_in_pixels_ = screen_loc_in_pixels;
ui::EnumerateTopLevelWindows(this);
return toplevel_;
}
bool X11TopmostWindowFinder::ShouldStopIterating(XID xid) {
if (!ui::IsWindowVisible(xid))
return false;
auto* window = DesktopWindowTreeHostLinux::GetContentWindowForWidget(
static_cast<gfx::AcceleratedWidget>(xid));
if (window) {
if (ShouldStopIteratingAtLocalProcessWindow(window)) {
toplevel_ = xid;
return true;
}
return false;
}
if (ui::WindowContainsPoint(xid, screen_loc_in_pixels_)) {
toplevel_ = xid;
return true;
}
return false;
}
bool X11TopmostWindowFinder::ShouldStopIteratingAtLocalProcessWindow(
aura::Window* window) {
if (ignore_.find(window) != ignore_.end())
return false;
// Currently |window|->IsVisible() always returns true.
// TODO(pkotwicz): Fix this. crbug.com/353038
if (!window->IsVisible())
return false;
auto* host = DesktopWindowTreeHostLinux::GetHostForWidget(
window->GetHost()->GetAcceleratedWidget());
if (!static_cast<DesktopWindowTreeHostX11*>(host)
->GetXRootWindowOuterBounds()
.Contains(screen_loc_in_pixels_))
return false;
aura::client::ScreenPositionClient* screen_position_client =
aura::client::GetScreenPositionClient(window->GetRootWindow());
gfx::Point window_loc(screen_loc_in_pixels_);
screen_position_client->ConvertPointFromScreen(window, &window_loc);
return host->ContainsPointInXRegion(window_loc);
}
} // namespace views
|