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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
// Copyright 2018 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 "components/exo/wm_helper_chromeos.h"
#include "components/exo/wm_helper.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/memory/singleton.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/client/focus_client.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/display/manager/display_configurator.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/types/display_snapshot.h"
#include "ui/wm/core/capture_controller.h"
#include "ui/wm/public/activation_client.h"
namespace exo {
namespace {
aura::Window* GetPrimaryRoot() {
return ash::Shell::Get()->GetPrimaryRootWindow();
}
// A property key to store whether IME should be blocked for the surface.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kImeBlockedKey, false)
} // namespace
////////////////////////////////////////////////////////////////////////////////
// WMHelperChromeOS, public:
WMHelperChromeOS::WMHelperChromeOS() : vsync_timing_manager_(this) {}
WMHelperChromeOS::~WMHelperChromeOS() {}
WMHelperChromeOS* WMHelperChromeOS::GetInstance() {
return static_cast<WMHelperChromeOS*>(WMHelper::GetInstance());
}
void WMHelperChromeOS::AddTabletModeObserver(
ash::TabletModeObserver* observer) {
ash::Shell::Get()->tablet_mode_controller()->AddObserver(observer);
}
void WMHelperChromeOS::RemoveTabletModeObserver(
ash::TabletModeObserver* observer) {
ash::Shell::Get()->tablet_mode_controller()->RemoveObserver(observer);
}
void WMHelperChromeOS::AddDisplayConfigurationObserver(
ash::WindowTreeHostManager::Observer* observer) {
ash::Shell::Get()->window_tree_host_manager()->AddObserver(observer);
}
void WMHelperChromeOS::RemoveDisplayConfigurationObserver(
ash::WindowTreeHostManager::Observer* observer) {
ash::Shell::Get()->window_tree_host_manager()->RemoveObserver(observer);
}
void WMHelperChromeOS::AddActivationObserver(
wm::ActivationChangeObserver* observer) {
ash::Shell::Get()->activation_client()->AddObserver(observer);
}
void WMHelperChromeOS::RemoveActivationObserver(
wm::ActivationChangeObserver* observer) {
ash::Shell::Get()->activation_client()->RemoveObserver(observer);
}
void WMHelperChromeOS::AddFocusObserver(
aura::client::FocusChangeObserver* observer) {
aura::client::GetFocusClient(GetPrimaryRoot())->AddObserver(observer);
}
void WMHelperChromeOS::RemoveFocusObserver(
aura::client::FocusChangeObserver* observer) {
aura::client::GetFocusClient(GetPrimaryRoot())->RemoveObserver(observer);
}
void WMHelperChromeOS::AddDragDropObserver(DragDropObserver* observer) {
drag_drop_observers_.AddObserver(observer);
}
void WMHelperChromeOS::RemoveDragDropObserver(DragDropObserver* observer) {
drag_drop_observers_.RemoveObserver(observer);
}
void WMHelperChromeOS::SetDragDropDelegate(aura::Window* window) {
aura::client::SetDragDropDelegate(window, this);
}
void WMHelperChromeOS::ResetDragDropDelegate(aura::Window* window) {
aura::client::SetDragDropDelegate(window, nullptr);
}
VSyncTimingManager& WMHelperChromeOS::GetVSyncTimingManager() {
return vsync_timing_manager_;
}
void WMHelperChromeOS::OnDragEntered(const ui::DropTargetEvent& event) {
for (DragDropObserver& observer : drag_drop_observers_)
observer.OnDragEntered(event);
}
int WMHelperChromeOS::OnDragUpdated(const ui::DropTargetEvent& event) {
int valid_operation = ui::DragDropTypes::DRAG_NONE;
for (DragDropObserver& observer : drag_drop_observers_)
valid_operation = valid_operation | observer.OnDragUpdated(event);
return valid_operation;
}
void WMHelperChromeOS::OnDragExited() {
for (DragDropObserver& observer : drag_drop_observers_)
observer.OnDragExited();
}
int WMHelperChromeOS::OnPerformDrop(const ui::DropTargetEvent& event,
std::unique_ptr<ui::OSExchangeData> data) {
int valid_operation = ui::DragDropTypes::DRAG_NONE;
for (DragDropObserver& observer : drag_drop_observers_)
valid_operation = valid_operation | observer.OnPerformDrop(event);
return valid_operation;
}
void WMHelperChromeOS::AddVSyncParameterObserver(
mojo::PendingRemote<viz::mojom::VSyncParameterObserver> observer) {
GetPrimaryRoot()->layer()->GetCompositor()->AddVSyncParameterObserver(
std::move(observer));
}
const display::ManagedDisplayInfo& WMHelperChromeOS::GetDisplayInfo(
int64_t display_id) const {
return ash::Shell::Get()->display_manager()->GetDisplayInfo(display_id);
}
const std::vector<uint8_t>& WMHelperChromeOS::GetDisplayIdentificationData(
int64_t display_id) const {
const auto& displays =
ash::Shell::Get()->display_configurator()->cached_displays();
for (display::DisplaySnapshot* display : displays)
if (display->display_id() == display_id)
return display->edid();
static std::vector<uint8_t> no_data;
return no_data;
}
bool WMHelperChromeOS::GetActiveModeForDisplayId(
int64_t display_id,
display::ManagedDisplayMode* mode) const {
return ash::Shell::Get()->display_manager()->GetActiveModeForDisplayId(
display_id, mode);
}
aura::Window* WMHelperChromeOS::GetPrimaryDisplayContainer(int container_id) {
return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
container_id);
}
aura::Window* WMHelperChromeOS::GetActiveWindow() const {
return ash::Shell::Get()->activation_client()->GetActiveWindow();
}
aura::Window* WMHelperChromeOS::GetFocusedWindow() const {
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow());
return focus_client->GetFocusedWindow();
}
aura::Window* WMHelperChromeOS::GetRootWindowForNewWindows() const {
return ash::Shell::GetRootWindowForNewWindows();
}
aura::client::CursorClient* WMHelperChromeOS::GetCursorClient() {
return aura::client::GetCursorClient(ash::Shell::GetPrimaryRootWindow());
}
void WMHelperChromeOS::AddPreTargetHandler(ui::EventHandler* handler) {
ash::Shell::Get()->AddPreTargetHandler(handler);
}
void WMHelperChromeOS::PrependPreTargetHandler(ui::EventHandler* handler) {
ash::Shell::Get()->AddPreTargetHandler(
handler, ui::EventTarget::Priority::kAccessibility);
}
void WMHelperChromeOS::RemovePreTargetHandler(ui::EventHandler* handler) {
ash::Shell::Get()->RemovePreTargetHandler(handler);
}
void WMHelperChromeOS::AddPostTargetHandler(ui::EventHandler* handler) {
ash::Shell::Get()->AddPostTargetHandler(handler);
}
void WMHelperChromeOS::RemovePostTargetHandler(ui::EventHandler* handler) {
ash::Shell::Get()->RemovePostTargetHandler(handler);
}
bool WMHelperChromeOS::InTabletMode() const {
return ash::Shell::Get()->tablet_mode_controller()->InTabletMode();
}
double WMHelperChromeOS::GetDefaultDeviceScaleFactor() const {
if (!display::Display::HasInternalDisplay())
return 1.0;
if (display::Display::HasForceDeviceScaleFactor())
return display::Display::GetForcedDeviceScaleFactor();
display::DisplayManager* display_manager =
ash::Shell::Get()->display_manager();
const display::ManagedDisplayInfo& display_info =
display_manager->GetDisplayInfo(display::Display::InternalDisplayId());
DCHECK(display_info.display_modes().size());
return display_info.display_modes()[0].device_scale_factor();
}
void WMHelperChromeOS::SetImeBlocked(aura::Window* window, bool ime_blocked) {
DCHECK_EQ(window, window->GetToplevelWindow());
window->SetProperty(kImeBlockedKey, ime_blocked);
}
bool WMHelperChromeOS::IsImeBlocked(aura::Window* window) const {
return window && window->GetToplevelWindow()->GetProperty(kImeBlockedKey);
}
WMHelper::LifetimeManager* WMHelperChromeOS::GetLifetimeManager() {
return &lifetime_manager_;
}
aura::client::CaptureClient* WMHelperChromeOS::GetCaptureClient() {
return wm::CaptureController::Get();
}
} // namespace exo
|