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.
5 #ifndef COMPONENTS_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_
6 #define COMPONENTS_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "components/view_manager/public/cpp/types.h"
13 #include "components/view_manager/public/cpp/view_manager_client_factory.h"
14 #include "components/view_manager/public/cpp/view_manager_delegate.h"
15 #include "components/view_manager/public/cpp/view_observer.h"
16 #include "components/window_manager/public/interfaces/window_manager_internal.mojom.h"
17 #include "components/window_manager/window_manager_impl.h"
18 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.h"
19 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_impl.h"
20 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
21 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h"
22 #include "ui/mojo/events/input_events.mojom.h"
23 #include "ui/mojo/events/input_key_codes.mojom.h"
29 namespace window_manager
{
31 class WindowManagerDelegate
;
32 class WindowManagerImpl
;
34 // Implements core window manager functionality that could conceivably be shared
35 // across multiple window managers implementing superficially different user
36 // experiences. Establishes communication with the view manager.
37 // A window manager wishing to use this core should create and own an instance
38 // of this object. They may implement the associated ViewManager/WindowManager
39 // delegate interfaces exposed by the view manager, this object provides the
40 // canonical implementation of said interfaces but will call out to the wrapped
42 class WindowManagerApp
43 : public mojo::ApplicationDelegate
,
44 public mojo::ViewManagerDelegate
,
45 public mojo::ViewObserver
,
46 public mojo::InterfaceFactory
<mojo::WindowManager
>,
47 public mojo::InterfaceFactory
<mojo::WindowManagerInternal
>,
48 public mojo::WindowManagerInternal
{
50 WindowManagerApp(ViewManagerDelegate
* view_manager_delegate
,
51 WindowManagerDelegate
* window_manager_delegate
);
52 ~WindowManagerApp() override
;
54 // Register/deregister new connections to the window manager service.
55 void AddConnection(WindowManagerImpl
* connection
);
56 void RemoveConnection(WindowManagerImpl
* connection
);
58 void DispatchInputEventToViewDEPRECATED(mojo::View
* view
,
59 mojo::EventPtr event
);
60 void SetViewportSize(const gfx::Size
& size
);
64 void AddAccelerator(mojo::KeyboardCode keyboard_code
, mojo::EventFlags flags
);
65 void RemoveAccelerator(mojo::KeyboardCode keyboard_code
,
66 mojo::EventFlags flags
);
68 // WindowManagerImpl::Embed() forwards to this. If connected to ViewManager
69 // then forwards to delegate, otherwise waits for connection to establish then
71 void Embed(const mojo::String
& url
,
72 mojo::InterfaceRequest
<mojo::ServiceProvider
> services
,
73 mojo::ServiceProviderPtr exposed_services
);
75 // Overridden from ApplicationDelegate:
76 void Initialize(mojo::ApplicationImpl
* impl
) override
;
77 bool ConfigureIncomingConnection(
78 mojo::ApplicationConnection
* connection
) override
;
81 // TODO(sky): rename this. Connections is ambiguous.
82 typedef std::set
<WindowManagerImpl
*> Connections
;
86 mojo::ViewManager
* view_manager() {
87 return root_
? root_
->view_manager() : nullptr;
90 // Overridden from ViewManagerDelegate:
91 void OnEmbed(mojo::View
* root
,
92 mojo::InterfaceRequest
<mojo::ServiceProvider
> services
,
93 mojo::ServiceProviderPtr exposed_services
) override
;
94 void OnViewManagerDisconnected(mojo::ViewManager
* view_manager
) override
;
96 // Overridden from ViewObserver:
97 void OnViewDestroying(mojo::View
* view
) override
;
99 // Creates the connection to the ViewManager.
100 void LaunchViewManager(mojo::ApplicationImpl
* app
);
102 // InterfaceFactory<WindowManagerInternal>:
104 mojo::ApplicationConnection
* connection
,
105 mojo::InterfaceRequest
<mojo::WindowManagerInternal
> request
) override
;
107 // InterfaceFactory<WindowManager>:
108 void Create(mojo::ApplicationConnection
* connection
,
109 mojo::InterfaceRequest
<mojo::WindowManager
> request
) override
;
111 // WindowManagerInternal:
112 void SetViewManagerClient(
113 mojo::ScopedMessagePipeHandle view_manager_client_request
) override
;
114 void OnAccelerator(mojo::EventPtr event
) override
;
118 ViewManagerDelegate
* wrapped_view_manager_delegate_
;
119 WindowManagerDelegate
* window_manager_delegate_
;
121 mojo::ViewManagerServicePtr view_manager_service_
;
122 scoped_ptr
<mojo::ViewManagerClientFactory
> view_manager_client_factory_
;
126 Connections connections_
;
128 mojo::WindowManagerInternalClientPtr window_manager_client_
;
130 ScopedVector
<PendingEmbed
> pending_embeds_
;
132 scoped_ptr
<mojo::ViewManagerClient
> view_manager_client_
;
134 scoped_ptr
<mojo::Binding
<WindowManagerInternal
>> wm_internal_binding_
;
136 DISALLOW_COPY_AND_ASSIGN(WindowManagerApp
);
139 } // namespace window_manager
141 #endif // COMPONENTS_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_