| 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 16 matching lines...) Expand all Loading... |
| 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 int64_t display_id, | 206 int64_t display_id, |
| 171 Id focused_window_id, | 207 Id focused_window_id, |
| 172 bool drawn); | 208 bool drawn); |
| 173 | 209 |
| 174 void OnReceivedCursorLocationMemory(mojo::ScopedSharedBufferHandle handle); | 210 void OnReceivedCursorLocationMemory(mojo::ScopedSharedBufferHandle handle); |
| 175 | 211 |
| 176 // Overridden from WindowTreeConnection: | |
| 177 void SetDeleteOnNoRoots(bool value) override; | |
| 178 const std::set<Window*>& GetRoots() override; | |
| 179 Window* GetFocusedWindow() override; | |
| 180 void ClearFocus() override; | |
| 181 gfx::Point GetCursorScreenPoint() override; | |
| 182 void SetEventObserver(mojom::EventMatcherPtr matcher) override; | |
| 183 Window* NewWindow(const Window::SharedProperties* properties) override; | |
| 184 Window* NewTopLevelWindow( | |
| 185 const Window::SharedProperties* properties) override; | |
| 186 void AddObserver(WindowTreeConnectionObserver* observer) override; | |
| 187 void RemoveObserver(WindowTreeConnectionObserver* observer) override; | |
| 188 | |
| 189 // Overridden from WindowTreeClient: | 212 // Overridden from WindowTreeClient: |
| 190 void OnEmbed(ClientSpecificId client_id, | 213 void OnEmbed(ClientSpecificId client_id, |
| 191 mojom::WindowDataPtr root, | 214 mojom::WindowDataPtr root, |
| 192 mojom::WindowTreePtr tree, | 215 mojom::WindowTreePtr tree, |
| 193 int64_t display_id, | 216 int64_t display_id, |
| 194 Id focused_window_id, | 217 Id focused_window_id, |
| 195 bool drawn) override; | 218 bool drawn) override; |
| 196 void OnEmbeddedAppDisconnected(Id window_id) override; | 219 void OnEmbeddedAppDisconnected(Id window_id) override; |
| 197 void OnUnembed(Id window_id) override; | 220 void OnUnembed(Id window_id) override; |
| 198 void OnLostCapture(Id window_id) override; | 221 void OnLostCapture(Id window_id) override; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // id for this client. | 302 // id for this client. |
| 280 ClientSpecificId client_id_; | 303 ClientSpecificId client_id_; |
| 281 | 304 |
| 282 // Id assigned to the next window created. | 305 // Id assigned to the next window created. |
| 283 ClientSpecificId next_window_id_; | 306 ClientSpecificId next_window_id_; |
| 284 | 307 |
| 285 // Id used for the next change id supplied to the server. | 308 // Id used for the next change id supplied to the server. |
| 286 uint32_t next_change_id_; | 309 uint32_t next_change_id_; |
| 287 InFlightMap in_flight_map_; | 310 InFlightMap in_flight_map_; |
| 288 | 311 |
| 289 WindowTreeDelegate* delegate_; | 312 WindowTreeClientDelegate* delegate_; |
| 290 | 313 |
| 291 WindowManagerDelegate* window_manager_delegate_; | 314 WindowManagerDelegate* window_manager_delegate_; |
| 292 | 315 |
| 293 std::set<Window*> roots_; | 316 std::set<Window*> roots_; |
| 294 | 317 |
| 295 IdToWindowMap windows_; | 318 IdToWindowMap windows_; |
| 296 std::map<ClientSpecificId, std::set<Window*>> embedded_windows_; | 319 std::map<ClientSpecificId, std::set<Window*>> embedded_windows_; |
| 297 | 320 |
| 298 Window* capture_window_; | 321 Window* capture_window_; |
| 299 | 322 |
| 300 Window* focused_window_; | 323 Window* focused_window_; |
| 301 | 324 |
| 302 mojo::Binding<WindowTreeClient> binding_; | 325 mojo::Binding<mojom::WindowTreeClient> binding_; |
| 303 mojom::WindowTreePtr tree_ptr_; | 326 mojom::WindowTreePtr tree_ptr_; |
| 304 // Typically this is the value contained in |tree_ptr_|, but tests may | 327 // Typically this is the value contained in |tree_ptr_|, but tests may |
| 305 // directly set this. | 328 // directly set this. |
| 306 mojom::WindowTree* tree_; | 329 mojom::WindowTree* tree_; |
| 307 | 330 |
| 308 bool delete_on_no_roots_; | 331 bool delete_on_no_roots_; |
| 309 | 332 |
| 310 bool in_destructor_; | 333 bool in_destructor_; |
| 311 | 334 |
| 312 // A handle to shared memory that is one 32 bit integer long. The window | 335 // A handle to shared memory that is one 32 bit integer long. The window |
| 313 // server uses this to let us synchronously read the cursor location. | 336 // server uses this to let us synchronously read the cursor location. |
| 314 mojo::ScopedSharedBufferHandle cursor_location_handle_; | 337 mojo::ScopedSharedBufferHandle cursor_location_handle_; |
| 315 | 338 |
| 316 // The one int in |cursor_location_handle_|. When we read from this | 339 // The one int in |cursor_location_handle_|. When we read from this |
| 317 // location, we must always read from it atomically. | 340 // location, we must always read from it atomically. |
| 318 base::subtle::Atomic32* cursor_location_memory_; | 341 base::subtle::Atomic32* cursor_location_memory_; |
| 319 | 342 |
| 320 base::ObserverList<WindowTreeConnectionObserver> observers_; | 343 base::ObserverList<WindowTreeClientObserver> observers_; |
| 321 | 344 |
| 322 std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManager>> | 345 std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManager>> |
| 323 window_manager_internal_; | 346 window_manager_internal_; |
| 324 mojom::WindowManagerClientAssociatedPtr window_manager_internal_client_; | 347 mojom::WindowManagerClientAssociatedPtr window_manager_internal_client_; |
| 325 | 348 |
| 326 bool has_event_observer_ = false; | 349 bool has_event_observer_ = false; |
| 327 | 350 |
| 328 // Monotonically increasing ID for event observers. | 351 // Monotonically increasing ID for event observers. |
| 329 uint32_t event_observer_id_ = 0u; | 352 uint32_t event_observer_id_ = 0u; |
| 330 | 353 |
| 331 base::WeakPtrFactory<WindowTreeClientImpl> weak_factory_; | 354 base::WeakPtrFactory<WindowTreeClient> weak_factory_; |
| 332 | 355 |
| 333 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl); | 356 DISALLOW_COPY_AND_ASSIGN(WindowTreeClient); |
| 334 }; | 357 }; |
| 335 | 358 |
| 336 } // namespace mus | 359 } // namespace mus |
| 337 | 360 |
| 338 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_WINDOW_TREE_CLIENT_IMPL_H_ | 361 #endif // COMPONENTS_MUS_PUBLIC_CPP_WINDOW_TREE_CLIENT_H_ |
| OLD | NEW |