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_ACCELERATORS_ACCELERATOR_REGISTRAR_IMPL_H_ | 5 #ifndef ASH_MUS_ACCELERATORS_ACCELERATOR_REGISTRAR_IMPL_H_ |
6 #define ASH_MUS_ACCELERATORS_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/accelerators/accelerator_handler.h" |
13 #include "ash/mus/window_manager_observer.h" | 13 #include "ash/mus/window_manager_observer.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.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 #include "services/ui/public/interfaces/accelerator_registrar.mojom.h" | 18 #include "services/ui/public/interfaces/accelerator_registrar.mojom.h" |
| 19 #include "ui/base/accelerators/accelerator.h" |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
21 namespace mus { | 22 namespace mus { |
22 | 23 |
23 class WindowManager; | 24 class WindowManager; |
24 | 25 |
25 // Manages AcceleratorHandlers from a particular AcceleratorRegistrar | 26 // Manages AcceleratorHandlers from a particular AcceleratorRegistrar |
26 // connection. This manages its own lifetime, and destroys itself when the | 27 // connection. This manages its own lifetime, and destroys itself when the |
27 // AcceleratorRegistrar and all its AcceleratorHandlers are disconnected. Upon | 28 // AcceleratorRegistrar and all its AcceleratorHandlers are disconnected. Upon |
28 // destruction, it calls the DestroyCallback. | 29 // destruction, it calls the DestroyCallback. |
29 class AcceleratorRegistrarImpl : public ::ui::mojom::AcceleratorRegistrar, | 30 class AcceleratorRegistrarImpl : public ::ui::mojom::AcceleratorRegistrar, |
30 public WindowManagerObserver, | 31 public WindowManagerObserver, |
31 public AcceleratorHandler { | 32 public AcceleratorHandler, |
| 33 public ui::AcceleratorTarget { |
32 public: | 34 public: |
33 using DestroyCallback = base::Callback<void(AcceleratorRegistrarImpl*)>; | 35 using DestroyCallback = base::Callback<void(AcceleratorRegistrarImpl*)>; |
34 AcceleratorRegistrarImpl(WindowManager* window_manager, | 36 AcceleratorRegistrarImpl(WindowManager* window_manager, |
35 uint16_t accelerator_namespace, | 37 uint16_t accelerator_namespace, |
36 mojo::InterfaceRequest<AcceleratorRegistrar> request, | 38 mojo::InterfaceRequest<AcceleratorRegistrar> request, |
37 const DestroyCallback& destroy_callback); | 39 const DestroyCallback& destroy_callback); |
38 | 40 |
39 void Destroy(); | 41 void Destroy(); |
40 | 42 |
41 // Returns true if this AcceleratorRegistrar has an accelerator with the | 43 // Returns true if this AcceleratorRegistrar has an accelerator with the |
42 // specified id. | 44 // specified id. |
43 bool OwnsAccelerator(uint32_t accelerator_id) const; | 45 bool OwnsAccelerator(uint32_t accelerator_id) const; |
44 | 46 |
45 void ProcessAccelerator(uint32_t accelerator_id, const ui::Event& event); | 47 void ProcessAccelerator(uint32_t accelerator_id, const ui::Event& event); |
46 | 48 |
47 private: | 49 private: |
48 ~AcceleratorRegistrarImpl() override; | 50 ~AcceleratorRegistrarImpl() override; |
49 | 51 |
50 void OnBindingGone(); | 52 void OnBindingGone(); |
51 void OnHandlerGone(); | 53 void OnHandlerGone(); |
52 | 54 |
53 void RemoveAllAccelerators(); | 55 void RemoveAllAccelerators(); |
54 | 56 |
| 57 // If |matcher| identifies a key-binding accelerator registers it and |
| 58 // returns true, returns false otherwise. |
| 59 bool AddAcceleratorForKeyBinding(uint32_t accelerator_id, |
| 60 const ::ui::mojom::EventMatcher& matcher, |
| 61 const AddAcceleratorCallback& callback); |
| 62 |
55 // ::ui::mojom::AcceleratorRegistrar: | 63 // ::ui::mojom::AcceleratorRegistrar: |
56 void SetHandler(::ui::mojom::AcceleratorHandlerPtr handler) override; | 64 void SetHandler(::ui::mojom::AcceleratorHandlerPtr handler) override; |
57 void AddAccelerator(uint32_t accelerator_id, | 65 void AddAccelerator(uint32_t accelerator_id, |
58 ::ui::mojom::EventMatcherPtr matcher, | 66 ::ui::mojom::EventMatcherPtr matcher, |
59 const AddAcceleratorCallback& callback) override; | 67 const AddAcceleratorCallback& callback) override; |
60 void RemoveAccelerator(uint32_t accelerator_id) override; | 68 void RemoveAccelerator(uint32_t accelerator_id) override; |
61 | 69 |
62 // AcceleratorHandler: | 70 // AcceleratorHandler: |
63 ui::mojom::EventResult OnAccelerator(uint32_t id, | 71 ui::mojom::EventResult OnAccelerator(uint32_t id, |
64 const ui::Event& event) override; | 72 const ui::Event& event) override; |
65 | 73 |
66 // WindowManagerObserver: | 74 // WindowManagerObserver: |
67 void OnWindowTreeClientDestroyed() override; | 75 void OnWindowTreeClientDestroyed() override; |
68 | 76 |
| 77 // AcceleratorTarget: |
| 78 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 79 bool CanHandleAccelerators() const override; |
| 80 |
69 WindowManager* window_manager_; | 81 WindowManager* window_manager_; |
70 ::ui::mojom::AcceleratorHandlerPtr accelerator_handler_; | 82 ::ui::mojom::AcceleratorHandlerPtr accelerator_handler_; |
71 mojo::Binding<AcceleratorRegistrar> binding_; | 83 mojo::Binding<AcceleratorRegistrar> binding_; |
72 uint16_t accelerator_namespace_; | 84 uint16_t accelerator_namespace_; |
| 85 // Only contains non-keyboard accelerators. |
73 std::set<uint32_t> accelerators_; | 86 std::set<uint32_t> accelerators_; |
74 DestroyCallback destroy_callback_; | 87 DestroyCallback destroy_callback_; |
75 | 88 |
| 89 // Used only for keyboard accelerators. |
| 90 std::map<ui::Accelerator, uint16_t> keyboard_accelerator_to_id_; |
| 91 std::map<uint16_t, ui::Accelerator> id_to_keyboard_accelerator_; |
| 92 |
76 DISALLOW_COPY_AND_ASSIGN(AcceleratorRegistrarImpl); | 93 DISALLOW_COPY_AND_ASSIGN(AcceleratorRegistrarImpl); |
77 }; | 94 }; |
78 | 95 |
79 } // namespace mus | 96 } // namespace mus |
80 } // namespace ash | 97 } // namespace ash |
81 | 98 |
82 #endif // ASH_MUS_ACCELERATORS_ACCELERATOR_REGISTRAR_IMPL_H_ | 99 #endif // ASH_MUS_ACCELERATORS_ACCELERATOR_REGISTRAR_IMPL_H_ |
OLD | NEW |