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
|
// Copyright 2015 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.
#ifndef SERVICES_UI_WS_DISPLAY_H_
#define SERVICES_UI_WS_DISPLAY_H_
#include <stdint.h>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "cc/surfaces/local_surface_id_allocator.h"
#include "services/ui/common/types.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "services/ui/public/interfaces/window_tree_host.mojom.h"
#include "services/ui/ws/focus_controller_delegate.h"
#include "services/ui/ws/focus_controller_observer.h"
#include "services/ui/ws/platform_display.h"
#include "services/ui/ws/platform_display_delegate.h"
#include "services/ui/ws/server_window.h"
#include "services/ui/ws/server_window_observer.h"
#include "services/ui/ws/server_window_tracker.h"
#include "services/ui/ws/user_id_tracker_observer.h"
#include "services/ui/ws/window_manager_window_tree_factory_set_observer.h"
#include "ui/display/display.h"
#include "ui/events/event_sink.h"
namespace display {
struct ViewportMetrics;
}
namespace ui {
namespace ws {
class DisplayBinding;
class DisplayManager;
class FocusController;
class WindowManagerDisplayRoot;
class WindowServer;
class WindowTree;
namespace test {
class DisplayTestApi;
}
// Displays manages the state associated with a single display. Display has a
// single root window whose children are the roots for a per-user
// WindowManager. Display is configured in two distinct ways:
// . with a DisplayBinding. In this mode there is only ever one WindowManager
// for the display, which comes from the client that created the
// Display.
// . without a DisplayBinding. In this mode a WindowManager is automatically
// created per user.
class Display : public PlatformDisplayDelegate,
public mojom::WindowTreeHost,
public FocusControllerObserver,
public FocusControllerDelegate,
public UserIdTrackerObserver,
public WindowManagerWindowTreeFactorySetObserver,
public EventSink {
public:
explicit Display(WindowServer* window_server);
~Display() override;
// Initializes the display root ServerWindow and PlatformDisplay. Adds this to
// DisplayManager as a pending display, until accelerated widget is available.
void Init(const display::ViewportMetrics& metrics,
std::unique_ptr<DisplayBinding> binding);
// Returns the ID for this display. In internal mode this is the
// display::Display ID. In external mode this hasn't been defined yet.
int64_t GetId() const;
// Sets the display::Display corresponding to this ws::Display. This is only
// valid in internal window mode.
void SetDisplay(const display::Display& display);
// PlatformDisplayDelegate:
const display::Display& GetDisplay() override;
DisplayManager* display_manager();
const DisplayManager* display_manager() const;
PlatformDisplay* platform_display() { return platform_display_.get(); }
// Returns the size of the display in physical pixels.
gfx::Size GetSize() const;
WindowServer* window_server() { return window_server_; }
// Returns the root of the Display. The root's children are the roots
// of the corresponding WindowManagers.
ServerWindow* root_window() { return root_.get(); }
const ServerWindow* root_window() const { return root_.get(); }
// Returns the ServerWindow whose id is |id|. This does not do a search over
// all windows, rather just the display and window manager root windows.
//
// In general you shouldn't use this, rather use WindowServer::GetWindow(),
// which calls this as necessary.
ServerWindow* GetRootWithId(const WindowId& id);
WindowManagerDisplayRoot* GetWindowManagerDisplayRootWithRoot(
const ServerWindow* window);
WindowManagerDisplayRoot* GetWindowManagerDisplayRootForUser(
const UserId& user_id) {
return const_cast<WindowManagerDisplayRoot*>(
const_cast<const Display*>(this)->GetWindowManagerDisplayRootForUser(
user_id));
}
const WindowManagerDisplayRoot* GetWindowManagerDisplayRootForUser(
const UserId& user_id) const;
WindowManagerDisplayRoot* GetActiveWindowManagerDisplayRoot() {
return const_cast<WindowManagerDisplayRoot*>(
const_cast<const Display*>(this)->GetActiveWindowManagerDisplayRoot());
}
const WindowManagerDisplayRoot* GetActiveWindowManagerDisplayRoot() const;
size_t num_window_manager_states() const {
return window_manager_display_root_map_.size();
}
// TODO(sky): this should only be called by WindowServer, move to interface
// used by WindowServer.
// See description of WindowServer::SetFocusedWindow() for details on return
// value.
bool SetFocusedWindow(ServerWindow* window);
// NOTE: this returns the focused window only if the focused window is in this
// display. If this returns null focus may be in another display.
ServerWindow* GetFocusedWindow();
void ActivateNextWindow();
void AddActivationParent(ServerWindow* window);
void RemoveActivationParent(ServerWindow* window);
void UpdateTextInputState(ServerWindow* window,
const ui::TextInputState& state);
void SetImeVisibility(ServerWindow* window, bool visible);
// Called just before |tree| is destroyed.
void OnWillDestroyTree(WindowTree* tree);
// Removes |display_root| from internal maps. This called prior to
// |display_root| being destroyed.
void RemoveWindowManagerDisplayRoot(WindowManagerDisplayRoot* display_root);
// Sets the native cursor to |cursor|.
void SetNativeCursor(const ui::CursorData& curosor);
// mojom::WindowTreeHost:
void SetSize(const gfx::Size& size) override;
void SetTitle(const std::string& title) override;
// Updates the size of display root ServerWindow and WM root ServerWindow(s).
void OnViewportMetricsChanged(const display::ViewportMetrics& metrics);
// Returns the root window of the active user.
ServerWindow* GetActiveRootWindow();
private:
friend class test::DisplayTestApi;
using WindowManagerDisplayRootMap =
std::map<UserId, WindowManagerDisplayRoot*>;
class CursorState;
// Inits the necessary state once the display is ready.
void InitWindowManagerDisplayRoots();
// Creates the set of WindowManagerDisplayRoots from the
// WindowManagerWindowTreeFactorySet.
void CreateWindowManagerDisplayRootsFromFactories();
void CreateWindowManagerDisplayRootFromFactory(
WindowManagerWindowTreeFactory* factory);
// Creates the root ServerWindow for this display, where |size| is in physical
// pixels.
void CreateRootWindow(const gfx::Size& size);
// PlatformDisplayDelegate:
ServerWindow* GetRootWindow() override;
EventSink* GetEventSink() override;
void OnAcceleratedWidgetAvailable() override;
void OnNativeCaptureLost() override;
OzonePlatform* GetOzonePlatform() override;
// FocusControllerDelegate:
bool CanHaveActiveChildren(ServerWindow* window) const override;
// FocusControllerObserver:
void OnActivationChanged(ServerWindow* old_active_window,
ServerWindow* new_active_window) override;
void OnFocusChanged(FocusControllerChangeSource change_source,
ServerWindow* old_focused_window,
ServerWindow* new_focused_window) override;
// UserIdTrackerObserver:
void OnUserIdRemoved(const UserId& id) override;
// WindowManagerWindowTreeFactorySetObserver:
void OnWindowManagerWindowTreeFactoryReady(
WindowManagerWindowTreeFactory* factory) override;
// EventSink:
EventDispatchDetails OnEventFromSource(Event* event) override;
std::unique_ptr<DisplayBinding> binding_;
WindowServer* const window_server_;
std::unique_ptr<ServerWindow> root_;
std::unique_ptr<PlatformDisplay> platform_display_;
std::unique_ptr<FocusController> focus_controller_;
// In internal window mode this contains information about the display. In
// external window mode this will be invalid.
display::Display display_;
ServerWindowTracker activation_parents_;
cc::LocalSurfaceIdAllocator allocator_;
WindowManagerDisplayRootMap window_manager_display_root_map_;
DISALLOW_COPY_AND_ASSIGN(Display);
};
} // namespace ws
} // namespace ui
#endif // SERVICES_UI_WS_DISPLAY_H_
|