summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2014-10-14 13:57:56 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-14 20:58:20 +0000
commit38b5f50b180ed985b84ec0d4f02c84a389a24bea (patch)
tree81ba16d3f06809da31ebd4417848c6c71c2af84c
parentc668ebc1a75755c85ef11b1842f7bd182aa9c444 (diff)
downloadchromium_src-38b5f50b180ed985b84ec0d4f02c84a389a24bea.zip
chromium_src-38b5f50b180ed985b84ec0d4f02c84a389a24bea.tar.gz
chromium_src-38b5f50b180ed985b84ec0d4f02c84a389a24bea.tar.bz2
Splits window manager like methods into ViewManagerServiceDelegate
When connecting to the root the ViewManager also connects to the ViewManagerServiceDelegate. BUG=none TEST=none R=ben@chromium.org Review URL: https://codereview.chromium.org/636363002 Cr-Commit-Position: refs/heads/master@{#299544}
-rw-r--r--mojo/examples/window_manager/window_manager.cc32
-rw-r--r--mojo/examples/wm_flow/wm/wm.cc3
-rw-r--r--mojo/mojo_services.gypi10
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc31
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h8
-rw-r--r--mojo/services/public/cpp/view_manager/view_manager.h12
-rw-r--r--mojo/services/public/cpp/view_manager/window_manager_delegate.h33
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom17
-rw-r--r--mojo/services/public/interfaces/window_manager/BUILD.gn17
-rw-r--r--mojo/services/public/interfaces/window_manager/window_manager.mojom34
-rw-r--r--mojo/services/public/mojo_services_public.gyp19
-rw-r--r--mojo/services/view_manager/BUILD.gn5
-rw-r--r--mojo/services/view_manager/connection_manager.cc32
-rw-r--r--mojo/services/view_manager/connection_manager.h23
-rw-r--r--mojo/services/view_manager/display_manager.cc2
-rw-r--r--mojo/services/view_manager/view_manager_init_service_context.cc2
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.cc27
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.h1
-rw-r--r--mojo/services/view_manager/view_manager_unittest.cc83
-rw-r--r--mojo/services/view_manager/window_manager_client_impl.cc41
-rw-r--r--mojo/services/view_manager/window_manager_client_impl.h55
-rw-r--r--mojo/services/window_manager/BUILD.gn5
-rw-r--r--mojo/services/window_manager/main.cc4
-rw-r--r--mojo/services/window_manager/window_manager_app.cc41
-rw-r--r--mojo/services/window_manager/window_manager_app.h37
-rw-r--r--mojo/services/window_manager/window_manager_delegate.h25
-rw-r--r--mojo/services/window_manager/window_manager_service2_impl.cc80
-rw-r--r--mojo/services/window_manager/window_manager_service2_impl.h44
-rw-r--r--mojo/services/window_manager/window_manager_service_impl.cc71
-rw-r--r--mojo/services/window_manager/window_manager_service_impl.h35
30 files changed, 508 insertions, 321 deletions
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index 82a22bb..057ba67 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -20,10 +20,10 @@
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
#include "mojo/services/window_manager/window_manager_app.h"
+#include "mojo/services/window_manager/window_manager_delegate.h"
#include "mojo/views/views_init.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
@@ -181,32 +181,9 @@ class KeyboardManager : public KeyboardClient,
virtual void OnKeyboardEvent(Id view_id,
int32_t code,
int32_t flags) override {
- View* view = view_manager_->GetViewById(view_id);
- if (!view)
- return;
-#if defined(OS_WIN)
- const bool is_char = code != ui::VKEY_BACK && code != ui::VKEY_RETURN;
-#else
- const bool is_char = false;
-#endif
- if (is_char) {
- view_manager_->DispatchEvent(
- view,
- Event::From(ui::KeyEvent(ui::ET_KEY_PRESSED,
- static_cast<ui::KeyboardCode>(code),
- flags)));
- } else {
- view_manager_->DispatchEvent(
- view,
- Event::From(ui::KeyEvent(static_cast<base::char16>(code),
- static_cast<ui::KeyboardCode>(code),
- flags)));
- }
- view_manager_->DispatchEvent(
- view,
- Event::From(ui::KeyEvent(ui::ET_KEY_RELEASED,
- static_cast<ui::KeyboardCode>(code),
- flags)));
+ // TODO(sky): figure this out. Code use to dispatch events, but that's a
+ // hack. Instead strings should be passed through, or maybe a richer text
+ // input interface.
}
// Overridden from ViewObserver:
@@ -463,7 +440,6 @@ class WindowManager
const Id kInvalidSourceViewId = 0;
OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url);
}
- virtual void DispatchEvent(EventPtr event) override {}
// Overridden from ui::EventHandler:
virtual void OnEvent(ui::Event* event) override {
diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc
index 56d8b39..b781f60 100644
--- a/mojo/examples/wm_flow/wm/wm.cc
+++ b/mojo/examples/wm_flow/wm/wm.cc
@@ -13,9 +13,9 @@
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
#include "mojo/services/window_manager/window_manager_app.h"
+#include "mojo/services/window_manager/window_manager_delegate.h"
#include "mojo/views/views_init.h"
#include "ui/aura/window.h"
#include "ui/wm/core/focus_rules.h"
@@ -148,7 +148,6 @@ class SimpleWM : public mojo::ApplicationDelegate,
app_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>(
new mojo::ServiceProviderImpl).Pass());
}
- virtual void DispatchEvent(mojo::EventPtr event) override {}
// Overridden from mojo::ViewObserver:
virtual void OnViewInputEvent(mojo::View* view,
diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi
index 0bc1957..2bb1362 100644
--- a/mojo/mojo_services.gypi
+++ b/mojo/mojo_services.gypi
@@ -424,7 +424,6 @@
'services/public/cpp/view_manager/view_manager_context.h',
'services/public/cpp/view_manager/view_manager_delegate.h',
'services/public/cpp/view_manager/view_observer.h',
- 'services/public/cpp/view_manager/window_manager_delegate.h',
],
'export_dependent_settings': [
'services/public/mojo_services_public.gyp:mojo_view_manager_bindings',
@@ -522,6 +521,7 @@
'services/public/mojo_services_public.gyp:mojo_surfaces_bindings',
'services/public/mojo_services_public.gyp:mojo_view_manager_bindings',
'services/public/mojo_services_public.gyp:mojo_view_manager_common',
+ 'services/public/mojo_services_public.gyp:mojo_window_manager_bindings',
'<(mojo_system_for_loadable_module)',
],
'sources': [
@@ -547,6 +547,8 @@
'services/view_manager/view_manager_service_impl.h',
'services/view_manager/window_manager_access_policy.cc',
'services/view_manager/window_manager_access_policy.h',
+ 'services/view_manager/window_manager_client_impl.cc',
+ 'services/view_manager/window_manager_client_impl.h',
],
'includes': [
'mojo_public_gles2_for_loadable_module.gypi',
@@ -577,6 +579,7 @@
'services/public/mojo_services_public.gyp:mojo_input_events_bindings',
'services/public/mojo_services_public.gyp:mojo_view_manager_bindings',
'services/public/mojo_services_public.gyp:mojo_view_manager_common',
+ 'services/public/mojo_services_public.gyp:mojo_window_manager_bindings',
# Included only to force deps for bots.
'mojo_native_viewport_service',
'mojo_surfaces_service',
@@ -617,13 +620,18 @@
'mojo_base.gyp:mojo_common_lib',
'mojo_input_events_lib',
'mojo_view_manager_lib',
+ 'public/mojo_public.gyp:mojo_application_bindings',
'services/public/mojo_services_public.gyp:mojo_core_window_manager_bindings',
+ 'services/public/mojo_services_public.gyp:mojo_window_manager_bindings',
],
'sources': [
'services/window_manager/window_manager_app.cc',
'services/window_manager/window_manager_app.h',
+ 'services/window_manager/window_manager_delegate.h',
'services/window_manager/window_manager_service_impl.cc',
'services/window_manager/window_manager_service_impl.h',
+ 'services/window_manager/window_manager_service2_impl.cc',
+ 'services/window_manager/window_manager_service2_impl.h',
],
},
{
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
index 41c62ea..699876a 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
@@ -17,7 +17,6 @@
#include "mojo/services/public/cpp/view_manager/util.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
namespace mojo {
@@ -93,11 +92,7 @@ class RootObserver : public ViewObserver {
ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate,
Shell* shell)
- : connected_(false),
- connection_id_(0),
- next_id_(1),
- delegate_(delegate),
- window_manager_delegate_(NULL) {
+ : connected_(false), connection_id_(0), next_id_(1), delegate_(delegate) {
// TODO(beng): Come up with a better way of establishing a configuration for
// what the active window manager is.
std::string window_manager_url = "mojo:mojo_window_manager";
@@ -220,18 +215,6 @@ void ViewManagerClientImpl::RemoveView(Id view_id) {
////////////////////////////////////////////////////////////////////////////////
// ViewManagerClientImpl, ViewManager implementation:
-void ViewManagerClientImpl::SetWindowManagerDelegate(
- WindowManagerDelegate* window_manager_delegate) {
- CHECK(NULL != GetViewById(1));
- CHECK(!window_manager_delegate_);
- window_manager_delegate_ = window_manager_delegate;
-}
-
-void ViewManagerClientImpl::DispatchEvent(View* target, EventPtr event) {
- CHECK(window_manager_delegate_);
- service_->DispatchOnViewInputEvent(target->id(), event.Pass());
-}
-
const std::string& ViewManagerClientImpl::GetEmbedderURL() const {
return creator_url_;
}
@@ -353,18 +336,6 @@ void ViewManagerClientImpl::OnViewInputEvent(
ack_callback.Run();
}
-void ViewManagerClientImpl::Embed(
- const String& url,
- InterfaceRequest<ServiceProvider> service_provider) {
- if (window_manager_delegate_)
- window_manager_delegate_->Embed(url, service_provider.Pass());
-}
-
-void ViewManagerClientImpl::DispatchOnViewInputEvent(EventPtr event) {
- if (window_manager_delegate_)
- window_manager_delegate_->DispatchEvent(event.Pass());
-}
-
////////////////////////////////////////////////////////////////////////////////
// ViewManagerClientImpl, WindowManagerClient2 implementation:
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
index 574d865..f2a2b8e 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
@@ -77,9 +77,6 @@ class ViewManagerClientImpl : public ViewManager,
typedef std::map<Id, View*> IdToViewMap;
// Overridden from ViewManager:
- virtual void SetWindowManagerDelegate(
- WindowManagerDelegate* delegate) override;
- virtual void DispatchEvent(View* target, EventPtr event) override;
virtual const std::string& GetEmbedderURL() const override;
virtual const std::vector<View*>& GetRoots() const override;
virtual View* GetViewById(Id id) override;
@@ -108,10 +105,6 @@ class ViewManagerClientImpl : public ViewManager,
virtual void OnViewInputEvent(Id view_id,
EventPtr event,
const Callback<void()>& callback) override;
- virtual void Embed(
- const String& url,
- InterfaceRequest<ServiceProvider> service_provider) override;
- virtual void DispatchOnViewInputEvent(EventPtr event) override;
// Overridden from WindowManagerClient2:
virtual void OnWindowManagerReady() override;
@@ -139,7 +132,6 @@ class ViewManagerClientImpl : public ViewManager,
base::Callback<void(void)> change_acked_callback_;
ViewManagerDelegate* delegate_;
- WindowManagerDelegate* window_manager_delegate_;
std::vector<View*> roots_;
diff --git a/mojo/services/public/cpp/view_manager/view_manager.h b/mojo/services/public/cpp/view_manager/view_manager.h
index d153283..2586245 100644
--- a/mojo/services/public/cpp/view_manager/view_manager.h
+++ b/mojo/services/public/cpp/view_manager/view_manager.h
@@ -9,12 +9,9 @@
#include <vector>
#include "mojo/services/public/cpp/view_manager/types.h"
-#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
namespace mojo {
class View;
-class ViewManagerDelegate;
-class WindowManagerDelegate;
// Encapsulates a connection to the view manager service.
// A unique connection is made for every unique embed path for an app. e.g. for
@@ -22,15 +19,6 @@ class WindowManagerDelegate;
// and thus two instances of this class.
class ViewManager {
public:
- // Sets the window manager delegate. Can only be called by the app embedded at
- // the service root view. Can only be called once.
- virtual void SetWindowManagerDelegate(
- WindowManagerDelegate* window_manager_delegate) = 0;
-
- // Dispatches the supplied event to the specified View. Can be called only
- // by the application that called SetWindowManagerDelegate().
- virtual void DispatchEvent(View* target, EventPtr event) = 0;
-
// Returns the URL of the application that embedded this application.
virtual const std::string& GetEmbedderURL() const = 0;
diff --git a/mojo/services/public/cpp/view_manager/window_manager_delegate.h b/mojo/services/public/cpp/view_manager/window_manager_delegate.h
deleted file mode 100644
index 0ab271c..0000000
--- a/mojo/services/public/cpp/view_manager/window_manager_delegate.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
-#define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
-
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
-
-namespace mojo {
-
-class View;
-
-// A WindowManagerDelegate is provided by the application embedded at the
-// service root view.
-class WindowManagerDelegate {
- public:
- // Create an appropriate view to embed |url|.
- virtual void Embed(const String& url,
- InterfaceRequest<ServiceProvider> service_provider) {}
-
- // Dispatch the supplied input event to the appropriate view (taking into
- // account focus, activation, modality, etc.).
- virtual void DispatchEvent(EventPtr event) = 0;
-
- protected:
- virtual ~WindowManagerDelegate() {}
-};
-
-} // namespace mojo
-
-#endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index 094f5d3..bf8b82f 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -137,11 +137,6 @@ interface ViewManagerService {
Embed(string url,
uint32 view_id,
ServiceProvider? service_provider) => (bool success);
-
- // TODO(sky): move these to a separate interface when FIFO works.
-
- // Sends OnViewInputEvent() to the owner of the specified view.
- DispatchOnViewInputEvent(uint32 view_id, mojo.Event event);
};
// Changes to views are not sent to the connection that originated the
@@ -197,18 +192,6 @@ interface ViewManagerClient {
// Invoked when an event is targeted at the specified view.
OnViewInputEvent(uint32 view, mojo.Event event) => ();
-
- // TODO(sky): The following methods represent an interface between the view
- // manager and the application embedded at the service root view
- // (i.e. the window manager). These methods are not called on
- // any other clients. They should be moved to a separate interface
- // once support for derived FIFOs is landed.
-
- // Requests the window manager create a "top level" view embedding |url|.
- Embed(string url, ServiceProvider&? service_provider);
-
- // Requests the view manager dispatch the event.
- DispatchOnViewInputEvent(mojo.Event event);
};
}
diff --git a/mojo/services/public/interfaces/window_manager/BUILD.gn b/mojo/services/public/interfaces/window_manager/BUILD.gn
new file mode 100644
index 0000000..3d1e55f
--- /dev/null
+++ b/mojo/services/public/interfaces/window_manager/BUILD.gn
@@ -0,0 +1,17 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+# GYP version: mojo/mojo_services.gypi:mojo_window_manager_bindings
+mojom("window_manager") {
+ sources = [
+ "window_manager.mojom",
+ ]
+
+ deps = [
+ "//mojo/public/interfaces/application",
+ "//mojo/services/public/interfaces/input_events",
+ ]
+}
diff --git a/mojo/services/public/interfaces/window_manager/window_manager.mojom b/mojo/services/public/interfaces/window_manager/window_manager.mojom
new file mode 100644
index 0000000..a0a4ed9
--- /dev/null
+++ b/mojo/services/public/interfaces/window_manager/window_manager.mojom
@@ -0,0 +1,34 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import "mojo/public/interfaces/application/service_provider.mojom"
+import "mojo/services/public/interfaces/input_events/input_events.mojom"
+
+module mojo {
+
+// WindowManagerService provides high level window management policies.
+// WindowManagerService is used by the ViewManager. More specifically the first
+// connection from the ViewManager is expected to provide the
+// WindowManagerService.
+[Client=WindowManagerClient]
+interface WindowManagerService {
+ // Asks the WindowManager to embed |url| at the appropriate place. See
+ // ViewManager::Embed for details of |service_provider|.
+ Embed(string url, ServiceProvider&? service_provider);
+
+ // Called when an input event is received from the native system. It's
+ // expected that when this is received the WindowManagerService will call back
+ // to WindowManagerServieClient will call DispatchInputEventToView().
+ OnViewInputEvent(mojo.Event event);
+};
+
+// ViewManager provides this interface for functionality only exposed to the
+// WindowManagerServie.
+[Client=WindowManagerService]
+interface WindowManagerClient {
+ // Dispatches the specified input event to the specified view.
+ DispatchInputEventToView(uint32 view_id, mojo.Event event);
+};
+
+}
diff --git a/mojo/services/public/mojo_services_public.gyp b/mojo/services/public/mojo_services_public.gyp
index 6bd241e..e344b9f 100644
--- a/mojo/services/public/mojo_services_public.gyp
+++ b/mojo/services/public/mojo_services_public.gyp
@@ -243,6 +243,25 @@
],
},
{
+ # GN version: //mojo/services/public/interfaces/window_manager
+ 'target_name': 'mojo_window_manager_bindings',
+ 'type': 'static_library',
+ 'sources': [
+ 'interfaces/window_manager/window_manager.mojom',
+ ],
+ 'includes': [ '../../public/tools/bindings/mojom_bindings_generator.gypi' ],
+ 'dependencies': [
+ 'mojo_input_events_bindings',
+ '../../public/mojo_public.gyp:mojo_application_bindings',
+ '../../public/mojo_public.gyp:mojo_cpp_bindings',
+ ],
+ 'export_dependent_settings': [
+ 'mojo_input_events_bindings',
+ '../../public/mojo_public.gyp:mojo_application_bindings',
+ '../../public/mojo_public.gyp:mojo_cpp_bindings',
+ ],
+ },
+ {
# GN version: //mojo/services/public/interfaces/window_manager2
'target_name': 'mojo_core_window_manager_bindings',
'type': 'static_library',
diff --git a/mojo/services/view_manager/BUILD.gn b/mojo/services/view_manager/BUILD.gn
index 511a369..33effc1 100644
--- a/mojo/services/view_manager/BUILD.gn
+++ b/mojo/services/view_manager/BUILD.gn
@@ -25,6 +25,7 @@ shared_library("view_manager") {
"//mojo/services/public/interfaces/native_viewport",
"//mojo/services/public/interfaces/surfaces",
"//mojo/services/public/interfaces/view_manager",
+ "//mojo/services/public/interfaces/window_manager",
"//ui/base",
"//ui/events",
"//ui/events:events_base",
@@ -58,6 +59,8 @@ shared_library("view_manager") {
"view_manager_service_impl.h",
"window_manager_access_policy.cc",
"window_manager_access_policy.h",
+ "window_manager_client_impl.cc",
+ "window_manager_client_impl.h",
]
}
@@ -75,6 +78,8 @@ test("mojo_view_manager_unittests") {
"//mojo/public/cpp/bindings",
"//mojo/services/public/cpp/view_manager",
"//mojo/services/public/cpp/view_manager/lib:run_unittests",
+ "//mojo/services/public/interfaces/view_manager",
+ "//mojo/services/public/interfaces/window_manager",
"//mojo/shell:test_support",
"//testing/gtest",
"//ui/gfx/geometry",
diff --git a/mojo/services/view_manager/connection_manager.cc b/mojo/services/view_manager/connection_manager.cc
index 8f8b7a6..d610392 100644
--- a/mojo/services/view_manager/connection_manager.cc
+++ b/mojo/services/view_manager/connection_manager.cc
@@ -31,10 +31,9 @@ ConnectionManager::ConnectionManager(
ApplicationConnection* app_connection,
const Callback<void()>& native_viewport_closed_callback)
: app_connection_(app_connection),
+ wm_client_impl_(this),
next_connection_id_(1),
- display_manager_(app_connection,
- this,
- native_viewport_closed_callback),
+ display_manager_(app_connection, this, native_viewport_closed_callback),
root_(new ServerView(this, RootViewId())),
current_change_(NULL) {
root_->SetBounds(gfx::Rect(800, 600));
@@ -71,21 +70,22 @@ void ConnectionManager::RemoveConnection(ViewManagerServiceImpl* connection) {
}
}
-void ConnectionManager::EmbedRoot(
+void ConnectionManager::Embed(
const std::string& url,
InterfaceRequest<ServiceProvider> service_provider) {
if (connection_map_.empty()) {
+ // TODO(sky): this is unsafe and racy. Need a better way to determine the
+ // window manager.
EmbedImpl(kInvalidConnectionId,
String::From(url),
RootViewId(),
service_provider.Pass());
return;
}
- ViewManagerServiceImpl* connection = GetConnection(kWindowManagerConnection);
- connection->client()->Embed(url, service_provider.Pass());
+ wm_client_impl_.client()->Embed(url, service_provider.Pass());
}
-void ConnectionManager::Embed(
+void ConnectionManager::EmbedAtView(
ConnectionSpecificId creator_id,
const String& url,
Id transport_view_id,
@@ -130,13 +130,9 @@ const ViewManagerServiceImpl* ConnectionManager::GetConnectionWithRoot(
return NULL;
}
-void ConnectionManager::DispatchViewInputEventToWindowManager(EventPtr event) {
- // Input events are forwarded to the WindowManager. The WindowManager
- // eventually calls back to us with DispatchOnViewInputEvent().
- ViewManagerServiceImpl* connection = GetConnection(kWindowManagerConnection);
- if (!connection)
- return;
- connection->client()->DispatchOnViewInputEvent(event.Pass());
+void ConnectionManager::DispatchViewInputEventToDelegate(EventPtr event) {
+ if (wm_client_impl_.client())
+ wm_client_impl_.client()->OnViewInputEvent(event.Pass());
}
void ConnectionManager::ProcessViewBoundsChanged(const ServerView* view,
@@ -214,9 +210,17 @@ ViewManagerServiceImpl* ConnectionManager::EmbedImpl(
ServiceProvider* view_manager_service_provider =
app_connection_->ConnectToApplication(url)->GetServiceProvider();
+
view_manager_service_provider->ConnectToService(
ViewManagerServiceImpl::Client::Name_, pipe.handle1.Pass());
+ if (root_id == RootViewId()) {
+ MessagePipe wm_pipe;
+ view_manager_service_provider->ConnectToService(
+ WindowManagerClientImpl::Client::Name_, wm_pipe.handle1.Pass());
+ WeakBindToPipe(&wm_client_impl_, wm_pipe.handle0.Pass());
+ }
+
std::string creator_url;
ConnectionMap::const_iterator it = connection_map_.find(creator_id);
if (it != connection_map_.end())
diff --git a/mojo/services/view_manager/connection_manager.h b/mojo/services/view_manager/connection_manager.h
index 36fc354..1917439 100644
--- a/mojo/services/view_manager/connection_manager.h
+++ b/mojo/services/view_manager/connection_manager.h
@@ -15,6 +15,7 @@
#include "mojo/services/view_manager/server_view.h"
#include "mojo/services/view_manager/server_view_delegate.h"
#include "mojo/services/view_manager/view_manager_export.h"
+#include "mojo/services/view_manager/window_manager_client_impl.h"
namespace ui {
class Event;
@@ -75,17 +76,19 @@ class MOJO_VIEW_MANAGER_EXPORT ConnectionManager : public ServerViewDelegate {
void AddConnection(ViewManagerServiceImpl* connection);
void RemoveConnection(ViewManagerServiceImpl* connection);
- // Establishes the initial client. Similar to Connect(), but the resulting
- // client is allowed to do anything.
- void EmbedRoot(const std::string& url,
- InterfaceRequest<ServiceProvider> service_provider);
+ // Used in two cases:
+ // . Establishes the client for the root.
+ // . Requests to Embed() at an unspecified view. For this case the request
+ // is passed on to the WindowManagerService.
+ void Embed(const std::string& url,
+ InterfaceRequest<ServiceProvider> service_provider);
// See description of ViewManagerService::Embed() for details. This assumes
// |transport_view_id| is valid.
- void Embed(ConnectionSpecificId creator_id,
- const String& url,
- Id transport_view_id,
- InterfaceRequest<ServiceProvider> service_provider);
+ void EmbedAtView(ConnectionSpecificId creator_id,
+ const String& url,
+ Id transport_view_id,
+ InterfaceRequest<ServiceProvider> service_provider);
// Returns the connection by id.
ViewManagerServiceImpl* GetConnection(ConnectionSpecificId connection_id);
@@ -115,7 +118,7 @@ class MOJO_VIEW_MANAGER_EXPORT ConnectionManager : public ServerViewDelegate {
}
const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const;
- void DispatchViewInputEventToWindowManager(EventPtr event);
+ void DispatchViewInputEventToDelegate(EventPtr event);
// These functions trivially delegate to all ViewManagerServiceImpls, which in
// term notify their clients.
@@ -179,6 +182,8 @@ class MOJO_VIEW_MANAGER_EXPORT ConnectionManager : public ServerViewDelegate {
ApplicationConnection* app_connection_;
+ WindowManagerClientImpl wm_client_impl_;
+
// ID to use for next ViewManagerServiceImpl.
ConnectionSpecificId next_connection_id_;
diff --git a/mojo/services/view_manager/display_manager.cc b/mojo/services/view_manager/display_manager.cc
index 130bd90..06162d1 100644
--- a/mojo/services/view_manager/display_manager.cc
+++ b/mojo/services/view_manager/display_manager.cc
@@ -160,7 +160,7 @@ void DisplayManager::OnSizeChanged(SizePtr size) {
void DisplayManager::OnEvent(EventPtr event,
const mojo::Callback<void()>& callback) {
- connection_manager_->DispatchViewInputEventToWindowManager(event.Pass());
+ connection_manager_->DispatchViewInputEventToDelegate(event.Pass());
callback.Run();
}
diff --git a/mojo/services/view_manager/view_manager_init_service_context.cc b/mojo/services/view_manager/view_manager_init_service_context.cc
index bd934194..d23bec7 100644
--- a/mojo/services/view_manager/view_manager_init_service_context.cc
+++ b/mojo/services/view_manager/view_manager_init_service_context.cc
@@ -58,7 +58,7 @@ void ViewManagerInitServiceContext::Embed(
const String& url,
ServiceProviderPtr service_provider,
const Callback<void(bool)>& callback) {
- connection_manager_->EmbedRoot(url, GetProxy(&service_provider));
+ connection_manager_->Embed(url, GetProxy(&service_provider));
callback.Run(true);
}
diff --git a/mojo/services/view_manager/view_manager_service_impl.cc b/mojo/services/view_manager/view_manager_service_impl.cc
index 06638cf..f066b82 100644
--- a/mojo/services/view_manager/view_manager_service_impl.cc
+++ b/mojo/services/view_manager/view_manager_service_impl.cc
@@ -481,7 +481,7 @@ void ViewManagerServiceImpl::Embed(
spir.Bind(service_provider.PassMessagePipe());
if (ViewIdFromTransportId(transport_view_id) == InvalidViewId()) {
- connection_manager_->EmbedRoot(url, spir.Pass());
+ connection_manager_->Embed(url, spir.Pass());
callback.Run(true);
return;
}
@@ -503,33 +503,10 @@ void ViewManagerServiceImpl::Embed(
connection_manager_->OnConnectionMessagedClient(id_);
existing_owner->RemoveRoot(view_id);
}
- connection_manager_->Embed(id_, url, transport_view_id, spir.Pass());
+ connection_manager_->EmbedAtView(id_, url, transport_view_id, spir.Pass());
callback.Run(true);
}
-void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id,
- EventPtr event) {
- // We only allow the WM to dispatch events. At some point this function will
- // move to a separate interface and the check can go away.
- if (id_ != kWindowManagerConnection)
- return;
-
- const ViewId view_id(ViewIdFromTransportId(transport_view_id));
-
- // If another app is embedded at this view, we forward the input event to the
- // embedded app, rather than the app that created the view.
- ViewManagerServiceImpl* connection =
- connection_manager_->GetConnectionWithRoot(view_id);
- if (!connection)
- connection = connection_manager_->GetConnection(view_id.connection_id);
- if (connection) {
- connection->client()->OnViewInputEvent(
- transport_view_id,
- event.Pass(),
- base::Bind(&base::DoNothing));
- }
-}
-
void ViewManagerServiceImpl::OnConnectionEstablished() {
connection_manager_->AddConnection(this);
diff --git a/mojo/services/view_manager/view_manager_service_impl.h b/mojo/services/view_manager/view_manager_service_impl.h
index 2f2ea9a..c77f285 100644
--- a/mojo/services/view_manager/view_manager_service_impl.h
+++ b/mojo/services/view_manager/view_manager_service_impl.h
@@ -177,7 +177,6 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl
Id view_id,
ServiceProviderPtr service_provider,
const Callback<void(bool)>& callback) override;
- virtual void DispatchOnViewInputEvent(Id view_id, EventPtr event) override;
// InterfaceImpl:
virtual void OnConnectionEstablished() override;
diff --git a/mojo/services/view_manager/view_manager_unittest.cc b/mojo/services/view_manager/view_manager_unittest.cc
index 4123c12..dc3544e 100644
--- a/mojo/services/view_manager/view_manager_unittest.cc
+++ b/mojo/services/view_manager/view_manager_unittest.cc
@@ -20,11 +20,13 @@
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/connect.h"
+#include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/public/cpp/bindings/lib/router.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/cpp/view_manager/util.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
+#include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
#include "mojo/services/view_manager/ids.h"
#include "mojo/services/view_manager/test_change_tracker.h"
#include "mojo/shell/shell_test_helper.h"
@@ -54,10 +56,11 @@ class ViewManagerProxy : public TestChangeTracker::Delegate {
public:
explicit ViewManagerProxy(TestChangeTracker* tracker)
: tracker_(tracker),
- main_loop_(NULL),
- view_manager_(NULL),
+ main_loop_(nullptr),
+ view_manager_(nullptr),
+ window_manager_client_(nullptr),
quit_count_(0),
- router_(NULL) {
+ router_(nullptr) {
SetInstance(this);
}
@@ -79,6 +82,9 @@ class ViewManagerProxy : public TestChangeTracker::Delegate {
}
ViewManagerService* view_manager() { return view_manager_; }
+ WindowManagerClient* window_manager_client() {
+ return window_manager_client_;
+ }
// Runs the main loop until |count| changes have been received.
std::vector<Change> DoRunLoopUntilChangesCount(size_t count) {
@@ -224,6 +230,7 @@ class ViewManagerProxy : public TestChangeTracker::Delegate {
private:
friend class TestViewManagerClientConnection;
+ friend class WindowManagerServiceImpl;
void set_router(mojo::internal::Router* router) { router_ = router; }
@@ -231,6 +238,10 @@ class ViewManagerProxy : public TestChangeTracker::Delegate {
view_manager_ = view_manager;
}
+ void set_window_manager_client(WindowManagerClient* client) {
+ window_manager_client_ = client;
+ }
+
static void RunMainLoop() {
DCHECK(!main_run_loop_);
main_run_loop_ = new base::RunLoop;
@@ -291,6 +302,7 @@ class ViewManagerProxy : public TestChangeTracker::Delegate {
base::MessageLoop* main_loop_;
ViewManagerService* view_manager_;
+ WindowManagerClient* window_manager_client_;
// Number of changes we're waiting on until we quit the current loop.
size_t quit_count_;
@@ -314,14 +326,18 @@ bool ViewManagerProxy::in_embed_ = false;
class TestViewManagerClientConnection
: public InterfaceImpl<ViewManagerClient> {
public:
- TestViewManagerClientConnection() : connection_(&tracker_) {
- tracker_.set_delegate(&connection_);
+ TestViewManagerClientConnection() : proxy_(&tracker_) {
+ tracker_.set_delegate(&proxy_);
}
+ TestChangeTracker* tracker() { return &tracker_; }
+
+ ViewManagerProxy* proxy() { return &proxy_; }
+
// InterfaceImpl:
virtual void OnConnectionEstablished() override {
- connection_.set_router(internal_state()->router());
- connection_.set_view_manager(client());
+ proxy_.set_router(internal_state()->router());
+ proxy_.set_view_manager(client());
}
// ViewManagerClient:
@@ -360,28 +376,47 @@ class TestViewManagerClientConnection
const Callback<void()>& callback) override {
tracker_.OnViewInputEvent(view_id, event.Pass());
}
+
+ private:
+ TestChangeTracker tracker_;
+ ViewManagerProxy proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection);
+};
+
+class WindowManagerServiceImpl : public InterfaceImpl<WindowManagerService> {
+ public:
+ explicit WindowManagerServiceImpl(TestViewManagerClientConnection* connection)
+ : connection_(connection) {}
+ virtual ~WindowManagerServiceImpl() {}
+
+ // InterfaceImpl:
+ virtual void OnConnectionEstablished() override {
+ connection_->proxy()->set_window_manager_client(client());
+ }
+
+ // WindowManagerService:
virtual void Embed(
const String& url,
InterfaceRequest<ServiceProvider> service_provider) override {
- tracker_.DelegateEmbed(url);
- }
- virtual void DispatchOnViewInputEvent(mojo::EventPtr event) override {
+ connection_->tracker()->DelegateEmbed(url);
}
+ virtual void OnViewInputEvent(mojo::EventPtr event) override {}
private:
- TestChangeTracker tracker_;
- ViewManagerProxy connection_;
+ TestViewManagerClientConnection* connection_;
- DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection);
+ DISALLOW_COPY_AND_ASSIGN(WindowManagerServiceImpl);
};
// Used with ViewManagerService::Embed(). Creates a
// TestViewManagerClientConnection, which creates and owns the ViewManagerProxy.
class EmbedApplicationLoader : public ApplicationLoader,
ApplicationDelegate,
- public InterfaceFactory<ViewManagerClient> {
+ public InterfaceFactory<ViewManagerClient>,
+ public InterfaceFactory<WindowManagerService> {
public:
- EmbedApplicationLoader() {}
+ EmbedApplicationLoader() : last_view_manager_client_(nullptr) {}
virtual ~EmbedApplicationLoader() {}
// ApplicationLoader implementation:
@@ -401,17 +436,27 @@ class EmbedApplicationLoader : public ApplicationLoader,
// ApplicationDelegate implementation:
virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
override {
- connection->AddService(this);
+ connection->AddService<ViewManagerClient>(this);
+ connection->AddService<WindowManagerService>(this);
return true;
}
// InterfaceFactory<ViewManagerClient> implementation:
virtual void Create(ApplicationConnection* connection,
InterfaceRequest<ViewManagerClient> request) override {
- BindToRequest(new TestViewManagerClientConnection, &request);
+ last_view_manager_client_ = new TestViewManagerClientConnection;
+ BindToRequest(last_view_manager_client_, &request);
+ }
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<WindowManagerService> request) override {
+ BindToRequest(new WindowManagerServiceImpl(last_view_manager_client_),
+ &request);
}
private:
+ // Used so that TestViewManagerClientConnection and
+ // WindowManagerServiceImpl can share the same TestChangeTracker.
+ TestViewManagerClientConnection* last_view_manager_client_;
ScopedVector<ApplicationImpl> apps_;
DISALLOW_COPY_AND_ASSIGN(EmbedApplicationLoader);
@@ -1190,8 +1235,8 @@ TEST_F(ViewManagerTest, OnViewInput) {
{
EventPtr event(Event::New());
event->action = static_cast<EventType>(1);
- connection_->view_manager()->DispatchOnViewInputEvent(BuildViewId(1, 1),
- event.Pass());
+ connection_->window_manager_client()->DispatchInputEventToView(
+ BuildViewId(1, 1), event.Pass());
connection2_->DoRunLoopUntilChangesCount(1);
const Changes changes(ChangesToDescription1(connection2_->changes()));
ASSERT_EQ(1u, changes.size());
diff --git a/mojo/services/view_manager/window_manager_client_impl.cc b/mojo/services/view_manager/window_manager_client_impl.cc
new file mode 100644
index 0000000..493e8f1
--- /dev/null
+++ b/mojo/services/view_manager/window_manager_client_impl.cc
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/view_manager/window_manager_client_impl.h"
+
+#include "base/bind.h"
+#include "mojo/services/view_manager/connection_manager.h"
+#include "mojo/services/view_manager/view_manager_service_impl.h"
+
+namespace mojo {
+namespace service {
+
+WindowManagerClientImpl::WindowManagerClientImpl(
+ ConnectionManager* connection_manager)
+ : connection_manager_(connection_manager) {
+}
+
+WindowManagerClientImpl::~WindowManagerClientImpl() {
+}
+
+void WindowManagerClientImpl::DispatchInputEventToView(Id transport_view_id,
+ EventPtr event) {
+ const ViewId view_id(ViewIdFromTransportId(transport_view_id));
+
+ ViewManagerServiceImpl* connection =
+ connection_manager_->GetConnectionWithRoot(view_id);
+ if (!connection)
+ connection = connection_manager_->GetConnection(view_id.connection_id);
+ if (connection) {
+ connection->client()->OnViewInputEvent(
+ transport_view_id, event.Pass(), base::Bind(&base::DoNothing));
+ }
+}
+
+void WindowManagerClientImpl::OnConnectionError() {
+ // TODO(sky): deal with this. We may need to tear everything down here.
+}
+
+} // namespace service
+} // namespace mojo
diff --git a/mojo/services/view_manager/window_manager_client_impl.h b/mojo/services/view_manager/window_manager_client_impl.h
new file mode 100644
index 0000000..b25aafe
--- /dev/null
+++ b/mojo/services/view_manager/window_manager_client_impl.h
@@ -0,0 +1,55 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_VIEW_MANAGER_WINDOW_MANAGER_CLIENT_IMPL_H_
+#define MOJO_SERVICES_VIEW_MANAGER_WINDOW_MANAGER_CLIENT_IMPL_H_
+
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
+#include "mojo/services/view_manager/ids.h"
+#include "mojo/services/view_manager/view_manager_export.h"
+
+namespace mojo {
+namespace service {
+
+class ConnectionManager;
+
+#if defined(OS_WIN)
+// Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
+// below.
+#pragma warning(push)
+#pragma warning(disable : 4275)
+#endif
+
+class MOJO_VIEW_MANAGER_EXPORT WindowManagerClientImpl
+ : public InterfaceImpl<WindowManagerClient> {
+ public:
+ explicit WindowManagerClientImpl(ConnectionManager* connection_manager);
+ virtual ~WindowManagerClientImpl();
+
+ // WindowManagerClient:
+ virtual void DispatchInputEventToView(Id transport_view_id,
+ EventPtr event) override;
+
+ // InterfaceImp overrides:
+ virtual void OnConnectionError() override;
+
+ private:
+ ConnectionManager* connection_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowManagerClientImpl);
+};
+
+#if defined(OS_WIN)
+#pragma warning(pop)
+#endif
+
+} // namespace service
+} // namespace mojo
+
+#endif // MOJO_SERVICES_VIEW_MANAGER_WINDOW_MANAGER_CLIENT_IMPL_H_
diff --git a/mojo/services/window_manager/BUILD.gn b/mojo/services/window_manager/BUILD.gn
index 40b22f2..02f3a8e 100644
--- a/mojo/services/window_manager/BUILD.gn
+++ b/mojo/services/window_manager/BUILD.gn
@@ -28,8 +28,11 @@ source_set("lib") {
sources = [
"window_manager_app.cc",
"window_manager_app.h",
+ "window_manager_delegate.h",
"window_manager_service_impl.cc",
"window_manager_service_impl.h",
+ "window_manager_service2_impl.cc",
+ "window_manager_service2_impl.h",
]
public_deps = [
@@ -44,6 +47,7 @@ source_set("lib") {
"//mojo/public/cpp/bindings",
"//mojo/public/interfaces/application:application",
"//mojo/services/public/cpp/view_manager",
+ "//mojo/services/public/interfaces/window_manager",
"//mojo/services/public/interfaces/window_manager2",
"//ui/aura",
"//ui/base",
@@ -68,6 +72,7 @@ test("mojo_core_window_manager_unittests") {
"//mojo/environment:chromium",
"//mojo/services/public/cpp/view_manager",
"//mojo/services/public/interfaces/view_manager",
+ "//mojo/services/public/interfaces/window_manager",
"//mojo/services/public/interfaces/window_manager2",
"//mojo/shell:test_support",
"//testing/gtest",
diff --git a/mojo/services/window_manager/main.cc b/mojo/services/window_manager/main.cc
index ea0edb1..3e2d37c 100644
--- a/mojo/services/window_manager/main.cc
+++ b/mojo/services/window_manager/main.cc
@@ -9,8 +9,8 @@
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
#include "mojo/services/window_manager/window_manager_app.h"
+#include "mojo/services/window_manager/window_manager_delegate.h"
// ApplicationDelegate implementation file for WindowManager users (e.g.
// core window manager tests) that do not want to provide their own
@@ -46,7 +46,6 @@ class DefaultWindowManager : public ApplicationDelegate,
scoped_ptr<ServiceProvider> imported_services) override {
view_manager_ = view_manager;
root_ = root;
- view_manager_->SetWindowManagerDelegate(this);
}
virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {}
@@ -59,7 +58,6 @@ class DefaultWindowManager : public ApplicationDelegate,
view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>(
new mojo::ServiceProviderImpl).Pass());
}
- virtual void DispatchEvent(EventPtr event) override {}
scoped_ptr<WindowManagerApp> window_manager_app_;
diff --git a/mojo/services/window_manager/window_manager_app.cc b/mojo/services/window_manager/window_manager_app.cc
index 518671c..ffd80a8 100644
--- a/mojo/services/window_manager/window_manager_app.cc
+++ b/mojo/services/window_manager/window_manager_app.cc
@@ -81,12 +81,14 @@ WindowManagerApp::WindowManagerApp(
ViewManagerDelegate* view_manager_delegate,
WindowManagerDelegate* window_manager_delegate)
: shell_(nullptr),
+ window_manager_service2_factory_(this),
window_manager_service_factory_(this),
wrapped_view_manager_delegate_(view_manager_delegate),
- wrapped_window_manager_delegate_(window_manager_delegate),
+ window_manager_delegate_(window_manager_delegate),
view_manager_(NULL),
root_(NULL),
- dummy_delegate_(new DummyDelegate) {
+ dummy_delegate_(new DummyDelegate),
+ window_manager_client_(nullptr) {
}
WindowManagerApp::~WindowManagerApp() {}
@@ -101,12 +103,12 @@ aura::Window* WindowManagerApp::GetWindowForViewId(Id view) {
return it != view_id_to_window_map_.end() ? it->second : NULL;
}
-void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) {
+void WindowManagerApp::AddConnection(WindowManagerService2Impl* connection) {
DCHECK(connections_.find(connection) == connections_.end());
connections_.insert(connection);
}
-void WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) {
+void WindowManagerApp::RemoveConnection(WindowManagerService2Impl* connection) {
DCHECK(connections_.find(connection) != connections_.end());
connections_.erase(connection);
}
@@ -157,8 +159,9 @@ void WindowManagerApp::Initialize(ApplicationImpl* impl) {
bool WindowManagerApp::ConfigureIncomingConnection(
ApplicationConnection* connection) {
- connection->AddService(&window_manager_service_factory_);
+ connection->AddService(&window_manager_service2_factory_);
connection->AddService(view_manager_client_factory_.get());
+ connection->AddService(&window_manager_service_factory_);
return true;
}
@@ -171,7 +174,6 @@ void WindowManagerApp::OnEmbed(ViewManager* view_manager,
scoped_ptr<ServiceProvider> imported_services) {
DCHECK(!view_manager_ && !root_);
view_manager_ = view_manager;
- view_manager_->SetWindowManagerDelegate(this);
root_ = root;
window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_));
@@ -204,22 +206,6 @@ void WindowManagerApp::OnViewManagerDisconnected(
}
////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, WindowManagerDelegate implementation:
-
-void WindowManagerApp::Embed(
- const String& url,
- InterfaceRequest<ServiceProvider> service_provider) {
- if (wrapped_window_manager_delegate_)
- wrapped_window_manager_delegate_->Embed(url, service_provider.Pass());
-}
-
-void WindowManagerApp::DispatchEvent(EventPtr event) {
- scoped_ptr<ui::Event> ui_event = event.To<scoped_ptr<ui::Event> >();
- if (ui_event)
- window_tree_host_->SendEventToProcessor(ui_event.get());
-}
-
-////////////////////////////////////////////////////////////////////////////////
// WindowManagerApp, ViewObserver implementation:
void WindowManagerApp::OnTreeChanged(
@@ -270,8 +256,15 @@ void WindowManagerApp::OnViewBoundsChanged(View* view,
// WindowManagerApp, ui::EventHandler implementation:
void WindowManagerApp::OnEvent(ui::Event* event) {
- aura::Window* window = static_cast<aura::Window*>(event->target());
- view_manager_->DispatchEvent(GetViewForWindow(window), Event::From(*event));
+ if (!window_manager_client_)
+ return;
+
+ View* view = GetViewForWindow(static_cast<aura::Window*>(event->target()));
+ if (!view)
+ return;
+
+ window_manager_client_->DispatchInputEventToView(view->id(),
+ Event::From(*event));
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/mojo/services/window_manager/window_manager_app.h b/mojo/services/window_manager/window_manager_app.h
index 5b7ccb5..8c9c244 100644
--- a/mojo/services/window_manager/window_manager_app.h
+++ b/mojo/services/window_manager/window_manager_app.h
@@ -16,7 +16,7 @@
#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
+#include "mojo/services/window_manager/window_manager_service2_impl.h"
#include "mojo/services/window_manager/window_manager_service_impl.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/events/event_handler.h"
@@ -39,8 +39,9 @@ namespace mojo {
class AuraInit;
class DummyDelegate;
-class WindowManagerServiceImpl;
-class WindowTreeHostMojo;
+class WindowManagerClient;
+class WindowManagerDelegate;
+class WindowManagerService2Impl;
// Implements core window manager functionality that could conceivably be shared
// across multiple window managers implementing superficially different user
@@ -56,7 +57,6 @@ class WindowTreeHostMojo;
class WindowManagerApp
: public ApplicationDelegate,
public ViewManagerDelegate,
- public WindowManagerDelegate,
public ViewObserver,
public ui::EventHandler,
public aura::client::FocusChangeObserver,
@@ -70,8 +70,8 @@ class WindowManagerApp
aura::Window* GetWindowForViewId(Id view);
// Register/deregister new connections to the window manager service.
- void AddConnection(WindowManagerServiceImpl* connection);
- void RemoveConnection(WindowManagerServiceImpl* connection);
+ void AddConnection(WindowManagerService2Impl* connection);
+ void RemoveConnection(WindowManagerService2Impl* connection);
// These are canonical implementations of the window manager API methods.
void SetCapture(Id view);
@@ -82,17 +82,25 @@ class WindowManagerApp
// A client of this object will use this accessor to gain access to the
// aura::Window hierarchy and attach event handlers.
- aura::WindowTreeHost* host() { return window_tree_host_.get(); }
+ WindowTreeHostMojo* host() { return window_tree_host_.get(); }
+
+ WindowManagerDelegate* window_manager_delegate() {
+ return window_manager_delegate_;
+ }
void InitFocus(wm::FocusRules* rules);
+ void set_window_manager_client(WindowManagerClient* client) {
+ window_manager_client_ = client;
+ }
+
// Overridden from ApplicationDelegate:
virtual void Initialize(ApplicationImpl* impl) override;
virtual bool ConfigureIncomingConnection(
ApplicationConnection* connection) override;
private:
- typedef std::set<WindowManagerServiceImpl*> Connections;
+ typedef std::set<WindowManagerService2Impl*> Connections;
typedef std::map<Id, aura::Window*> ViewIdToWindowMap;
// Overridden from ViewManagerDelegate:
@@ -102,12 +110,6 @@ class WindowManagerApp
scoped_ptr<ServiceProvider> imported_services) override;
virtual void OnViewManagerDisconnected(ViewManager* view_manager) override;
- // Overridden from WindowManagerDelegate:
- virtual void Embed(
- const String& url,
- InterfaceRequest<ServiceProvider> service_provider) override;
- virtual void DispatchEvent(EventPtr event) override;
-
// Overridden from ViewObserver:
virtual void OnTreeChanged(
const ViewObserver::TreeChangeParams& params) override;
@@ -140,11 +142,14 @@ class WindowManagerApp
Shell* shell_;
+ InterfaceFactoryImplWithContext<WindowManagerService2Impl, WindowManagerApp>
+ window_manager_service2_factory_;
+
InterfaceFactoryImplWithContext<WindowManagerServiceImpl, WindowManagerApp>
window_manager_service_factory_;
ViewManagerDelegate* wrapped_view_manager_delegate_;
- WindowManagerDelegate* wrapped_window_manager_delegate_;
+ WindowManagerDelegate* window_manager_delegate_;
ViewManager* view_manager_;
scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
@@ -162,6 +167,8 @@ class WindowManagerApp
scoped_ptr<DummyDelegate> dummy_delegate_;
+ WindowManagerClient* window_manager_client_;
+
DISALLOW_COPY_AND_ASSIGN(WindowManagerApp);
};
diff --git a/mojo/services/window_manager/window_manager_delegate.h b/mojo/services/window_manager/window_manager_delegate.h
new file mode 100644
index 0000000..72d7d92
--- /dev/null
+++ b/mojo/services/window_manager/window_manager_delegate.h
@@ -0,0 +1,25 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
+#define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
+
+#include "mojo/public/cpp/bindings/string.h"
+#include "mojo/public/interfaces/application/service_provider.mojom.h"
+
+namespace mojo {
+
+class WindowManagerDelegate {
+ public:
+ // See WindowManager::Embed() for details.
+ virtual void Embed(const String& url,
+ InterfaceRequest<ServiceProvider> service_provider) = 0;
+
+ protected:
+ virtual ~WindowManagerDelegate() {}
+};
+
+} // namespace mojo
+
+#endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
diff --git a/mojo/services/window_manager/window_manager_service2_impl.cc b/mojo/services/window_manager/window_manager_service2_impl.cc
new file mode 100644
index 0000000..e00c987
--- /dev/null
+++ b/mojo/services/window_manager/window_manager_service2_impl.cc
@@ -0,0 +1,80 @@
+
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/window_manager/window_manager_service2_impl.h"
+
+#include "mojo/services/window_manager/window_manager_app.h"
+
+namespace mojo {
+
+////////////////////////////////////////////////////////////////////////////////
+// WindowManagerService2Impl, public:
+
+WindowManagerService2Impl::WindowManagerService2Impl(
+ WindowManagerApp* window_manager)
+ : window_manager_(window_manager) {
+ window_manager_->AddConnection(this);
+}
+
+WindowManagerService2Impl::~WindowManagerService2Impl() {
+ window_manager_->RemoveConnection(this);
+}
+
+void WindowManagerService2Impl::NotifyReady() {
+ client()->OnWindowManagerReady();
+}
+
+void WindowManagerService2Impl::NotifyViewFocused(Id new_focused_id,
+ Id old_focused_id) {
+ client()->OnFocusChanged(old_focused_id, new_focused_id);
+}
+
+void WindowManagerService2Impl::NotifyWindowActivated(Id new_active_id,
+ Id old_active_id) {
+ client()->OnActiveWindowChanged(old_active_id, new_active_id);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WindowManagerService2Impl, WindowManager implementation:
+
+void WindowManagerService2Impl::SetCapture(
+ Id view,
+ const Callback<void(bool)>& callback) {
+ bool success = window_manager_->IsReady();
+ if (success)
+ window_manager_->SetCapture(view);
+ callback.Run(success);
+}
+
+void WindowManagerService2Impl::FocusWindow(
+ Id view,
+ const Callback<void(bool)>& callback) {
+ bool success = window_manager_->IsReady();
+ if (success)
+ window_manager_->FocusWindow(view);
+ callback.Run(success);
+}
+
+void WindowManagerService2Impl::ActivateWindow(
+ Id view,
+ const Callback<void(bool)>& callback) {
+ bool success = window_manager_->IsReady();
+ if (success)
+ window_manager_->ActivateWindow(view);
+ callback.Run(success);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WindowManagerService2Impl, InterfaceImpl overrides:
+
+void WindowManagerService2Impl::OnConnectionEstablished() {
+ // If the connection was established prior to the window manager being
+ // embedded by the view manager, |window_manager_|'s ViewManagerDelegate
+ // impl will call NotifyReady() when it is.
+ if (window_manager_->IsReady())
+ NotifyReady();
+}
+
+} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_service2_impl.h b/mojo/services/window_manager/window_manager_service2_impl.h
new file mode 100644
index 0000000..be129b4
--- /dev/null
+++ b/mojo/services/window_manager/window_manager_service2_impl.h
@@ -0,0 +1,44 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE2_IMPL_H_
+#define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE2_IMPL_H_
+
+#include "base/basictypes.h"
+#include "mojo/services/public/cpp/view_manager/types.h"
+#include "mojo/services/public/interfaces/window_manager2/window_manager2.mojom.h"
+
+namespace mojo {
+
+class WindowManagerApp;
+
+class WindowManagerService2Impl : public InterfaceImpl<WindowManagerService2> {
+ public:
+ explicit WindowManagerService2Impl(WindowManagerApp* manager);
+ virtual ~WindowManagerService2Impl();
+
+ void NotifyReady();
+ void NotifyViewFocused(Id new_focused_id, Id old_focused_id);
+ void NotifyWindowActivated(Id new_active_id, Id old_active_id);
+
+ private:
+ // Overridden from WindowManagerService:
+ virtual void SetCapture(Id view,
+ const Callback<void(bool)>& callback) override;
+ virtual void FocusWindow(Id view,
+ const Callback<void(bool)>& callback) override;
+ virtual void ActivateWindow(Id view,
+ const Callback<void(bool)>& callback) override;
+
+ // Overridden from InterfaceImpl:
+ virtual void OnConnectionEstablished() override;
+
+ WindowManagerApp* window_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowManagerService2Impl);
+};
+
+} // namespace mojo
+
+#endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE2_IMPL_H_
diff --git a/mojo/services/window_manager/window_manager_service_impl.cc b/mojo/services/window_manager/window_manager_service_impl.cc
index aa1be19..2ceee5c 100644
--- a/mojo/services/window_manager/window_manager_service_impl.cc
+++ b/mojo/services/window_manager/window_manager_service_impl.cc
@@ -1,80 +1,37 @@
-
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/services/window_manager/window_manager_service_impl.h"
+#include "mojo/aura/window_tree_host_mojo.h"
+#include "mojo/converters/input_events/input_events_type_converters.h"
#include "mojo/services/window_manager/window_manager_app.h"
+#include "mojo/services/window_manager/window_manager_delegate.h"
namespace mojo {
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerServiceImpl, public:
-
-WindowManagerServiceImpl::WindowManagerServiceImpl(
- WindowManagerApp* window_manager)
- : window_manager_(window_manager) {
- window_manager_->AddConnection(this);
+WindowManagerServiceImpl::WindowManagerServiceImpl(WindowManagerApp* app)
+ : app_(app) {
}
WindowManagerServiceImpl::~WindowManagerServiceImpl() {
- window_manager_->RemoveConnection(this);
-}
-
-void WindowManagerServiceImpl::NotifyReady() {
- client()->OnWindowManagerReady();
-}
-
-void WindowManagerServiceImpl::NotifyViewFocused(Id new_focused_id,
- Id old_focused_id) {
- client()->OnFocusChanged(old_focused_id, new_focused_id);
}
-void WindowManagerServiceImpl::NotifyWindowActivated(Id new_active_id,
- Id old_active_id) {
- client()->OnActiveWindowChanged(old_active_id, new_active_id);
+void WindowManagerServiceImpl::Embed(
+ const String& url,
+ InterfaceRequest<ServiceProvider> service_provider) {
+ app_->window_manager_delegate()->Embed(url, service_provider.Pass());
}
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerServiceImpl, WindowManager implementation:
-
-void WindowManagerServiceImpl::SetCapture(
- Id view,
- const Callback<void(bool)>& callback) {
- bool success = window_manager_->IsReady();
- if (success)
- window_manager_->SetCapture(view);
- callback.Run(success);
-}
-
-void WindowManagerServiceImpl::FocusWindow(
- Id view,
- const Callback<void(bool)>& callback) {
- bool success = window_manager_->IsReady();
- if (success)
- window_manager_->FocusWindow(view);
- callback.Run(success);
+void WindowManagerServiceImpl::OnViewInputEvent(mojo::EventPtr event) {
+ scoped_ptr<ui::Event> ui_event = event.To<scoped_ptr<ui::Event>>();
+ if (ui_event)
+ app_->host()->SendEventToProcessor(ui_event.get());
}
-void WindowManagerServiceImpl::ActivateWindow(
- Id view,
- const Callback<void(bool)>& callback) {
- bool success = window_manager_->IsReady();
- if (success)
- window_manager_->ActivateWindow(view);
- callback.Run(success);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerServiceImpl, InterfaceImpl overrides:
-
void WindowManagerServiceImpl::OnConnectionEstablished() {
- // If the connection was established prior to the window manager being
- // embedded by the view manager, |window_manager_|'s ViewManagerDelegate
- // impl will call NotifyReady() when it is.
- if (window_manager_->IsReady())
- NotifyReady();
+ app_->set_window_manager_client(client());
}
} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_service_impl.h b/mojo/services/window_manager/window_manager_service_impl.h
index e72e1ac..ba2d29e 100644
--- a/mojo/services/window_manager/window_manager_service_impl.h
+++ b/mojo/services/window_manager/window_manager_service_impl.h
@@ -2,43 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE_IMPL_H_
-#define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE_IMPL_H_
+#ifndef MOJO_SERVICES_WINDOW_MANAGER_WNDOW_MANAGER_SERVICE_IMPL_H_
+#define MOJO_SERVICES_WINDOW_MANAGER_WNDOW_MANAGER_SERVICE_IMPL_H_
#include "base/basictypes.h"
-#include "mojo/services/public/cpp/view_manager/types.h"
-#include "mojo/services/public/interfaces/window_manager2/window_manager2.mojom.h"
+#include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
namespace mojo {
class WindowManagerApp;
-class WindowManagerServiceImpl : public InterfaceImpl<WindowManagerService2> {
+class WindowManagerServiceImpl : public InterfaceImpl<WindowManagerService> {
public:
- explicit WindowManagerServiceImpl(WindowManagerApp* manager);
+ explicit WindowManagerServiceImpl(WindowManagerApp* app);
virtual ~WindowManagerServiceImpl();
- void NotifyReady();
- void NotifyViewFocused(Id new_focused_id, Id old_focused_id);
- void NotifyWindowActivated(Id new_active_id, Id old_active_id);
-
private:
- // Overridden from WindowManagerService:
- virtual void SetCapture(Id view,
- const Callback<void(bool)>& callback) override;
- virtual void FocusWindow(Id view,
- const Callback<void(bool)>& callback) override;
- virtual void ActivateWindow(Id view,
- const Callback<void(bool)>& callback) override;
-
- // Overridden from InterfaceImpl:
+ // WindowManagerServiceImpl:
+ virtual void Embed(
+ const String& url,
+ InterfaceRequest<ServiceProvider> service_provider) override;
+ virtual void OnViewInputEvent(mojo::EventPtr event) override;
+
+ // InterfaceImpl:
virtual void OnConnectionEstablished() override;
- WindowManagerApp* window_manager_;
+ WindowManagerApp* app_;
DISALLOW_COPY_AND_ASSIGN(WindowManagerServiceImpl);
};
} // namespace mojo
-#endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE_IMPL_H_
+#endif // MOJO_SERVICES_WINDOW_MANAGER_WNDOW_MANAGER_SERVICE_IMPL_H_