| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 MASH_WM_ACCELERATOR_REGISTRAR_IMPL_H_ | 5 #ifndef ASH_MUS_ACCELERATOR_REGISTRAR_IMPL_H_ |
| 6 #define MASH_WM_ACCELERATOR_REGISTRAR_IMPL_H_ | 6 #define ASH_MUS_ACCELERATOR_REGISTRAR_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "ash/mus/root_windows_observer.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "components/mus/public/interfaces/accelerator_registrar.mojom.h" | 15 #include "components/mus/public/interfaces/accelerator_registrar.mojom.h" |
| 15 #include "mash/wm/root_windows_observer.h" | |
| 16 #include "mojo/public/cpp/bindings/binding_set.h" | 16 #include "mojo/public/cpp/bindings/binding_set.h" |
| 17 #include "mojo/public/cpp/bindings/strong_binding.h" | 17 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 18 | 18 |
| 19 namespace mash { | 19 namespace ash { |
| 20 namespace wm { | 20 namespace mus { |
| 21 | 21 |
| 22 class WindowManagerApplication; | 22 class WindowManagerApplication; |
| 23 | 23 |
| 24 // Manages AcceleratorHandlers from a particular AcceleratorRegistrar | 24 // Manages AcceleratorHandlers from a particular AcceleratorRegistrar |
| 25 // connection. This manages its own lifetime, and destroys itself when the | 25 // connection. This manages its own lifetime, and destroys itself when the |
| 26 // AcceleratorRegistrar and all its AcceleratorHandlers are disconnected. Upon | 26 // AcceleratorRegistrar and all its AcceleratorHandlers are disconnected. Upon |
| 27 // destruction, it calls the DestroyCallback. | 27 // destruction, it calls the DestroyCallback. |
| 28 class AcceleratorRegistrarImpl : public mus::mojom::AcceleratorRegistrar, | 28 class AcceleratorRegistrarImpl : public ::mus::mojom::AcceleratorRegistrar, |
| 29 public RootWindowsObserver { | 29 public RootWindowsObserver { |
| 30 public: | 30 public: |
| 31 using DestroyCallback = base::Callback<void(AcceleratorRegistrarImpl*)>; | 31 using DestroyCallback = base::Callback<void(AcceleratorRegistrarImpl*)>; |
| 32 AcceleratorRegistrarImpl(WindowManagerApplication* wm_app, | 32 AcceleratorRegistrarImpl(WindowManagerApplication* wm_app, |
| 33 uint32_t accelerator_namespace, | 33 uint32_t accelerator_namespace, |
| 34 mojo::InterfaceRequest<AcceleratorRegistrar> request, | 34 mojo::InterfaceRequest<AcceleratorRegistrar> request, |
| 35 const DestroyCallback& destroy_callback); | 35 const DestroyCallback& destroy_callback); |
| 36 | 36 |
| 37 void Destroy(); | 37 void Destroy(); |
| 38 | 38 |
| 39 // Returns true if this AcceleratorRegistrar has an accelerator with the | 39 // Returns true if this AcceleratorRegistrar has an accelerator with the |
| 40 // specified id. | 40 // specified id. |
| 41 bool OwnsAccelerator(uint32_t accelerator_id) const; | 41 bool OwnsAccelerator(uint32_t accelerator_id) const; |
| 42 | 42 |
| 43 void ProcessAccelerator(uint32_t accelerator_id, mus::mojom::EventPtr event); | 43 void ProcessAccelerator(uint32_t accelerator_id, |
| 44 ::mus::mojom::EventPtr event); |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 struct Accelerator; | 47 struct Accelerator; |
| 47 | 48 |
| 48 ~AcceleratorRegistrarImpl() override; | 49 ~AcceleratorRegistrarImpl() override; |
| 49 | 50 |
| 50 uint32_t ComputeAcceleratorId(uint32_t accelerator_id) const; | 51 uint32_t ComputeAcceleratorId(uint32_t accelerator_id) const; |
| 51 void OnBindingGone(); | 52 void OnBindingGone(); |
| 52 void OnHandlerGone(); | 53 void OnHandlerGone(); |
| 53 | 54 |
| 54 void AddAcceleratorToRoot(RootWindowController* root, | 55 void AddAcceleratorToRoot(RootWindowController* root, |
| 55 uint32_t namespaced_accelerator_id); | 56 uint32_t namespaced_accelerator_id); |
| 56 | 57 |
| 57 void RemoveAllAccelerators(); | 58 void RemoveAllAccelerators(); |
| 58 | 59 |
| 59 // mus::mojom::AcceleratorRegistrar: | 60 // ::mus::mojom::AcceleratorRegistrar: |
| 60 void SetHandler(mus::mojom::AcceleratorHandlerPtr handler) override; | 61 void SetHandler(::mus::mojom::AcceleratorHandlerPtr handler) override; |
| 61 void AddAccelerator(uint32_t accelerator_id, | 62 void AddAccelerator(uint32_t accelerator_id, |
| 62 mus::mojom::EventMatcherPtr matcher, | 63 ::mus::mojom::EventMatcherPtr matcher, |
| 63 const AddAcceleratorCallback& callback) override; | 64 const AddAcceleratorCallback& callback) override; |
| 64 void RemoveAccelerator(uint32_t accelerator_id) override; | 65 void RemoveAccelerator(uint32_t accelerator_id) override; |
| 65 | 66 |
| 66 // RootWindowsObserver: | 67 // RootWindowsObserver: |
| 67 void OnRootWindowControllerAdded(RootWindowController* controller) override; | 68 void OnRootWindowControllerAdded(RootWindowController* controller) override; |
| 68 | 69 |
| 69 WindowManagerApplication* wm_app_; | 70 WindowManagerApplication* wm_app_; |
| 70 mus::mojom::AcceleratorHandlerPtr accelerator_handler_; | 71 ::mus::mojom::AcceleratorHandlerPtr accelerator_handler_; |
| 71 mojo::Binding<AcceleratorRegistrar> binding_; | 72 mojo::Binding<AcceleratorRegistrar> binding_; |
| 72 uint32_t accelerator_namespace_; | 73 uint32_t accelerator_namespace_; |
| 73 std::map<uint32_t, Accelerator> accelerators_; | 74 std::map<uint32_t, Accelerator> accelerators_; |
| 74 DestroyCallback destroy_callback_; | 75 DestroyCallback destroy_callback_; |
| 75 | 76 |
| 76 DISALLOW_COPY_AND_ASSIGN(AcceleratorRegistrarImpl); | 77 DISALLOW_COPY_AND_ASSIGN(AcceleratorRegistrarImpl); |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 } // namespace wm | 80 } // namespace mus |
| 80 } // namespace mash | 81 } // namespace ash |
| 81 | 82 |
| 82 #endif // MASH_WM_ACCELERATOR_REGISTRAR_IMPL_H_ | 83 #endif // ASH_MUS_ACCELERATOR_REGISTRAR_IMPL_H_ |
| OLD | NEW |