| 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_VIEW_MANAGER_CONNECTION_MANAGER_H_ | 5 #ifndef COMPONENTS_VIEW_MANAGER_CONNECTION_MANAGER_H_ |
| 6 #define COMPONENTS_VIEW_MANAGER_CONNECTION_MANAGER_H_ | 6 #define COMPONENTS_VIEW_MANAGER_CONNECTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "components/native_viewport/public/interfaces/native_viewport.mojom.h" | 14 #include "components/native_viewport/public/interfaces/native_viewport.mojom.h" |
| 15 #include "components/view_manager/animation_runner.h" | 15 #include "components/view_manager/animation_runner.h" |
| 16 #include "components/view_manager/event_dispatcher.h" | 16 #include "components/view_manager/event_dispatcher.h" |
| 17 #include "components/view_manager/focus_controller_delegate.h" | 17 #include "components/view_manager/focus_controller_delegate.h" |
| 18 #include "components/view_manager/ids.h" | 18 #include "components/view_manager/ids.h" |
| 19 #include "components/view_manager/public/interfaces/view_manager.mojom.h" | 19 #include "components/view_manager/public/interfaces/view_manager.mojom.h" |
| 20 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h" |
| 20 #include "components/view_manager/server_view_delegate.h" | 21 #include "components/view_manager/server_view_delegate.h" |
| 21 #include "components/view_manager/server_view_observer.h" | 22 #include "components/view_manager/server_view_observer.h" |
| 22 #include "components/window_manager/public/interfaces/window_manager_internal.mo
jom.h" | |
| 23 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" | 23 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" |
| 24 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 24 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
| 25 | 25 |
| 26 namespace view_manager { | 26 namespace view_manager { |
| 27 | 27 |
| 28 class ClientConnection; | 28 class ClientConnection; |
| 29 class ConnectionManagerDelegate; | 29 class ConnectionManagerDelegate; |
| 30 class DisplayManager; | 30 class DisplayManager; |
| 31 class FocusController; | 31 class FocusController; |
| 32 class ServerView; | 32 class ServerView; |
| 33 class ViewManagerServiceImpl; | 33 class ViewManagerServiceImpl; |
| 34 | 34 |
| 35 // ConnectionManager manages the set of connections to the ViewManager (all the | 35 // ConnectionManager manages the set of connections to the ViewManager (all the |
| 36 // ViewManagerServiceImpls) as well as providing the root of the hierarchy. | 36 // ViewManagerServiceImpls) as well as providing the root of the hierarchy. |
| 37 class ConnectionManager : public ServerViewDelegate, | 37 class ConnectionManager : public ServerViewDelegate, |
| 38 public ServerViewObserver, | 38 public ServerViewObserver, |
| 39 public mojo::WindowManagerInternalClient, | 39 public mojo::ViewManagerRoot, |
| 40 public FocusControllerDelegate { | 40 public FocusControllerDelegate { |
| 41 public: | 41 public: |
| 42 // Create when a ViewManagerServiceImpl is about to make a change. Ensures | 42 // Create when a ViewManagerServiceImpl is about to make a change. Ensures |
| 43 // clients are notified correctly. | 43 // clients are notified correctly. |
| 44 class ScopedChange { | 44 class ScopedChange { |
| 45 public: | 45 public: |
| 46 ScopedChange(ViewManagerServiceImpl* connection, | 46 ScopedChange(ViewManagerServiceImpl* connection, |
| 47 ConnectionManager* connection_manager, | 47 ConnectionManager* connection_manager, |
| 48 bool is_delete_view); | 48 bool is_delete_view); |
| 49 ~ScopedChange(); | 49 ~ScopedChange(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 const mojo::ConnectionSpecificId connection_id_; | 66 const mojo::ConnectionSpecificId connection_id_; |
| 67 const bool is_delete_view_; | 67 const bool is_delete_view_; |
| 68 | 68 |
| 69 // See description of MarkConnectionAsMessaged/DidMessageConnection. | 69 // See description of MarkConnectionAsMessaged/DidMessageConnection. |
| 70 std::set<mojo::ConnectionSpecificId> message_ids_; | 70 std::set<mojo::ConnectionSpecificId> message_ids_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 72 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 ConnectionManager(ConnectionManagerDelegate* delegate, | 75 ConnectionManager(ConnectionManagerDelegate* delegate, |
| 76 scoped_ptr<DisplayManager> display_manager, | 76 scoped_ptr<DisplayManager> display_manager); |
| 77 mojo::WindowManagerInternal* wm_internal); | |
| 78 ~ConnectionManager() override; | 77 ~ConnectionManager() override; |
| 79 | 78 |
| 80 // Creates a new ServerView. The return value is owned by the caller, but must | 79 // Creates a new ServerView. The return value is owned by the caller, but must |
| 81 // be destroyed before ConnectionManager. | 80 // be destroyed before ConnectionManager. |
| 82 ServerView* CreateServerView(const ViewId& id); | 81 ServerView* CreateServerView(const ViewId& id); |
| 83 | 82 |
| 84 // Returns the id for the next ViewManagerServiceImpl. | 83 // Returns the id for the next ViewManagerServiceImpl. |
| 85 mojo::ConnectionSpecificId GetAndAdvanceNextConnectionId(); | 84 mojo::ConnectionSpecificId GetAndAdvanceNextConnectionId(); |
| 86 | 85 |
| 87 // Invoked when a ViewManagerServiceImpl's connection encounters an error. | 86 // Invoked when a ViewManagerServiceImpl's connection encounters an error. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // Returns true if OnConnectionMessagedClient() was invoked for id. | 123 // Returns true if OnConnectionMessagedClient() was invoked for id. |
| 125 bool DidConnectionMessageClient(mojo::ConnectionSpecificId id) const; | 124 bool DidConnectionMessageClient(mojo::ConnectionSpecificId id) const; |
| 126 | 125 |
| 127 // Returns the ViewManagerServiceImpl that has |id| as a root. | 126 // Returns the ViewManagerServiceImpl that has |id| as a root. |
| 128 ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) { | 127 ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) { |
| 129 return const_cast<ViewManagerServiceImpl*>( | 128 return const_cast<ViewManagerServiceImpl*>( |
| 130 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id)); | 129 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id)); |
| 131 } | 130 } |
| 132 const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const; | 131 const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const; |
| 133 | 132 |
| 134 mojo::WindowManagerInternal* wm_internal() { return wm_internal_; } | 133 mojo::ViewManagerRootClient* view_manager_root_client() { |
| 134 return view_manager_root_client_.get(); |
| 135 } |
| 135 | 136 |
| 136 void SetWindowManagerClientConnection( | 137 void SetWindowManagerClientConnection( |
| 137 scoped_ptr<ClientConnection> connection); | 138 scoped_ptr<ClientConnection> connection); |
| 138 bool has_window_manager_client_connection() const { | 139 bool has_window_manager_client_connection() const { |
| 139 return window_manager_client_connection_ != nullptr; | 140 return window_manager_client_connection_ != nullptr; |
| 140 } | 141 } |
| 141 | 142 |
| 142 mojo::ViewManagerClient* GetWindowManagerViewManagerClient(); | 143 mojo::ViewManagerClient* GetWindowManagerViewManagerClient(); |
| 143 | 144 |
| 144 // WindowManagerInternalClient implementation helper; see mojom for details. | 145 // ViewManagerRoot implementation helper; see mojom for details. |
| 145 bool CloneAndAnimate(const ViewId& view_id); | 146 bool CloneAndAnimate(const ViewId& view_id); |
| 146 | 147 |
| 147 // Processes an event, potentially changing focus. | 148 // Processes an event, potentially changing focus. |
| 148 void ProcessEvent(mojo::EventPtr event); | 149 void ProcessEvent(mojo::EventPtr event); |
| 149 | 150 |
| 150 // Dispatches |event| directly to the appropriate connection for |view|. | 151 // Dispatches |event| directly to the appropriate connection for |view|. |
| 151 void DispatchInputEventToView(const ServerView* view, mojo::EventPtr event); | 152 void DispatchInputEventToView(const ServerView* view, mojo::EventPtr event); |
| 152 | 153 |
| 153 // These functions trivially delegate to all ViewManagerServiceImpls, which in | 154 // These functions trivially delegate to all ViewManagerServiceImpls, which in |
| 154 // term notify their clients. | 155 // term notify their clients. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 const gfx::Rect& new_bounds) override; | 217 const gfx::Rect& new_bounds) override; |
| 217 void OnViewReordered(ServerView* view, | 218 void OnViewReordered(ServerView* view, |
| 218 ServerView* relative, | 219 ServerView* relative, |
| 219 mojo::OrderDirection direction) override; | 220 mojo::OrderDirection direction) override; |
| 220 void OnWillChangeViewVisibility(ServerView* view) override; | 221 void OnWillChangeViewVisibility(ServerView* view) override; |
| 221 void OnViewSharedPropertyChanged( | 222 void OnViewSharedPropertyChanged( |
| 222 ServerView* view, | 223 ServerView* view, |
| 223 const std::string& name, | 224 const std::string& name, |
| 224 const std::vector<uint8_t>* new_data) override; | 225 const std::vector<uint8_t>* new_data) override; |
| 225 | 226 |
| 226 // WindowManagerInternalClient: | 227 // ViewManagerRoot: |
| 227 void DispatchInputEventToViewDEPRECATED(mojo::Id transport_view_id, | 228 void SetViewManagerRootClient(mojo::ViewManagerRootClientPtr client) override; |
| 228 mojo::EventPtr event) override; | |
| 229 void SetViewportSize(mojo::SizePtr size) override; | 229 void SetViewportSize(mojo::SizePtr size) override; |
| 230 void CloneAndAnimate(mojo::Id transport_view_id) override; | 230 void CloneAndAnimate(mojo::Id transport_view_id) override; |
| 231 void AddAccelerator(mojo::KeyboardCode keyboard_code, | 231 void AddAccelerator(mojo::KeyboardCode keyboard_code, |
| 232 mojo::EventFlags flags) override; | 232 mojo::EventFlags flags) override; |
| 233 void RemoveAccelerator(mojo::KeyboardCode keyboard_code, | 233 void RemoveAccelerator(mojo::KeyboardCode keyboard_code, |
| 234 mojo::EventFlags flags) override; | 234 mojo::EventFlags flags) override; |
| 235 | 235 |
| 236 // FocusControllerDelegate: | 236 // FocusControllerDelegate: |
| 237 void OnFocusChanged(ServerView* old_focused_view, | 237 void OnFocusChanged(ServerView* old_focused_view, |
| 238 ServerView* new_focused_view) override; | 238 ServerView* new_focused_view) override; |
| 239 | 239 |
| 240 ConnectionManagerDelegate* delegate_; | 240 ConnectionManagerDelegate* delegate_; |
| 241 | 241 |
| 242 // The ClientConnection containing the ViewManagerService implementation | 242 // The ClientConnection containing the ViewManagerService implementation |
| 243 // provided to the initial connection (the WindowManager). | 243 // provided to the initial connection (the WindowManager). |
| 244 // NOTE: |window_manager_client_connection_| is also in |connection_map_|. | 244 // NOTE: |window_manager_client_connection_| is also in |connection_map_|. |
| 245 ClientConnection* window_manager_client_connection_; | 245 ClientConnection* window_manager_client_connection_; |
| 246 | 246 |
| 247 // ID to use for next ViewManagerServiceImpl. | 247 // ID to use for next ViewManagerServiceImpl. |
| 248 mojo::ConnectionSpecificId next_connection_id_; | 248 mojo::ConnectionSpecificId next_connection_id_; |
| 249 | 249 |
| 250 // Set of ViewManagerServiceImpls. | 250 // Set of ViewManagerServiceImpls. |
| 251 ConnectionMap connection_map_; | 251 ConnectionMap connection_map_; |
| 252 | 252 |
| 253 scoped_ptr<DisplayManager> display_manager_; | 253 scoped_ptr<DisplayManager> display_manager_; |
| 254 | 254 |
| 255 scoped_ptr<ServerView> root_; | 255 scoped_ptr<ServerView> root_; |
| 256 | 256 |
| 257 mojo::WindowManagerInternal* wm_internal_; | |
| 258 | |
| 259 // If non-null we're processing a change. The ScopedChange is not owned by us | 257 // If non-null we're processing a change. The ScopedChange is not owned by us |
| 260 // (it's created on the stack by ViewManagerServiceImpl). | 258 // (it's created on the stack by ViewManagerServiceImpl). |
| 261 ScopedChange* current_change_; | 259 ScopedChange* current_change_; |
| 262 | 260 |
| 263 bool in_destructor_; | 261 bool in_destructor_; |
| 264 | 262 |
| 265 // TODO(sky): nuke! Just a proof of concept until get real animation api. | 263 // TODO(sky): nuke! Just a proof of concept until get real animation api. |
| 266 base::RepeatingTimer<ConnectionManager> animation_timer_; | 264 base::RepeatingTimer<ConnectionManager> animation_timer_; |
| 267 | 265 |
| 268 AnimationRunner animation_runner_; | 266 AnimationRunner animation_runner_; |
| 269 | 267 |
| 270 EventDispatcher event_dispatcher_; | 268 EventDispatcher event_dispatcher_; |
| 271 | 269 |
| 272 mojo::Binding<mojo::NativeViewportEventDispatcher> event_dispatcher_binding_; | 270 mojo::Binding<mojo::NativeViewportEventDispatcher> event_dispatcher_binding_; |
| 273 | 271 |
| 274 scoped_ptr<FocusController> focus_controller_; | 272 scoped_ptr<FocusController> focus_controller_; |
| 275 | 273 |
| 274 mojo::ViewManagerRootClientPtr view_manager_root_client_; |
| 275 |
| 276 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); | 276 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); |
| 277 }; | 277 }; |
| 278 | 278 |
| 279 } // namespace view_manager | 279 } // namespace view_manager |
| 280 | 280 |
| 281 #endif // COMPONENTS_VIEW_MANAGER_CONNECTION_MANAGER_H_ | 281 #endif // COMPONENTS_VIEW_MANAGER_CONNECTION_MANAGER_H_ |
| OLD | NEW |