OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_LIB_WINDOW_TREE_CLIENT_IMPL_H_ | 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_WINDOW_TREE_CLIENT_H_ |
6 #define COMPONENTS_MUS_PUBLIC_CPP_LIB_WINDOW_TREE_CLIENT_IMPL_H_ | 6 #define COMPONENTS_MUS_PUBLIC_CPP_WINDOW_TREE_CLIENT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/atomicops.h" | 15 #include "base/atomicops.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
19 #include "components/mus/common/types.h" | 19 #include "components/mus/common/types.h" |
20 #include "components/mus/public/cpp/window.h" | 20 #include "components/mus/public/cpp/window.h" |
21 #include "components/mus/public/cpp/window_manager_delegate.h" | 21 #include "components/mus/public/cpp/window_manager_delegate.h" |
22 #include "components/mus/public/cpp/window_tree_connection.h" | |
23 #include "components/mus/public/interfaces/window_tree.mojom.h" | 22 #include "components/mus/public/interfaces/window_tree.mojom.h" |
24 #include "mojo/public/cpp/bindings/associated_binding.h" | 23 #include "mojo/public/cpp/bindings/associated_binding.h" |
25 #include "mojo/public/cpp/bindings/strong_binding.h" | 24 #include "mojo/public/cpp/bindings/strong_binding.h" |
26 | 25 |
27 namespace gfx { | 26 namespace gfx { |
28 class Insets; | 27 class Insets; |
29 class Size; | 28 class Size; |
30 } | 29 } |
31 | 30 |
| 31 namespace shell { |
| 32 class Connector; |
| 33 } |
| 34 |
32 namespace mus { | 35 namespace mus { |
33 class InFlightChange; | 36 class InFlightChange; |
34 class WindowTreeClientImplPrivate; | 37 class WindowTreeClientDelegate; |
35 class WindowTreeConnection; | 38 class WindowTreeClientPrivate; |
36 class WindowTreeDelegate; | 39 class WindowTreeClientObserver; |
37 | |
38 enum class ChangeType; | 40 enum class ChangeType; |
39 | 41 |
40 // Manages the connection with the Window Server service. | 42 // Manages the connection with the Window Server service. |
41 class WindowTreeClientImpl : public WindowTreeConnection, | 43 class WindowTreeClient : public mojom::WindowTreeClient, |
42 public mojom::WindowTreeClient, | 44 public mojom::WindowManager, |
43 public mojom::WindowManager, | 45 public WindowManagerClient { |
44 public WindowManagerClient { | |
45 public: | 46 public: |
46 WindowTreeClientImpl(WindowTreeDelegate* delegate, | 47 WindowTreeClient(WindowTreeClientDelegate* delegate, |
47 WindowManagerDelegate* window_manager_delegate, | 48 WindowManagerDelegate* window_manager_delegate, |
48 mojo::InterfaceRequest<mojom::WindowTreeClient> request); | 49 mojom::WindowTreeClientRequest request); |
49 ~WindowTreeClientImpl() override; | 50 ~WindowTreeClient() override; |
50 | 51 |
51 // Establishes the connection by way of the WindowTreeFactory. | 52 // Establishes the connection by way of the WindowTreeFactory. |
52 void ConnectViaWindowTreeFactory(shell::Connector* connector); | 53 void ConnectViaWindowTreeFactory(shell::Connector* connector); |
53 | 54 |
54 // Wait for OnEmbed(), returning when done. | 55 // Wait for OnEmbed(), returning when done. |
55 void WaitForEmbed(); | 56 void WaitForEmbed(); |
56 | 57 |
57 bool connected() const { return tree_ != nullptr; } | 58 bool connected() const { return tree_ != nullptr; } |
58 ClientSpecificId client_id() const { return client_id_; } | 59 ClientSpecificId client_id() const { return client_id_; } |
59 | 60 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 mojom::SurfaceType type, | 113 mojom::SurfaceType type, |
113 mojo::InterfaceRequest<mojom::Surface> surface, | 114 mojo::InterfaceRequest<mojom::Surface> surface, |
114 mojom::SurfaceClientPtr client); | 115 mojom::SurfaceClientPtr client); |
115 | 116 |
116 // Sets the input capture to |window| without notifying the server. | 117 // Sets the input capture to |window| without notifying the server. |
117 void LocalSetCapture(Window* window); | 118 void LocalSetCapture(Window* window); |
118 // Sets focus to |window| without notifying the server. | 119 // Sets focus to |window| without notifying the server. |
119 void LocalSetFocus(Window* window); | 120 void LocalSetFocus(Window* window); |
120 | 121 |
121 // Start/stop tracking windows. While tracked, they can be retrieved via | 122 // Start/stop tracking windows. While tracked, they can be retrieved via |
122 // WindowTreeConnection::GetWindowById. | 123 // WindowTreeClient::GetWindowById. |
123 void AddWindow(Window* window); | 124 void AddWindow(Window* window); |
124 | 125 |
125 bool IsRoot(Window* window) const { return roots_.count(window) > 0; } | 126 bool IsRoot(Window* window) const { return roots_.count(window) > 0; } |
126 | 127 |
127 void OnWindowDestroying(Window* window); | 128 void OnWindowDestroying(Window* window); |
128 | 129 |
129 // Called after the window's observers have been notified of destruction (as | 130 // Called after the window's observers have been notified of destruction (as |
130 // the last step of ~Window). | 131 // the last step of ~Window). |
131 void OnWindowDestroyed(Window* window); | 132 void OnWindowDestroyed(Window* window); |
132 | 133 |
133 Window* GetWindowByServerId(Id id); | 134 Window* GetWindowByServerId(Id id); |
134 | 135 |
135 // WindowTreeConnection: | 136 // Sets whether this is deleted when there are no roots. The default is to |
136 Window* GetCaptureWindow() override; | 137 // delete when there are no roots. |
| 138 void SetDeleteOnNoRoots(bool value); |
| 139 |
| 140 // Returns the root of this connection. |
| 141 const std::set<Window*>& GetRoots(); |
| 142 |
| 143 // Returns the Window with input capture; null if no window has requested |
| 144 // input capture, or if another app has capture. |
| 145 Window* GetCaptureWindow(); |
| 146 |
| 147 // Returns the focused window; null if focus is not yet known or another app |
| 148 // is focused. |
| 149 Window* GetFocusedWindow(); |
| 150 |
| 151 // Sets focus to null. This does nothing if focus is currently null. |
| 152 void ClearFocus(); |
| 153 |
| 154 // Returns the current location of the mouse on screen. Note: this method may |
| 155 // race the asynchronous initialization; but in that case we return (0, 0). |
| 156 gfx::Point GetCursorScreenPoint(); |
| 157 |
| 158 // See description in window_tree.mojom. When an existing event observer is |
| 159 // updated or cleared then any future events from the server for that observer |
| 160 // will be ignored. |
| 161 void SetEventObserver(mojom::EventMatcherPtr matcher); |
| 162 |
| 163 // Creates and returns a new Window (which is owned by the window server). |
| 164 // Windows are initially hidden, use SetVisible(true) to show. |
| 165 Window* NewWindow() { return NewWindow(nullptr); } |
| 166 Window* NewWindow( |
| 167 const std::map<std::string, std::vector<uint8_t>>* properties); |
| 168 Window* NewTopLevelWindow( |
| 169 const std::map<std::string, std::vector<uint8_t>>* properties); |
| 170 |
| 171 void AddObserver(WindowTreeClientObserver* observer); |
| 172 void RemoveObserver(WindowTreeClientObserver* observer); |
137 | 173 |
138 private: | 174 private: |
139 friend class WindowTreeClientImplPrivate; | 175 friend class WindowTreeClientPrivate; |
140 | 176 |
141 enum class NewWindowType { | 177 enum class NewWindowType { |
142 CHILD, | 178 CHILD, |
143 TOP_LEVEL, | 179 TOP_LEVEL, |
144 }; | 180 }; |
145 | 181 |
146 using IdToWindowMap = std::map<Id, Window*>; | 182 using IdToWindowMap = std::map<Id, Window*>; |
147 | 183 |
148 // TODO(sky): this assumes change_ids never wrap, which is a bad assumption. | 184 // TODO(sky): this assumes change_ids never wrap, which is a bad assumption. |
149 using InFlightMap = std::map<uint32_t, std::unique_ptr<InFlightChange>>; | 185 using InFlightMap = std::map<uint32_t, std::unique_ptr<InFlightChange>>; |
(...skipping 15 matching lines...) Expand all Loading... |
165 | 201 |
166 // OnEmbed() calls into this. Exposed as a separate function for testing. | 202 // OnEmbed() calls into this. Exposed as a separate function for testing. |
167 void OnEmbedImpl(mojom::WindowTree* window_tree, | 203 void OnEmbedImpl(mojom::WindowTree* window_tree, |
168 ClientSpecificId client_id, | 204 ClientSpecificId client_id, |
169 mojom::WindowDataPtr root_data, | 205 mojom::WindowDataPtr root_data, |
170 Id focused_window_id, | 206 Id focused_window_id, |
171 bool drawn); | 207 bool drawn); |
172 | 208 |
173 void OnReceivedCursorLocationMemory(mojo::ScopedSharedBufferHandle handle); | 209 void OnReceivedCursorLocationMemory(mojo::ScopedSharedBufferHandle handle); |
174 | 210 |
175 // Overridden from WindowTreeConnection: | |
176 void SetDeleteOnNoRoots(bool value) override; | |
177 const std::set<Window*>& GetRoots() override; | |
178 Window* GetFocusedWindow() override; | |
179 void ClearFocus() override; | |
180 gfx::Point GetCursorScreenPoint() override; | |
181 void SetEventObserver(mojom::EventMatcherPtr matcher) override; | |
182 Window* NewWindow(const Window::SharedProperties* properties) override; | |
183 Window* NewTopLevelWindow( | |
184 const Window::SharedProperties* properties) override; | |
185 void AddObserver(WindowTreeConnectionObserver* observer) override; | |
186 void RemoveObserver(WindowTreeConnectionObserver* observer) override; | |
187 | |
188 // Overridden from WindowTreeClient: | 211 // Overridden from WindowTreeClient: |
189 void OnEmbed(ClientSpecificId client_id, | 212 void OnEmbed(ClientSpecificId client_id, |
190 mojom::WindowDataPtr root, | 213 mojom::WindowDataPtr root, |
191 mojom::WindowTreePtr tree, | 214 mojom::WindowTreePtr tree, |
192 Id focused_window_id, | 215 Id focused_window_id, |
193 bool drawn) override; | 216 bool drawn) override; |
194 void OnEmbeddedAppDisconnected(Id window_id) override; | 217 void OnEmbeddedAppDisconnected(Id window_id) override; |
195 void OnUnembed(Id window_id) override; | 218 void OnUnembed(Id window_id) override; |
196 void OnLostCapture(Id window_id) override; | 219 void OnLostCapture(Id window_id) override; |
197 void OnTopLevelCreated(uint32_t change_id, | 220 void OnTopLevelCreated(uint32_t change_id, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // id for this client. | 299 // id for this client. |
277 ClientSpecificId client_id_; | 300 ClientSpecificId client_id_; |
278 | 301 |
279 // Id assigned to the next window created. | 302 // Id assigned to the next window created. |
280 ClientSpecificId next_window_id_; | 303 ClientSpecificId next_window_id_; |
281 | 304 |
282 // Id used for the next change id supplied to the server. | 305 // Id used for the next change id supplied to the server. |
283 uint32_t next_change_id_; | 306 uint32_t next_change_id_; |
284 InFlightMap in_flight_map_; | 307 InFlightMap in_flight_map_; |
285 | 308 |
286 WindowTreeDelegate* delegate_; | 309 WindowTreeClientDelegate* delegate_; |
287 | 310 |
288 WindowManagerDelegate* window_manager_delegate_; | 311 WindowManagerDelegate* window_manager_delegate_; |
289 | 312 |
290 std::set<Window*> roots_; | 313 std::set<Window*> roots_; |
291 | 314 |
292 IdToWindowMap windows_; | 315 IdToWindowMap windows_; |
293 std::map<ClientSpecificId, std::set<Window*>> embedded_windows_; | 316 std::map<ClientSpecificId, std::set<Window*>> embedded_windows_; |
294 | 317 |
295 Window* capture_window_; | 318 Window* capture_window_; |
296 | 319 |
297 Window* focused_window_; | 320 Window* focused_window_; |
298 | 321 |
299 mojo::Binding<WindowTreeClient> binding_; | 322 mojo::Binding<mojom::WindowTreeClient> binding_; |
300 mojom::WindowTreePtr tree_ptr_; | 323 mojom::WindowTreePtr tree_ptr_; |
301 // Typically this is the value contained in |tree_ptr_|, but tests may | 324 // Typically this is the value contained in |tree_ptr_|, but tests may |
302 // directly set this. | 325 // directly set this. |
303 mojom::WindowTree* tree_; | 326 mojom::WindowTree* tree_; |
304 | 327 |
305 bool delete_on_no_roots_; | 328 bool delete_on_no_roots_; |
306 | 329 |
307 bool in_destructor_; | 330 bool in_destructor_; |
308 | 331 |
309 // A handle to shared memory that is one 32 bit integer long. The window | 332 // A handle to shared memory that is one 32 bit integer long. The window |
310 // server uses this to let us synchronously read the cursor location. | 333 // server uses this to let us synchronously read the cursor location. |
311 mojo::ScopedSharedBufferHandle cursor_location_handle_; | 334 mojo::ScopedSharedBufferHandle cursor_location_handle_; |
312 | 335 |
313 // The one int in |cursor_location_handle_|. When we read from this | 336 // The one int in |cursor_location_handle_|. When we read from this |
314 // location, we must always read from it atomically. | 337 // location, we must always read from it atomically. |
315 base::subtle::Atomic32* cursor_location_memory_; | 338 base::subtle::Atomic32* cursor_location_memory_; |
316 | 339 |
317 base::ObserverList<WindowTreeConnectionObserver> observers_; | 340 base::ObserverList<WindowTreeClientObserver> observers_; |
318 | 341 |
319 std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManager>> | 342 std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManager>> |
320 window_manager_internal_; | 343 window_manager_internal_; |
321 mojom::WindowManagerClientAssociatedPtr window_manager_internal_client_; | 344 mojom::WindowManagerClientAssociatedPtr window_manager_internal_client_; |
322 | 345 |
323 bool has_event_observer_ = false; | 346 bool has_event_observer_ = false; |
324 | 347 |
325 // Monotonically increasing ID for event observers. | 348 // Monotonically increasing ID for event observers. |
326 uint32_t event_observer_id_ = 0u; | 349 uint32_t event_observer_id_ = 0u; |
327 | 350 |
328 base::WeakPtrFactory<WindowTreeClientImpl> weak_factory_; | 351 base::WeakPtrFactory<WindowTreeClient> weak_factory_; |
329 | 352 |
330 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl); | 353 DISALLOW_COPY_AND_ASSIGN(WindowTreeClient); |
331 }; | 354 }; |
332 | 355 |
333 } // namespace mus | 356 } // namespace mus |
334 | 357 |
335 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_WINDOW_TREE_CLIENT_IMPL_H_ | 358 #endif // COMPONENTS_MUS_PUBLIC_CPP_WINDOW_TREE_CLIENT_H_ |
OLD | NEW |