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