Chromium Code Reviews| Index: mash/wm/window_manager_application.cc |
| diff --git a/mash/wm/window_manager_application.cc b/mash/wm/window_manager_application.cc |
| index 1e934c6699654233331f22d35dc5ddc2f27ed10b..1cf17e308ef46d55a12a6e2b876f5df22370c0cc 100644 |
| --- a/mash/wm/window_manager_application.cc |
| +++ b/mash/wm/window_manager_application.cc |
| @@ -4,11 +4,13 @@ |
| #include "mash/wm/window_manager_application.h" |
| +#include "base/bind.h" |
| #include "components/mus/common/util.h" |
| #include "components/mus/public/cpp/event_matcher.h" |
| #include "components/mus/public/cpp/window.h" |
| #include "components/mus/public/cpp/window_tree_connection.h" |
| #include "components/mus/public/cpp/window_tree_host_factory.h" |
| +#include "mash/wm/accelerator_registrar_impl.h" |
| #include "mash/wm/background_layout.h" |
| #include "mash/wm/shelf_layout.h" |
| #include "mash/wm/window_layout.h" |
| @@ -51,6 +53,11 @@ void WindowManagerApplication::AddAccelerators() { |
| mus::mojom::EVENT_FLAGS_CONTROL_DOWN)); |
| } |
| +void WindowManagerApplication::OnAcceleratorRegistrarDestroyed( |
| + AcceleratorRegistrarImpl* registrar) { |
| + accelerator_registrars_.erase(registrar); |
| +} |
| + |
| void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { |
| app_ = app; |
| tracing_.Initialize(app); |
| @@ -68,7 +75,8 @@ void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { |
| bool WindowManagerApplication::ConfigureIncomingConnection( |
| mojo::ApplicationConnection* connection) { |
| - connection->AddService(this); |
| + connection->AddService<mus::mojom::AcceleratorRegistrar>(this); |
| + connection->AddService<mus::mojom::WindowManager>(this); |
| return true; |
| } |
| @@ -79,7 +87,12 @@ void WindowManagerApplication::OnAccelerator(uint32_t id, |
| window_tree_host_->ActivateNextWindow(); |
| break; |
| default: |
| - NOTREACHED() << "Unknown accelerator command: " << id; |
| + for (auto* registrar : accelerator_registrars_) { |
| + if (registrar->OwnsAccelerator(id)) { |
| + registrar->ProcessAccelerator(id, event.Pass()); |
| + break; |
| + } |
| + } |
| } |
| } |
| @@ -116,6 +129,24 @@ void WindowManagerApplication::OnConnectionLost( |
| void WindowManagerApplication::Create( |
| mojo::ApplicationConnection* connection, |
| + mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) { |
| + static int accelerator_registrar_count = 0; |
| + if (accelerator_registrar_count == std::numeric_limits<int>::max()) { |
| + // Restart from zero if we have reached the limit. It is technically |
| + // possible to end up with multiple active registrars with the same |
| + // namespace, but it is highly unlikely. In the event that multiple |
| + // registrars have the same namespace, this new registrar will be unable to |
| + // install accelerators. |
|
Ben Goodger (Google)
2015/12/02 00:59:45
how is this enforced? you don't seem to prevent re
sadrul
2015/12/02 19:14:25
Ah, you are right. We do not actually do the right
|
| + accelerator_registrar_count = 0; |
| + } |
| + accelerator_registrars_.insert(new AcceleratorRegistrarImpl( |
| + window_tree_host_.get(), ++accelerator_registrar_count, request.Pass(), |
| + base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed, |
| + base::Unretained(this)))); |
| +} |
| + |
| +void WindowManagerApplication::Create( |
| + mojo::ApplicationConnection* connection, |
| mojo::InterfaceRequest<mus::mojom::WindowManager> request) { |
| if (root_) { |
| window_manager_binding_.AddBinding(window_manager_.get(), request.Pass()); |