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