| 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 UI_AURA_MUS_WINDOW_TREE_CLIENT_H_ | 5 #ifndef UI_AURA_MUS_WINDOW_TREE_CLIENT_H_ |
| 6 #define UI_AURA_MUS_WINDOW_TREE_CLIENT_H_ | 6 #define UI_AURA_MUS_WINDOW_TREE_CLIENT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/atomicops.h" | 16 #include "base/atomicops.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 21 #include "mojo/public/cpp/bindings/associated_binding.h" | 21 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 22 #include "mojo/public/cpp/bindings/strong_binding.h" | 22 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 23 #include "services/ui/public/interfaces/window_tree.mojom.h" | 23 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 24 #include "ui/aura/aura_export.h" | 24 #include "ui/aura/aura_export.h" |
| 25 #include "ui/aura/client/capture_client_observer.h" | |
| 26 #include "ui/aura/client/focus_change_observer.h" | 25 #include "ui/aura/client/focus_change_observer.h" |
| 27 #include "ui/aura/client/transient_window_client_observer.h" | 26 #include "ui/aura/client/transient_window_client_observer.h" |
| 27 #include "ui/aura/mus/capture_synchronizer_delegate.h" |
| 28 #include "ui/aura/mus/drag_drop_controller_host.h" | 28 #include "ui/aura/mus/drag_drop_controller_host.h" |
| 29 #include "ui/aura/mus/mus_types.h" | 29 #include "ui/aura/mus/mus_types.h" |
| 30 #include "ui/aura/mus/window_manager_delegate.h" | 30 #include "ui/aura/mus/window_manager_delegate.h" |
| 31 #include "ui/aura/mus/window_tree_host_mus_delegate.h" | 31 #include "ui/aura/mus/window_tree_host_mus_delegate.h" |
| 32 | 32 |
| 33 namespace display { | 33 namespace display { |
| 34 class Display; | 34 class Display; |
| 35 } | 35 } |
| 36 | 36 |
| 37 namespace gfx { | 37 namespace gfx { |
| 38 class Insets; | 38 class Insets; |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace service_manager { | 41 namespace service_manager { |
| 42 class Connector; | 42 class Connector; |
| 43 } | 43 } |
| 44 | 44 |
| 45 namespace aura { | 45 namespace aura { |
| 46 class CaptureSynchronizer; |
| 46 class DragDropControllerMus; | 47 class DragDropControllerMus; |
| 47 class InFlightBoundsChange; | 48 class InFlightBoundsChange; |
| 48 class InFlightCaptureChange; | |
| 49 class InFlightChange; | 49 class InFlightChange; |
| 50 class InFlightFocusChange; | 50 class InFlightFocusChange; |
| 51 class InFlightPropertyChange; | 51 class InFlightPropertyChange; |
| 52 class InFlightVisibleChange; | 52 class InFlightVisibleChange; |
| 53 class WindowMus; | 53 class WindowMus; |
| 54 class WindowPortMus; | 54 class WindowPortMus; |
| 55 struct WindowPortInitData; | 55 struct WindowPortInitData; |
| 56 struct WindowPortPropertyData; | 56 struct WindowPortPropertyData; |
| 57 class WindowTreeClientDelegate; | 57 class WindowTreeClientDelegate; |
| 58 class WindowTreeClientPrivate; | 58 class WindowTreeClientPrivate; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 // | 69 // |
| 70 // WindowTreeClient is owned by the creator. Generally when the delegate gets | 70 // WindowTreeClient is owned by the creator. Generally when the delegate gets |
| 71 // one of OnEmbedRootDestroyed() or OnLostConnection() it should delete the | 71 // one of OnEmbedRootDestroyed() or OnLostConnection() it should delete the |
| 72 // WindowTreeClient. | 72 // WindowTreeClient. |
| 73 // | 73 // |
| 74 // When WindowTreeClient is deleted all windows are deleted (and observers | 74 // When WindowTreeClient is deleted all windows are deleted (and observers |
| 75 // notified). | 75 // notified). |
| 76 class AURA_EXPORT WindowTreeClient | 76 class AURA_EXPORT WindowTreeClient |
| 77 : NON_EXPORTED_BASE(public ui::mojom::WindowTreeClient), | 77 : NON_EXPORTED_BASE(public ui::mojom::WindowTreeClient), |
| 78 NON_EXPORTED_BASE(public ui::mojom::WindowManager), | 78 NON_EXPORTED_BASE(public ui::mojom::WindowManager), |
| 79 public CaptureSynchronizerDelegate, |
| 79 public DragDropControllerHost, | 80 public DragDropControllerHost, |
| 80 public WindowManagerClient, | 81 public WindowManagerClient, |
| 81 public WindowTreeHostMusDelegate, | 82 public WindowTreeHostMusDelegate, |
| 82 public client::CaptureClientObserver, | |
| 83 public client::FocusChangeObserver, | 83 public client::FocusChangeObserver, |
| 84 public client::TransientWindowClientObserver { | 84 public client::TransientWindowClientObserver { |
| 85 public: | 85 public: |
| 86 explicit WindowTreeClient( | 86 explicit WindowTreeClient( |
| 87 WindowTreeClientDelegate* delegate, | 87 WindowTreeClientDelegate* delegate, |
| 88 WindowManagerDelegate* window_manager_delegate = nullptr, | 88 WindowManagerDelegate* window_manager_delegate = nullptr, |
| 89 ui::mojom::WindowTreeClientRequest request = nullptr); | 89 ui::mojom::WindowTreeClientRequest request = nullptr); |
| 90 ~WindowTreeClient() override; | 90 ~WindowTreeClient() override; |
| 91 | 91 |
| 92 // Establishes the connection by way of the WindowTreeFactory. | 92 // Establishes the connection by way of the WindowTreeFactory. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 Id window_id, | 131 Id window_id, |
| 132 ui::mojom::CompositorFrameSinkType type, | 132 ui::mojom::CompositorFrameSinkType type, |
| 133 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink, | 133 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink, |
| 134 cc::mojom::MojoCompositorFrameSinkClientPtr client); | 134 cc::mojom::MojoCompositorFrameSinkClientPtr client); |
| 135 | 135 |
| 136 bool IsRoot(WindowMus* window) const { return roots_.count(window) > 0; } | 136 bool IsRoot(WindowMus* window) const { return roots_.count(window) > 0; } |
| 137 | 137 |
| 138 // Returns the root of this connection. | 138 // Returns the root of this connection. |
| 139 std::set<Window*> GetRoots(); | 139 std::set<Window*> GetRoots(); |
| 140 | 140 |
| 141 // Returns the Window with input capture; null if no window has requested | |
| 142 // input capture, or if another app has capture. | |
| 143 Window* GetCaptureWindow(); | |
| 144 | |
| 145 // Returns the focused window; null if focus is not yet known or another app | 141 // Returns the focused window; null if focus is not yet known or another app |
| 146 // is focused. | 142 // is focused. |
| 147 Window* GetFocusedWindow(); | 143 Window* GetFocusedWindow(); |
| 148 | 144 |
| 149 // Returns the current location of the mouse on screen. Note: this method may | 145 // Returns the current location of the mouse on screen. Note: this method may |
| 150 // race the asynchronous initialization; but in that case we return (0, 0). | 146 // race the asynchronous initialization; but in that case we return (0, 0). |
| 151 gfx::Point GetCursorScreenPoint(); | 147 gfx::Point GetCursorScreenPoint(); |
| 152 | 148 |
| 153 // See description in window_tree.mojom. When an existing pointer watcher is | 149 // See description in window_tree.mojom. When an existing pointer watcher is |
| 154 // updated or cleared then any future events from the server for that watcher | 150 // updated or cleared then any future events from the server for that watcher |
| (...skipping 10 matching lines...) Expand all Loading... |
| 165 | 161 |
| 166 // Cancels a in progress window move. (If no window is currently being moved, | 162 // Cancels a in progress window move. (If no window is currently being moved, |
| 167 // does nothing.) | 163 // does nothing.) |
| 168 void CancelWindowMove(Window* window); | 164 void CancelWindowMove(Window* window); |
| 169 | 165 |
| 170 void AddObserver(WindowTreeClientObserver* observer); | 166 void AddObserver(WindowTreeClientObserver* observer); |
| 171 void RemoveObserver(WindowTreeClientObserver* observer); | 167 void RemoveObserver(WindowTreeClientObserver* observer); |
| 172 | 168 |
| 173 private: | 169 private: |
| 174 friend class InFlightBoundsChange; | 170 friend class InFlightBoundsChange; |
| 175 friend class InFlightCaptureChange; | |
| 176 friend class InFlightFocusChange; | 171 friend class InFlightFocusChange; |
| 177 friend class InFlightPropertyChange; | 172 friend class InFlightPropertyChange; |
| 178 friend class InFlightVisibleChange; | 173 friend class InFlightVisibleChange; |
| 179 friend class WindowPortMus; | 174 friend class WindowPortMus; |
| 180 friend class WindowTreeClientPrivate; | 175 friend class WindowTreeClientPrivate; |
| 181 | 176 |
| 182 using IdToWindowMap = std::map<Id, WindowMus*>; | 177 using IdToWindowMap = std::map<Id, WindowMus*>; |
| 183 | 178 |
| 184 // TODO(sky): this assumes change_ids never wrap, which is a bad assumption. | 179 // TODO(sky): this assumes change_ids never wrap, which is a bad assumption. |
| 185 using InFlightMap = std::map<uint32_t, std::unique_ptr<InFlightChange>>; | 180 using InFlightMap = std::map<uint32_t, std::unique_ptr<InFlightChange>>; |
| 186 | 181 |
| 187 void RegisterWindowMus(WindowMus* window); | 182 void RegisterWindowMus(WindowMus* window); |
| 188 | 183 |
| 189 WindowMus* GetWindowByServerId(Id id); | 184 WindowMus* GetWindowByServerId(Id id); |
| 190 | 185 |
| 191 // Returns true if the specified window was created by this client. | 186 // Returns true if the specified window was created by this client. |
| 192 bool WasCreatedByThisClient(const WindowMus* window) const; | 187 bool WasCreatedByThisClient(const WindowMus* window) const; |
| 193 | 188 |
| 194 void SetFocusFromServer(WindowMus* window); | 189 void SetFocusFromServer(WindowMus* window); |
| 195 void SetFocusFromServerImpl(client::FocusClient* focus_client, | 190 void SetFocusFromServerImpl(client::FocusClient* focus_client, |
| 196 WindowMus* window); | 191 WindowMus* window); |
| 197 | 192 |
| 198 void SetCaptureFromServer(WindowMus* window); | |
| 199 | |
| 200 // Returns the oldest InFlightChange that matches |change|. | 193 // Returns the oldest InFlightChange that matches |change|. |
| 201 InFlightChange* GetOldestInFlightChangeMatching(const InFlightChange& change); | 194 InFlightChange* GetOldestInFlightChangeMatching(const InFlightChange& change); |
| 202 | 195 |
| 203 // See InFlightChange for details on how InFlightChanges are used. | 196 // See InFlightChange for details on how InFlightChanges are used. |
| 204 uint32_t ScheduleInFlightChange(std::unique_ptr<InFlightChange> change); | 197 uint32_t ScheduleInFlightChange(std::unique_ptr<InFlightChange> change); |
| 205 | 198 |
| 206 // Returns true if there is an InFlightChange that matches |change|. If there | 199 // Returns true if there is an InFlightChange that matches |change|. If there |
| 207 // is an existing change SetRevertValueFrom() is invoked on it. Returns false | 200 // is an existing change SetRevertValueFrom() is invoked on it. Returns false |
| 208 // if there is no InFlightChange matching |change|. | 201 // if there is no InFlightChange matching |change|. |
| 209 // See InFlightChange for details on how InFlightChanges are used. | 202 // See InFlightChange for details on how InFlightChanges are used. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 233 int64_t display_id, | 226 int64_t display_id, |
| 234 Window* content_window); | 227 Window* content_window); |
| 235 | 228 |
| 236 WindowMus* NewWindowFromWindowData( | 229 WindowMus* NewWindowFromWindowData( |
| 237 WindowMus* parent, | 230 WindowMus* parent, |
| 238 const ui::mojom::WindowDataPtr& window_data); | 231 const ui::mojom::WindowDataPtr& window_data); |
| 239 | 232 |
| 240 // Sets the ui::mojom::WindowTree implementation. | 233 // Sets the ui::mojom::WindowTree implementation. |
| 241 void SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr); | 234 void SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr); |
| 242 | 235 |
| 236 // Called when the connection to the server is established. |
| 237 void WindowTreeConnectionEstablished(ui::mojom::WindowTree* window_tree); |
| 238 |
| 243 // Called when the ui::mojom::WindowTree connection is lost, deletes this. | 239 // Called when the ui::mojom::WindowTree connection is lost, deletes this. |
| 244 void OnConnectionLost(); | 240 void OnConnectionLost(); |
| 245 | 241 |
| 246 // Called when a Window property changes. If |key| is handled internally | 242 // Called when a Window property changes. If |key| is handled internally |
| 247 // (maps to a function on WindowTree) returns true. | 243 // (maps to a function on WindowTree) returns true. |
| 248 bool HandleInternalPropertyChanged(WindowMus* window, const void* key); | 244 bool HandleInternalPropertyChanged(WindowMus* window, const void* key); |
| 249 | 245 |
| 250 // OnEmbed() calls into this. Exposed as a separate function for testing. | 246 // OnEmbed() calls into this. Exposed as a separate function for testing. |
| 251 void OnEmbedImpl(ui::mojom::WindowTree* window_tree, | 247 void OnEmbedImpl(ui::mojom::WindowTree* window_tree, |
| 252 ClientSpecificId client_id, | 248 ClientSpecificId client_id, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 void RemoveActivationParent(Window* window) override; | 419 void RemoveActivationParent(Window* window) override; |
| 424 void ActivateNextWindow() override; | 420 void ActivateNextWindow() override; |
| 425 void SetUnderlaySurfaceOffsetAndExtendedHitArea( | 421 void SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 426 Window* window, | 422 Window* window, |
| 427 const gfx::Vector2d& offset, | 423 const gfx::Vector2d& offset, |
| 428 const gfx::Insets& hit_area) override; | 424 const gfx::Insets& hit_area) override; |
| 429 | 425 |
| 430 // Overriden from client::FocusChangeObserver: | 426 // Overriden from client::FocusChangeObserver: |
| 431 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override; | 427 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override; |
| 432 | 428 |
| 433 // Overriden from client::CaptureClientObserver: | |
| 434 void OnCaptureChanged(Window* lost_capture, Window* gained_capture) override; | |
| 435 | |
| 436 // Overriden from WindowTreeHostMusDelegate: | 429 // Overriden from WindowTreeHostMusDelegate: |
| 437 void SetRootWindowBounds(Window* window, gfx::Rect* bounds) override; | 430 void SetRootWindowBounds(Window* window, gfx::Rect* bounds) override; |
| 438 | 431 |
| 439 // Override from client::TransientWindowClientObserver: | 432 // Override from client::TransientWindowClientObserver: |
| 440 void OnTransientChildWindowAdded(Window* parent, | 433 void OnTransientChildWindowAdded(Window* parent, |
| 441 Window* transient_child) override; | 434 Window* transient_child) override; |
| 442 void OnTransientChildWindowRemoved(Window* parent, | 435 void OnTransientChildWindowRemoved(Window* parent, |
| 443 Window* transient_child) override; | 436 Window* transient_child) override; |
| 444 | 437 |
| 445 // Overriden from DragDropControllerHost: | 438 // Overriden from DragDropControllerHost: |
| 446 uint32_t CreateChangeIdForDrag(WindowMus* window) override; | 439 uint32_t CreateChangeIdForDrag(WindowMus* window) override; |
| 447 | 440 |
| 441 // Overrided from CaptureSynchronizerDelegate: |
| 442 uint32_t CreateChangeIdForCapture(WindowMus* window) override; |
| 443 |
| 448 // The one int in |cursor_location_mapping_|. When we read from this | 444 // The one int in |cursor_location_mapping_|. When we read from this |
| 449 // location, we must always read from it atomically. | 445 // location, we must always read from it atomically. |
| 450 base::subtle::Atomic32* cursor_location_memory() { | 446 base::subtle::Atomic32* cursor_location_memory() { |
| 451 return reinterpret_cast<base::subtle::Atomic32*>( | 447 return reinterpret_cast<base::subtle::Atomic32*>( |
| 452 cursor_location_mapping_.get()); | 448 cursor_location_mapping_.get()); |
| 453 } | 449 } |
| 454 | 450 |
| 455 // This is set once and only once when we get OnEmbed(). It gives the unique | 451 // This is set once and only once when we get OnEmbed(). It gives the unique |
| 456 // id for this client. | 452 // id for this client. |
| 457 ClientSpecificId client_id_; | 453 ClientSpecificId client_id_; |
| 458 | 454 |
| 459 // Id assigned to the next window created. | 455 // Id assigned to the next window created. |
| 460 ClientSpecificId next_window_id_; | 456 ClientSpecificId next_window_id_; |
| 461 | 457 |
| 462 // Id used for the next change id supplied to the server. | 458 // Id used for the next change id supplied to the server. |
| 463 uint32_t next_change_id_; | 459 uint32_t next_change_id_; |
| 464 InFlightMap in_flight_map_; | 460 InFlightMap in_flight_map_; |
| 465 | 461 |
| 466 WindowTreeClientDelegate* delegate_; | 462 WindowTreeClientDelegate* delegate_; |
| 467 | 463 |
| 468 WindowManagerDelegate* window_manager_delegate_; | 464 WindowManagerDelegate* window_manager_delegate_; |
| 469 | 465 |
| 470 std::set<WindowMus*> roots_; | 466 std::set<WindowMus*> roots_; |
| 471 | 467 |
| 472 IdToWindowMap windows_; | 468 IdToWindowMap windows_; |
| 473 std::map<ClientSpecificId, std::set<Window*>> embedded_windows_; | 469 std::map<ClientSpecificId, std::set<Window*>> embedded_windows_; |
| 474 | 470 |
| 475 bool setting_capture_ = false; | 471 std::unique_ptr<CaptureSynchronizer> capture_synchronizer_; |
| 476 WindowMus* window_setting_capture_to_ = nullptr; | |
| 477 WindowMus* capture_window_ = nullptr; | |
| 478 | 472 |
| 479 bool setting_focus_ = false; | 473 bool setting_focus_ = false; |
| 480 WindowMus* window_setting_focus_to_ = nullptr; | 474 WindowMus* window_setting_focus_to_ = nullptr; |
| 481 WindowMus* focused_window_ = nullptr; | 475 WindowMus* focused_window_ = nullptr; |
| 482 | 476 |
| 483 mojo::Binding<ui::mojom::WindowTreeClient> binding_; | 477 mojo::Binding<ui::mojom::WindowTreeClient> binding_; |
| 484 ui::mojom::WindowTreePtr tree_ptr_; | 478 ui::mojom::WindowTreePtr tree_ptr_; |
| 485 // Typically this is the value contained in |tree_ptr_|, but tests may | 479 // Typically this is the value contained in |tree_ptr_|, but tests may |
| 486 // directly set this. | 480 // directly set this. |
| 487 ui::mojom::WindowTree* tree_; | 481 ui::mojom::WindowTree* tree_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 517 std::unique_ptr<DragDropControllerMus> drag_drop_controller_; | 511 std::unique_ptr<DragDropControllerMus> drag_drop_controller_; |
| 518 | 512 |
| 519 base::WeakPtrFactory<WindowTreeClient> weak_factory_; | 513 base::WeakPtrFactory<WindowTreeClient> weak_factory_; |
| 520 | 514 |
| 521 DISALLOW_COPY_AND_ASSIGN(WindowTreeClient); | 515 DISALLOW_COPY_AND_ASSIGN(WindowTreeClient); |
| 522 }; | 516 }; |
| 523 | 517 |
| 524 } // namespace aura | 518 } // namespace aura |
| 525 | 519 |
| 526 #endif // UI_AURA_MUS_WINDOW_TREE_CLIENT_H_ | 520 #endif // UI_AURA_MUS_WINDOW_TREE_CLIENT_H_ |
| OLD | NEW |