| 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 MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ | 5 #ifndef MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ |
| 6 #define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ | 6 #define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "mojo/aura/window_tree_host_mojo.h" |
| 12 #include "mojo/public/cpp/application/application_delegate.h" | 13 #include "mojo/public/cpp/application/application_delegate.h" |
| 13 #include "mojo/public/cpp/application/interface_factory_impl.h" | 14 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 14 #include "mojo/public/cpp/bindings/string.h" | 15 #include "mojo/public/cpp/bindings/string.h" |
| 15 #include "mojo/services/public/cpp/view_manager/types.h" | 16 #include "mojo/services/public/cpp/view_manager/types.h" |
| 16 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 18 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 19 #include "mojo/services/public/interfaces/window_manager/window_manager_internal
.mojom.h" | 20 #include "mojo/services/public/interfaces/window_manager/window_manager_internal
.mojom.h" |
| 20 #include "mojo/services/window_manager/focus_controller_observer.h" | |
| 21 #include "mojo/services/window_manager/native_viewport_event_dispatcher_impl.h" | 21 #include "mojo/services/window_manager/native_viewport_event_dispatcher_impl.h" |
| 22 #include "mojo/services/window_manager/view_target.h" | |
| 23 #include "mojo/services/window_manager/window_manager_impl.h" | 22 #include "mojo/services/window_manager/window_manager_impl.h" |
| 23 #include "ui/aura/client/focus_change_observer.h" |
| 24 #include "ui/events/event_handler.h" | 24 #include "ui/events/event_handler.h" |
| 25 #include "ui/wm/public/activation_change_observer.h" |
| 25 | 26 |
| 26 namespace gfx { | 27 namespace aura { |
| 27 class Size; | 28 namespace client { |
| 29 class ActivationClient; |
| 30 class FocusClient; |
| 31 } |
| 32 class Window; |
| 33 } |
| 34 |
| 35 namespace wm { |
| 36 class FocusRules; |
| 37 class ScopedCaptureClient; |
| 28 } | 38 } |
| 29 | 39 |
| 30 namespace mojo { | 40 namespace mojo { |
| 31 | 41 |
| 32 class FocusController; | 42 class AuraInit; |
| 33 class FocusRules; | 43 class DummyDelegate; |
| 34 class WindowManagerClient; | 44 class WindowManagerClient; |
| 35 class WindowManagerDelegate; | 45 class WindowManagerDelegate; |
| 36 class WindowManagerImpl; | 46 class WindowManagerImpl; |
| 37 class ViewEventDispatcher; | |
| 38 | 47 |
| 39 // Implements core window manager functionality that could conceivably be shared | 48 // Implements core window manager functionality that could conceivably be shared |
| 40 // across multiple window managers implementing superficially different user | 49 // across multiple window managers implementing superficially different user |
| 41 // experiences. Establishes communication with the view manager. | 50 // experiences. Establishes communication with the view manager. |
| 42 // A window manager wishing to use this core should create and own an instance | 51 // A window manager wishing to use this core should create and own an instance |
| 43 // of this object. They may implement the associated ViewManager/WindowManager | 52 // of this object. They may implement the associated ViewManager/WindowManager |
| 44 // delegate interfaces exposed by the view manager, this object provides the | 53 // delegate interfaces exposed by the view manager, this object provides the |
| 45 // canonical implementation of said interfaces but will call out to the wrapped | 54 // canonical implementation of said interfaces but will call out to the wrapped |
| 46 // instances. | 55 // instances. |
| 56 // This object maintains an aura::WindowTreeHost containing a hierarchy of |
| 57 // aura::Windows. Window manager functionality (e.g. focus, activation, |
| 58 // modality, etc.) are implemented using aura core window manager components. |
| 47 class WindowManagerApp : public ApplicationDelegate, | 59 class WindowManagerApp : public ApplicationDelegate, |
| 48 public ViewManagerDelegate, | 60 public ViewManagerDelegate, |
| 49 public ViewObserver, | 61 public ViewObserver, |
| 50 public ui::EventHandler, | 62 public ui::EventHandler, |
| 51 public FocusControllerObserver, | 63 public aura::client::FocusChangeObserver, |
| 64 public aura::client::ActivationChangeObserver, |
| 52 public InterfaceFactory<WindowManagerInternal> { | 65 public InterfaceFactory<WindowManagerInternal> { |
| 53 public: | 66 public: |
| 54 WindowManagerApp(ViewManagerDelegate* view_manager_delegate, | 67 WindowManagerApp(ViewManagerDelegate* view_manager_delegate, |
| 55 WindowManagerDelegate* window_manager_delegate); | 68 WindowManagerDelegate* window_manager_delegate); |
| 56 ~WindowManagerApp() override; | 69 ~WindowManagerApp() override; |
| 57 | 70 |
| 58 static View* GetViewForViewTarget(ViewTarget* view); | 71 static View* GetViewForWindow(aura::Window* window); |
| 59 ViewTarget* GetViewTargetForViewId(Id view); | 72 aura::Window* GetWindowForViewId(Id view); |
| 60 | |
| 61 mojo::ViewEventDispatcher* event_dispatcher() { | |
| 62 return view_event_dispatcher_.get(); | |
| 63 } | |
| 64 | 73 |
| 65 // Register/deregister new connections to the window manager service. | 74 // Register/deregister new connections to the window manager service. |
| 66 void AddConnection(WindowManagerImpl* connection); | 75 void AddConnection(WindowManagerImpl* connection); |
| 67 void RemoveConnection(WindowManagerImpl* connection); | 76 void RemoveConnection(WindowManagerImpl* connection); |
| 68 | 77 |
| 69 // These are canonical implementations of the window manager API methods. | 78 // These are canonical implementations of the window manager API methods. |
| 70 void SetCapture(Id view); | 79 void SetCapture(Id view); |
| 71 void FocusWindow(Id view); | 80 void FocusWindow(Id view); |
| 72 void ActivateWindow(Id view); | 81 void ActivateWindow(Id view); |
| 73 | 82 |
| 74 void SetViewportSize(const gfx::Size& size); | 83 void SetViewportSize(const gfx::Size&); |
| 75 | 84 |
| 76 bool IsReady() const; | 85 bool IsReady() const; |
| 77 | 86 |
| 78 FocusController* focus_controller() { return focus_controller_.get(); } | 87 // A client of this object will use this accessor to gain access to the |
| 88 // aura::Window hierarchy and attach event handlers. |
| 89 WindowTreeHostMojo* host() { return window_tree_host_.get(); } |
| 79 | 90 |
| 80 void InitFocus(scoped_ptr<FocusRules> rules); | 91 void InitFocus(wm::FocusRules* rules); |
| 81 | 92 |
| 82 // WindowManagerImpl::Embed() forwards to this. If connected to ViewManager | 93 // WindowManagerImpl::Embed() forwards to this. If connected to ViewManager |
| 83 // then forwards to delegate, otherwise waits for connection to establish then | 94 // then forwards to delegate, otherwise waits for connection to establish then |
| 84 // forwards. | 95 // forwards. |
| 85 void Embed(const String& url, | 96 void Embed(const String& url, |
| 86 InterfaceRequest<ServiceProvider> service_provider); | 97 InterfaceRequest<ServiceProvider> service_provider); |
| 87 | 98 |
| 88 // Overridden from ApplicationDelegate: | 99 // Overridden from ApplicationDelegate: |
| 89 void Initialize(ApplicationImpl* impl) override; | 100 void Initialize(ApplicationImpl* impl) override; |
| 90 bool ConfigureIncomingConnection(ApplicationConnection* connection) override; | 101 bool ConfigureIncomingConnection(ApplicationConnection* connection) override; |
| 91 | 102 |
| 92 private: | 103 private: |
| 93 // TODO(sky): rename this. Connections is ambiguous. | 104 // TODO(sky): rename this. Connections is ambiguous. |
| 94 typedef std::set<WindowManagerImpl*> Connections; | 105 typedef std::set<WindowManagerImpl*> Connections; |
| 95 typedef std::map<Id, ViewTarget*> ViewIdToViewTargetMap; | 106 typedef std::map<Id, aura::Window*> ViewIdToWindowMap; |
| 96 | 107 |
| 97 struct PendingEmbed; | 108 struct PendingEmbed; |
| 98 class WindowManagerInternalImpl; | 109 class WindowManagerInternalImpl; |
| 99 | 110 |
| 100 // Creates an ViewTarget for every view in the hierarchy beneath |view|, | |
| 101 // and adds to the registry so that it can be retrieved later via | |
| 102 // GetViewTargetForViewId(). | |
| 103 // TODO(beng): perhaps View should have a property bag. | |
| 104 void RegisterSubtree(View* view, ViewTarget* parent); | |
| 105 | |
| 106 // Recursively invokes Unregister() for |view| and all its descendants. | |
| 107 void UnregisterSubtree(View* view); | |
| 108 | |
| 109 // Deletes the ViewTarget associated with the hierarchy beneath |id|, | |
| 110 // and removes from the registry. | |
| 111 void Unregister(View* view); | |
| 112 | |
| 113 // Overridden from ViewManagerDelegate: | 111 // Overridden from ViewManagerDelegate: |
| 114 void OnEmbed(ViewManager* view_manager, | 112 void OnEmbed(ViewManager* view_manager, |
| 115 View* root, | 113 View* root, |
| 116 ServiceProviderImpl* exported_services, | 114 ServiceProviderImpl* exported_services, |
| 117 scoped_ptr<ServiceProvider> imported_services) override; | 115 scoped_ptr<ServiceProvider> imported_services) override; |
| 118 void OnViewManagerDisconnected(ViewManager* view_manager) override; | 116 void OnViewManagerDisconnected(ViewManager* view_manager) override; |
| 119 | 117 |
| 120 // Overridden from ViewObserver: | 118 // Overridden from ViewObserver: |
| 121 void OnTreeChanged(const ViewObserver::TreeChangeParams& params) override; | 119 void OnTreeChanged(const ViewObserver::TreeChangeParams& params) override; |
| 122 void OnViewDestroying(View* view) override; | 120 void OnViewDestroying(View* view) override; |
| 123 void OnViewBoundsChanged(View* view, | 121 void OnViewBoundsChanged(View* view, |
| 124 const Rect& old_bounds, | 122 const Rect& old_bounds, |
| 125 const Rect& new_bounds) override; | 123 const Rect& new_bounds) override; |
| 126 | 124 |
| 127 // Overridden from ui::EventHandler: | 125 // Overridden from ui::EventHandler: |
| 128 void OnEvent(ui::Event* event) override; | 126 void OnEvent(ui::Event* event) override; |
| 129 | 127 |
| 130 // Overridden from mojo::FocusControllerObserver: | 128 // Overridden from aura::client::FocusChangeObserver: |
| 131 void OnViewFocused(View* gained_focus, View* lost_focus) override; | 129 void OnWindowFocused(aura::Window* gained_focus, |
| 132 void OnViewActivated(View* gained_active, View* lost_active) override; | 130 aura::Window* lost_focus) override; |
| 131 |
| 132 // Overridden from aura::client::ActivationChangeObserver: |
| 133 void OnWindowActivated(aura::Window* gained_active, |
| 134 aura::Window* lost_active) override; |
| 135 |
| 136 // Creates an aura::Window for every view in the hierarchy beneath |view|, |
| 137 // and adds to the registry so that it can be retrieved later via |
| 138 // GetWindowForViewId(). |
| 139 // TODO(beng): perhaps View should have a property bag. |
| 140 void RegisterSubtree(View* view, aura::Window* parent); |
| 141 // Recursively invokes Unregister() for |view| and all its descendants. |
| 142 void UnregisterSubtree(View* view); |
| 143 // Deletes the aura::Windows associated with the hierarchy beneath |id|, |
| 144 // and removes from the registry. |
| 145 void Unregister(View* view); |
| 133 | 146 |
| 134 // Creates the connection to the ViewManager. | 147 // Creates the connection to the ViewManager. |
| 135 void LaunchViewManager(ApplicationImpl* app); | 148 void LaunchViewManager(ApplicationImpl* app); |
| 136 | 149 |
| 137 // InterfaceFactory<WindowManagerInternal>: | 150 // InterfaceFactory<WindowManagerInternal>: |
| 138 void Create(ApplicationConnection* connection, | 151 void Create(ApplicationConnection* connection, |
| 139 InterfaceRequest<WindowManagerInternal> request) override; | 152 InterfaceRequest<WindowManagerInternal> request) override; |
| 140 | 153 |
| 141 Shell* shell_; | 154 Shell* shell_; |
| 142 | 155 |
| 143 InterfaceFactoryImplWithContext<WindowManagerImpl, WindowManagerApp> | 156 InterfaceFactoryImplWithContext<WindowManagerImpl, WindowManagerApp> |
| 144 window_manager_factory_; | 157 window_manager_factory_; |
| 145 | 158 |
| 146 InterfaceFactoryImplWithContext<NativeViewportEventDispatcherImpl, | 159 InterfaceFactoryImplWithContext<NativeViewportEventDispatcherImpl, |
| 147 WindowManagerApp> | 160 WindowManagerApp> |
| 148 native_viewport_event_dispatcher_factory_; | 161 native_viewport_event_dispatcher_factory_; |
| 149 | 162 |
| 150 ViewManagerDelegate* wrapped_view_manager_delegate_; | 163 ViewManagerDelegate* wrapped_view_manager_delegate_; |
| 151 WindowManagerDelegate* window_manager_delegate_; | 164 WindowManagerDelegate* window_manager_delegate_; |
| 152 | 165 |
| 153 ViewManager* view_manager_; | 166 ViewManager* view_manager_; |
| 154 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 167 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
| 155 View* root_; | 168 View* root_; |
| 156 | 169 |
| 157 scoped_ptr<mojo::FocusController> focus_controller_; | 170 scoped_ptr<AuraInit> aura_init_; |
| 171 scoped_ptr<WindowTreeHostMojo> window_tree_host_; |
| 172 |
| 173 scoped_ptr<wm::ScopedCaptureClient> capture_client_; |
| 174 scoped_ptr<aura::client::FocusClient> focus_client_; |
| 175 aura::client::ActivationClient* activation_client_; |
| 158 | 176 |
| 159 Connections connections_; | 177 Connections connections_; |
| 160 ViewIdToViewTargetMap view_id_to_view_target_map_; | 178 ViewIdToWindowMap view_id_to_window_map_; |
| 179 |
| 180 scoped_ptr<DummyDelegate> dummy_delegate_; |
| 161 | 181 |
| 162 WindowManagerInternalClientPtr window_manager_client_; | 182 WindowManagerInternalClientPtr window_manager_client_; |
| 163 | 183 |
| 164 ScopedVector<PendingEmbed> pending_embeds_; | 184 ScopedVector<PendingEmbed> pending_embeds_; |
| 165 | 185 |
| 166 scoped_ptr<ViewManagerClient> view_manager_client_; | 186 scoped_ptr<ViewManagerClient> view_manager_client_; |
| 167 | 187 |
| 168 scoped_ptr<ViewEventDispatcher> view_event_dispatcher_; | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(WindowManagerApp); | 188 DISALLOW_COPY_AND_ASSIGN(WindowManagerApp); |
| 171 }; | 189 }; |
| 172 | 190 |
| 173 } // namespace mojo | 191 } // namespace mojo |
| 174 | 192 |
| 175 #endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ | 193 #endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ |
| OLD | NEW |