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 "mojo/aura/window_tree_host_mojo.h" 12 #include "mojo/aura/window_tree_host_mojo_delegate.h" 13 #include "mojo/public/cpp/application/application_delegate.h" 14 #include "mojo/public/cpp/application/interface_factory_impl.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/cpp/view_manager/window_manager_delegate.h" 21 #include "mojo/services/window_manager/window_manager_service_impl.h" 22 #include "ui/aura/client/focus_change_observer.h" 23 #include "ui/events/event_handler.h" 24 #include "ui/wm/public/activation_change_observer.h" 25 26 namespace aura { 27 namespace client { 28 class ActivationClient; 29 class FocusClient; 30 } 31 class Window; 32 } 33 34 namespace wm { 35 class ScopedCaptureClient; 36 } 37 38 namespace mojo { 39 40 class AuraInit; 41 class DummyDelegate; 42 class WindowManagerServiceImpl; 43 class WindowTreeHostMojo; 44 45 // Implements core window manager functionality that could conceivably be shared 46 // across multiple window managers implementing superficially different user 47 // experiences. Establishes communication with the view manager. 48 // A window manager wishing to use this core should create and own an instance 49 // of this object. They may implement the associated ViewManager/WindowManager 50 // delegate interfaces exposed by the view manager, this object provides the 51 // canonical implementation of said interfaces but will call out to the wrapped 52 // instances. 53 // This object maintains an aura::WindowTreeHost containing a hierarchy of 54 // aura::Windows. Window manager functionality (e.g. focus, activation, 55 // modality, etc.) are implemented using aura core window manager components. 56 class WindowManagerApp 57 : public ApplicationDelegate, 58 public ViewManagerDelegate, 59 public WindowManagerDelegate, 60 public ViewObserver, 61 public WindowTreeHostMojoDelegate, 62 public ui::EventHandler, 63 public aura::client::FocusChangeObserver, 64 public aura::client::ActivationChangeObserver { 65 public: 66 WindowManagerApp(ViewManagerDelegate* view_manager_delegate, 67 WindowManagerDelegate* window_manager_delegate); 68 virtual ~WindowManagerApp(); 69 70 static View* GetViewForWindow(aura::Window* window); 71 72 // Register/deregister new connections to the window manager service. 73 void AddConnection(WindowManagerServiceImpl* connection); 74 void RemoveConnection(WindowManagerServiceImpl* connection); 75 76 // These are canonical implementations of the window manager API methods. 77 void SetCapture(Id view); 78 void FocusWindow(Id view); 79 void ActivateWindow(Id view); 80 81 bool IsReady() const; 82 83 // A client of this object will use this accessor to gain access to the 84 // aura::Window hierarchy and attach event handlers. host()85 aura::WindowTreeHost* host() { return window_tree_host_.get(); } 86 87 // Overridden from ApplicationDelegate: 88 virtual void Initialize(ApplicationImpl* impl) MOJO_OVERRIDE; 89 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 90 MOJO_OVERRIDE; 91 92 private: 93 typedef std::set<WindowManagerServiceImpl*> Connections; 94 typedef std::map<Id, aura::Window*> ViewIdToWindowMap; 95 96 // Overridden from ViewManagerDelegate: 97 virtual void OnEmbed( 98 ViewManager* view_manager, 99 View* root, 100 ServiceProviderImpl* exported_services, 101 scoped_ptr<ServiceProvider> imported_services) MOJO_OVERRIDE; 102 virtual void OnViewManagerDisconnected( 103 ViewManager* view_manager) MOJO_OVERRIDE; 104 105 // Overridden from WindowManagerDelegate: 106 virtual void Embed( 107 const String& url, 108 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE; 109 virtual void DispatchEvent(EventPtr event) OVERRIDE; 110 111 // Overridden from ViewObserver: 112 virtual void OnTreeChanged( 113 const ViewObserver::TreeChangeParams& params) MOJO_OVERRIDE; 114 virtual void OnViewDestroyed(View* view) MOJO_OVERRIDE; 115 virtual void OnViewBoundsChanged(View* view, 116 const gfx::Rect& old_bounds, 117 const gfx::Rect& new_bounds) MOJO_OVERRIDE; 118 119 // Overridden from WindowTreeHostMojoDelegate: 120 virtual void CompositorContentsChanged(const SkBitmap& bitmap) MOJO_OVERRIDE; 121 122 // Overridden from ui::EventHandler: 123 virtual void OnEvent(ui::Event* event) MOJO_OVERRIDE; 124 125 // Overridden from aura::client::FocusChangeObserver: 126 virtual void OnWindowFocused(aura::Window* gained_focus, 127 aura::Window* lost_focus) MOJO_OVERRIDE; 128 129 // Overridden from aura::client::ActivationChangeObserver: 130 virtual void OnWindowActivated(aura::Window* gained_active, 131 aura::Window* lost_active) MOJO_OVERRIDE; 132 133 aura::Window* GetWindowForViewId(Id view) const; 134 135 // Creates an aura::Window for every view in the hierarchy beneath |view|, 136 // and adds to the registry so that it can be retrieved later via 137 // GetWindowForViewId(). 138 // TODO(beng): perhaps View should have a property bag. 139 void RegisterSubtree(View* view, aura::Window* parent); 140 // Deletes the aura::Windows associated with the hierarchy beneath |id|, 141 // and removes from the registry. 142 void UnregisterSubtree(View* view); 143 144 InterfaceFactoryImplWithContext<WindowManagerServiceImpl, WindowManagerApp> 145 window_manager_service_factory_; 146 147 ViewManagerDelegate* wrapped_view_manager_delegate_; 148 WindowManagerDelegate* wrapped_window_manager_delegate_; 149 150 ViewManager* view_manager_; 151 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; 152 View* root_; 153 154 scoped_ptr<AuraInit> aura_init_; 155 scoped_ptr<WindowTreeHostMojo> window_tree_host_; 156 157 scoped_ptr<wm::ScopedCaptureClient> capture_client_; 158 scoped_ptr<aura::client::FocusClient> focus_client_; 159 aura::client::ActivationClient* activation_client_; 160 161 Connections connections_; 162 ViewIdToWindowMap view_id_to_window_map_; 163 164 scoped_ptr<DummyDelegate> dummy_delegate_; 165 166 DISALLOW_COPY_AND_ASSIGN(WindowManagerApp); 167 }; 168 169 } // namespace mojo 170 171 #endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ 172