| 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/view_manager/animation_runner.h" | 14 #include "components/view_manager/animation_runner.h" |
| 15 #include "components/view_manager/event_dispatcher.h" | 15 #include "components/view_manager/event_dispatcher.h" |
| 16 #include "components/view_manager/focus_controller_delegate.h" | 16 #include "components/view_manager/focus_controller_delegate.h" |
| 17 #include "components/view_manager/ids.h" | 17 #include "components/view_manager/ids.h" |
| 18 #include "components/view_manager/public/interfaces/view_manager.mojom.h" | |
| 19 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h" | 18 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h" |
| 19 #include "components/view_manager/public/interfaces/view_tree.mojom.h" |
| 20 #include "components/view_manager/server_view_delegate.h" | 20 #include "components/view_manager/server_view_delegate.h" |
| 21 #include "components/view_manager/server_view_observer.h" | 21 #include "components/view_manager/server_view_observer.h" |
| 22 #include "components/view_manager/view_manager_root_impl.h" | 22 #include "components/view_manager/view_manager_root_impl.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 FocusController; | 30 class FocusController; |
| 31 class ServerView; | 31 class ServerView; |
| 32 class ViewManagerRootConnection; | 32 class ViewManagerRootConnection; |
| 33 class ViewManagerServiceImpl; | 33 class ViewTreeImpl; |
| 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 // ViewTreeImpl) 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 FocusControllerDelegate { | 39 public FocusControllerDelegate { |
| 40 public: | 40 public: |
| 41 // Create when a ViewManagerServiceImpl is about to make a change. Ensures | 41 // Create when a ViewTreeImpl is about to make a change. Ensures clients are |
| 42 // clients are notified correctly. | 42 // notified correctly. |
| 43 class ScopedChange { | 43 class ScopedChange { |
| 44 public: | 44 public: |
| 45 ScopedChange(ViewManagerServiceImpl* connection, | 45 ScopedChange(ViewTreeImpl* connection, |
| 46 ConnectionManager* connection_manager, | 46 ConnectionManager* connection_manager, |
| 47 bool is_delete_view); | 47 bool is_delete_view); |
| 48 ~ScopedChange(); | 48 ~ScopedChange(); |
| 49 | 49 |
| 50 mojo::ConnectionSpecificId connection_id() const { return connection_id_; } | 50 mojo::ConnectionSpecificId connection_id() const { return connection_id_; } |
| 51 bool is_delete_view() const { return is_delete_view_; } | 51 bool is_delete_view() const { return is_delete_view_; } |
| 52 | 52 |
| 53 // Marks the connection with the specified id as having seen a message. | 53 // Marks the connection with the specified id as having seen a message. |
| 54 void MarkConnectionAsMessaged(mojo::ConnectionSpecificId connection_id) { | 54 void MarkConnectionAsMessaged(mojo::ConnectionSpecificId connection_id) { |
| 55 message_ids_.insert(connection_id); | 55 message_ids_.insert(connection_id); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 explicit ConnectionManager(ConnectionManagerDelegate* delegate); | 74 explicit ConnectionManager(ConnectionManagerDelegate* delegate); |
| 75 ~ConnectionManager() override; | 75 ~ConnectionManager() override; |
| 76 | 76 |
| 77 // Adds a ViewManagerRoot. | 77 // Adds a ViewManagerRoot. |
| 78 void AddRoot(ViewManagerRootConnection* root_connection); | 78 void AddRoot(ViewManagerRootConnection* root_connection); |
| 79 | 79 |
| 80 // Creates a new ServerView. The return value is owned by the caller, but must | 80 // Creates a new ServerView. The return value is owned by the caller, but must |
| 81 // be destroyed before ConnectionManager. | 81 // be destroyed before ConnectionManager. |
| 82 ServerView* CreateServerView(const ViewId& id); | 82 ServerView* CreateServerView(const ViewId& id); |
| 83 | 83 |
| 84 // Returns the id for the next ViewManagerServiceImpl. | 84 // Returns the id for the next ViewTreeImpl. |
| 85 mojo::ConnectionSpecificId GetAndAdvanceNextConnectionId(); | 85 mojo::ConnectionSpecificId GetAndAdvanceNextConnectionId(); |
| 86 | 86 |
| 87 // Returns the id for the next ViewManagerRootImpl. | 87 // Returns the id for the next ViewManagerRootImpl. |
| 88 uint16_t GetAndAdvanceNextRootId(); | 88 uint16_t GetAndAdvanceNextRootId(); |
| 89 | 89 |
| 90 // Invoked when a ViewManagerServiceImpl's connection encounters an error. | 90 // Invoked when a ViewTreeImpl's connection encounters an error. |
| 91 void OnConnectionError(ClientConnection* connection); | 91 void OnConnectionError(ClientConnection* connection); |
| 92 | 92 |
| 93 // Invoked when a ViewManagerRootBindingOwnerBase's connection encounters an | 93 // Invoked when a ViewManagerRootBindingOwnerBase's connection encounters an |
| 94 // error or the associated Display window is closed. | 94 // error or the associated Display window is closed. |
| 95 void OnRootConnectionClosed(ViewManagerRootConnection* connection); | 95 void OnRootConnectionClosed(ViewManagerRootConnection* connection); |
| 96 | 96 |
| 97 // See description of ViewManagerService::Embed() for details. This assumes | 97 // See description of ViewTree::Embed() for details. This assumes |
| 98 // |transport_view_id| is valid. | 98 // |transport_view_id| is valid. |
| 99 void EmbedAtView(mojo::ConnectionSpecificId creator_id, | 99 void EmbedAtView(mojo::ConnectionSpecificId creator_id, |
| 100 const ViewId& view_id, | 100 const ViewId& view_id, |
| 101 mojo::URLRequestPtr request); | 101 mojo::URLRequestPtr request); |
| 102 ViewManagerServiceImpl* EmbedAtView( | 102 ViewTreeImpl* EmbedAtView(mojo::ConnectionSpecificId creator_id, |
| 103 mojo::ConnectionSpecificId creator_id, | 103 const ViewId& view_id, |
| 104 const ViewId& view_id, | 104 mojo::ViewTreeClientPtr client); |
| 105 mojo::ViewManagerClientPtr client); | |
| 106 | 105 |
| 107 // Invoked when an accelerator has been triggered on a view tree with the | 106 // Invoked when an accelerator has been triggered on a view tree with the |
| 108 // provided |root|. | 107 // provided |root|. |
| 109 void OnAccelerator(ServerView* root, mojo::EventPtr event); | 108 void OnAccelerator(ServerView* root, mojo::EventPtr event); |
| 110 | 109 |
| 111 // Returns the connection by id. | 110 // Returns the connection by id. |
| 112 ViewManagerServiceImpl* GetConnection( | 111 ViewTreeImpl* GetConnection( |
| 113 mojo::ConnectionSpecificId connection_id); | 112 mojo::ConnectionSpecificId connection_id); |
| 114 | 113 |
| 115 // Returns the View identified by |id|. | 114 // Returns the View identified by |id|. |
| 116 ServerView* GetView(const ViewId& id); | 115 ServerView* GetView(const ViewId& id); |
| 117 | 116 |
| 118 void SetFocusedView(ServerView* view); | 117 void SetFocusedView(ServerView* view); |
| 119 ServerView* GetFocusedView(); | 118 ServerView* GetFocusedView(); |
| 120 | 119 |
| 121 // Returns whether |view| is a descendant of some root view but not itself a | 120 // Returns whether |view| is a descendant of some root view but not itself a |
| 122 // root view. | 121 // root view. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 137 // Invoked when a connection messages a client about the change. This is used | 136 // Invoked when a connection messages a client about the change. This is used |
| 138 // to avoid sending ServerChangeIdAdvanced() unnecessarily. | 137 // to avoid sending ServerChangeIdAdvanced() unnecessarily. |
| 139 void OnConnectionMessagedClient(mojo::ConnectionSpecificId id); | 138 void OnConnectionMessagedClient(mojo::ConnectionSpecificId id); |
| 140 | 139 |
| 141 // Returns true if OnConnectionMessagedClient() was invoked for id. | 140 // Returns true if OnConnectionMessagedClient() was invoked for id. |
| 142 bool DidConnectionMessageClient(mojo::ConnectionSpecificId id) const; | 141 bool DidConnectionMessageClient(mojo::ConnectionSpecificId id) const; |
| 143 | 142 |
| 144 // Returns the metrics of the viewport where the provided |view| is displayed. | 143 // Returns the metrics of the viewport where the provided |view| is displayed. |
| 145 mojo::ViewportMetricsPtr GetViewportMetricsForView(const ServerView* view); | 144 mojo::ViewportMetricsPtr GetViewportMetricsForView(const ServerView* view); |
| 146 | 145 |
| 147 // Returns the ViewManagerServiceImpl that has |id| as a root. | 146 // Returns the ViewTreeImpl that has |id| as a root. |
| 148 ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) { | 147 ViewTreeImpl* GetConnectionWithRoot(const ViewId& id) { |
| 149 return const_cast<ViewManagerServiceImpl*>( | 148 return const_cast<ViewTreeImpl*>( |
| 150 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id)); | 149 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id)); |
| 151 } | 150 } |
| 152 const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const; | 151 const ViewTreeImpl* GetConnectionWithRoot(const ViewId& id) const; |
| 153 | 152 |
| 154 // Returns the first ancestor of |service| that is marked as an embed root. | 153 // Returns the first ancestor of |service| that is marked as an embed root. |
| 155 ViewManagerServiceImpl* GetEmbedRoot(ViewManagerServiceImpl* service); | 154 ViewTreeImpl* GetEmbedRoot(ViewTreeImpl* service); |
| 156 | 155 |
| 157 // ViewManagerRoot implementation helper; see mojom for details. | 156 // ViewManagerRoot implementation helper; see mojom for details. |
| 158 bool CloneAndAnimate(const ViewId& view_id); | 157 bool CloneAndAnimate(const ViewId& view_id); |
| 159 | 158 |
| 160 // Dispatches |event| directly to the appropriate connection for |view|. | 159 // Dispatches |event| directly to the appropriate connection for |view|. |
| 161 void DispatchInputEventToView(const ServerView* view, mojo::EventPtr event); | 160 void DispatchInputEventToView(const ServerView* view, mojo::EventPtr event); |
| 162 | 161 |
| 163 void OnEvent(ViewManagerRootImpl* root, mojo::EventPtr event); | 162 void OnEvent(ViewManagerRootImpl* root, mojo::EventPtr event); |
| 164 | 163 |
| 165 void AddAccelerator(ViewManagerRootImpl* root, | 164 void AddAccelerator(ViewManagerRootImpl* root, |
| 166 mojo::KeyboardCode keyboard_code, | 165 mojo::KeyboardCode keyboard_code, |
| 167 mojo::EventFlags flags); | 166 mojo::EventFlags flags); |
| 168 | 167 |
| 169 void RemoveAccelerator(ViewManagerRootImpl* root, | 168 void RemoveAccelerator(ViewManagerRootImpl* root, |
| 170 mojo::KeyboardCode keyboard_code, | 169 mojo::KeyboardCode keyboard_code, |
| 171 mojo::EventFlags flags); | 170 mojo::EventFlags flags); |
| 172 | 171 |
| 173 // Set IME's visibility for the specified view. If the view is not the current | 172 // Set IME's visibility for the specified view. If the view is not the current |
| 174 // focused view, this function will do nothing. | 173 // focused view, this function will do nothing. |
| 175 void SetImeVisibility(ServerView* view, bool visible); | 174 void SetImeVisibility(ServerView* view, bool visible); |
| 176 | 175 |
| 177 // These functions trivially delegate to all ViewManagerServiceImpls, which in | 176 // These functions trivially delegate to all ViewTreeImpls, which in |
| 178 // term notify their clients. | 177 // term notify their clients. |
| 179 void ProcessViewDestroyed(ServerView* view); | 178 void ProcessViewDestroyed(ServerView* view); |
| 180 void ProcessViewBoundsChanged(const ServerView* view, | 179 void ProcessViewBoundsChanged(const ServerView* view, |
| 181 const gfx::Rect& old_bounds, | 180 const gfx::Rect& old_bounds, |
| 182 const gfx::Rect& new_bounds); | 181 const gfx::Rect& new_bounds); |
| 183 void ProcessViewportMetricsChanged(const mojo::ViewportMetrics& old_metrics, | 182 void ProcessViewportMetricsChanged(const mojo::ViewportMetrics& old_metrics, |
| 184 const mojo::ViewportMetrics& new_metrics); | 183 const mojo::ViewportMetrics& new_metrics); |
| 185 void ProcessWillChangeViewHierarchy(const ServerView* view, | 184 void ProcessWillChangeViewHierarchy(const ServerView* view, |
| 186 const ServerView* new_parent, | 185 const ServerView* new_parent, |
| 187 const ServerView* old_parent); | 186 const ServerView* old_parent); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 const ui::TextInputState& state) override; | 254 const ui::TextInputState& state) override; |
| 256 | 255 |
| 257 void CloneAndAnimate(mojo::Id transport_view_id); | 256 void CloneAndAnimate(mojo::Id transport_view_id); |
| 258 | 257 |
| 259 // FocusControllerDelegate: | 258 // FocusControllerDelegate: |
| 260 void OnFocusChanged(ServerView* old_focused_view, | 259 void OnFocusChanged(ServerView* old_focused_view, |
| 261 ServerView* new_focused_view) override; | 260 ServerView* new_focused_view) override; |
| 262 | 261 |
| 263 ConnectionManagerDelegate* delegate_; | 262 ConnectionManagerDelegate* delegate_; |
| 264 | 263 |
| 265 // ID to use for next ViewManagerServiceImpl. | 264 // ID to use for next ViewTreeImpl. |
| 266 mojo::ConnectionSpecificId next_connection_id_; | 265 mojo::ConnectionSpecificId next_connection_id_; |
| 267 | 266 |
| 268 // ID to use for next ViewManagerRootImpl. | 267 // ID to use for next ViewManagerRootImpl. |
| 269 uint16_t next_root_id_; | 268 uint16_t next_root_id_; |
| 270 | 269 |
| 271 EventDispatcher event_dispatcher_; | 270 EventDispatcher event_dispatcher_; |
| 272 | 271 |
| 273 // Set of ViewManagerServiceImpls. | 272 // Set of ViewTreeImpls. |
| 274 ConnectionMap connection_map_; | 273 ConnectionMap connection_map_; |
| 275 | 274 |
| 276 // Set of ViewManagerRootImpls. | 275 // Set of ViewManagerRootImpls. |
| 277 RootConnectionMap root_connection_map_; | 276 RootConnectionMap root_connection_map_; |
| 278 | 277 |
| 279 // If non-null we're processing a change. The ScopedChange is not owned by us | 278 // If non-null we're processing a change. The ScopedChange is not owned by us |
| 280 // (it's created on the stack by ViewManagerServiceImpl). | 279 // (it's created on the stack by ViewTreeImpl). |
| 281 ScopedChange* current_change_; | 280 ScopedChange* current_change_; |
| 282 | 281 |
| 283 bool in_destructor_; | 282 bool in_destructor_; |
| 284 | 283 |
| 285 // TODO(sky): nuke! Just a proof of concept until get real animation api. | 284 // TODO(sky): nuke! Just a proof of concept until get real animation api. |
| 286 base::RepeatingTimer<ConnectionManager> animation_timer_; | 285 base::RepeatingTimer<ConnectionManager> animation_timer_; |
| 287 | 286 |
| 288 AnimationRunner animation_runner_; | 287 AnimationRunner animation_runner_; |
| 289 | 288 |
| 290 scoped_ptr<FocusController> focus_controller_; | 289 scoped_ptr<FocusController> focus_controller_; |
| 291 | 290 |
| 292 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); | 291 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); |
| 293 }; | 292 }; |
| 294 | 293 |
| 295 } // namespace view_manager | 294 } // namespace view_manager |
| 296 | 295 |
| 297 #endif // COMPONENTS_VIEW_MANAGER_CONNECTION_MANAGER_H_ | 296 #endif // COMPONENTS_VIEW_MANAGER_CONNECTION_MANAGER_H_ |
| OLD | NEW |