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 ASH_MUS_ACCELERATOR_REGISTRAR_IMPL_H_ | 5 #ifndef ASH_MUS_ACCELERATORS_ACCELERATOR_REGISTRAR_IMPL_H_ |
6 #define ASH_MUS_ACCELERATOR_REGISTRAR_IMPL_H_ | 6 #define ASH_MUS_ACCELERATORS_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/accelerators/accelerator_handler.h" |
12 #include "ash/mus/window_manager_observer.h" | 13 #include "ash/mus/window_manager_observer.h" |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "mojo/public/cpp/bindings/binding_set.h" | 16 #include "mojo/public/cpp/bindings/binding_set.h" |
16 #include "mojo/public/cpp/bindings/strong_binding.h" | 17 #include "mojo/public/cpp/bindings/strong_binding.h" |
17 #include "services/ui/public/interfaces/accelerator_registrar.mojom.h" | 18 #include "services/ui/public/interfaces/accelerator_registrar.mojom.h" |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
20 namespace mus { | 21 namespace mus { |
21 | 22 |
22 class WindowManager; | 23 class WindowManager; |
23 | 24 |
24 // Manages AcceleratorHandlers from a particular AcceleratorRegistrar | 25 // Manages AcceleratorHandlers from a particular AcceleratorRegistrar |
25 // connection. This manages its own lifetime, and destroys itself when the | 26 // connection. This manages its own lifetime, and destroys itself when the |
26 // AcceleratorRegistrar and all its AcceleratorHandlers are disconnected. Upon | 27 // AcceleratorRegistrar and all its AcceleratorHandlers are disconnected. Upon |
27 // destruction, it calls the DestroyCallback. | 28 // destruction, it calls the DestroyCallback. |
28 class AcceleratorRegistrarImpl : public ::ui::mojom::AcceleratorRegistrar, | 29 class AcceleratorRegistrarImpl : public ::ui::mojom::AcceleratorRegistrar, |
29 public WindowManagerObserver { | 30 public WindowManagerObserver, |
| 31 public AcceleratorHandler { |
30 public: | 32 public: |
31 using DestroyCallback = base::Callback<void(AcceleratorRegistrarImpl*)>; | 33 using DestroyCallback = base::Callback<void(AcceleratorRegistrarImpl*)>; |
32 AcceleratorRegistrarImpl(WindowManager* window_manager, | 34 AcceleratorRegistrarImpl(WindowManager* window_manager, |
33 uint32_t accelerator_namespace, | 35 uint16_t accelerator_namespace, |
34 mojo::InterfaceRequest<AcceleratorRegistrar> request, | 36 mojo::InterfaceRequest<AcceleratorRegistrar> request, |
35 const DestroyCallback& destroy_callback); | 37 const DestroyCallback& destroy_callback); |
36 | 38 |
37 void Destroy(); | 39 void Destroy(); |
38 | 40 |
39 // Returns true if this AcceleratorRegistrar has an accelerator with the | 41 // Returns true if this AcceleratorRegistrar has an accelerator with the |
40 // specified id. | 42 // specified id. |
41 bool OwnsAccelerator(uint32_t accelerator_id) const; | 43 bool OwnsAccelerator(uint32_t accelerator_id) const; |
42 | 44 |
43 void ProcessAccelerator(uint32_t accelerator_id, const ui::Event& event); | 45 void ProcessAccelerator(uint32_t accelerator_id, const ui::Event& event); |
44 | 46 |
45 private: | 47 private: |
46 ~AcceleratorRegistrarImpl() override; | 48 ~AcceleratorRegistrarImpl() override; |
47 | 49 |
48 uint32_t ComputeAcceleratorId(uint32_t accelerator_id) const; | |
49 void OnBindingGone(); | 50 void OnBindingGone(); |
50 void OnHandlerGone(); | 51 void OnHandlerGone(); |
51 | 52 |
52 void RemoveAllAccelerators(); | 53 void RemoveAllAccelerators(); |
53 | 54 |
54 // ::ui::mojom::AcceleratorRegistrar: | 55 // ::ui::mojom::AcceleratorRegistrar: |
55 void SetHandler(::ui::mojom::AcceleratorHandlerPtr handler) override; | 56 void SetHandler(::ui::mojom::AcceleratorHandlerPtr handler) override; |
56 void AddAccelerator(uint32_t accelerator_id, | 57 void AddAccelerator(uint32_t accelerator_id, |
57 ::ui::mojom::EventMatcherPtr matcher, | 58 ::ui::mojom::EventMatcherPtr matcher, |
58 const AddAcceleratorCallback& callback) override; | 59 const AddAcceleratorCallback& callback) override; |
59 void RemoveAccelerator(uint32_t accelerator_id) override; | 60 void RemoveAccelerator(uint32_t accelerator_id) override; |
60 | 61 |
| 62 // AcceleratorHandler: |
| 63 ui::mojom::EventResult OnAccelerator(uint32_t id, |
| 64 const ui::Event& event) override; |
| 65 |
61 // WindowManagerObserver: | 66 // WindowManagerObserver: |
62 void OnAccelerator(uint32_t id, const ui::Event& event) override; | |
63 void OnWindowTreeClientDestroyed() override; | 67 void OnWindowTreeClientDestroyed() override; |
64 | 68 |
65 WindowManager* window_manager_; | 69 WindowManager* window_manager_; |
66 ::ui::mojom::AcceleratorHandlerPtr accelerator_handler_; | 70 ::ui::mojom::AcceleratorHandlerPtr accelerator_handler_; |
67 mojo::Binding<AcceleratorRegistrar> binding_; | 71 mojo::Binding<AcceleratorRegistrar> binding_; |
68 uint32_t accelerator_namespace_; | 72 uint16_t accelerator_namespace_; |
69 std::set<uint32_t> accelerators_; | 73 std::set<uint32_t> accelerators_; |
70 DestroyCallback destroy_callback_; | 74 DestroyCallback destroy_callback_; |
71 | 75 |
72 DISALLOW_COPY_AND_ASSIGN(AcceleratorRegistrarImpl); | 76 DISALLOW_COPY_AND_ASSIGN(AcceleratorRegistrarImpl); |
73 }; | 77 }; |
74 | 78 |
75 } // namespace mus | 79 } // namespace mus |
76 } // namespace ash | 80 } // namespace ash |
77 | 81 |
78 #endif // ASH_MUS_ACCELERATOR_REGISTRAR_IMPL_H_ | 82 #endif // ASH_MUS_ACCELERATORS_ACCELERATOR_REGISTRAR_IMPL_H_ |
OLD | NEW |