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