Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: ash/mus/accelerators/accelerator_controller_registrar.h

Issue 2187703003: Wires up registering accelerators from mash with the wm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/BUILD.gn ('k') | ash/mus/accelerators/accelerator_controller_registrar.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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_CONTROLLER_REGISTRAR_H_
6 #define ASH_MUS_ACCELERATORS_ACCELERATOR_CONTROLLER_REGISTRAR_H_
7
8 #include <stdint.h>
9
10 #include <map>
11
12 #include "ash/mus/accelerators/accelerator_handler.h"
13 #include "base/macros.h"
14 #include "ui/base/accelerators/accelerator.h"
15 #include "ui/base/accelerators/accelerator_manager_delegate.h"
16 #include "ui/events/mojo/event_constants.mojom.h"
17
18 namespace ash {
19
20 class AcceleratorRouter;
21
22 namespace mus {
23
24 class WindowManager;
25
26 // Responsible for registering accelerators created by AcceleratorController
27 // with the WindowManager, as well as routing handling of accelerators to
28 // the right place.
29 class AcceleratorControllerRegistrar : public AcceleratorHandler,
30 public ui::AcceleratorManagerDelegate {
31 public:
32 AcceleratorControllerRegistrar(WindowManager* window_manager,
33 uint16_t id_namespace);
34 ~AcceleratorControllerRegistrar() override;
35
36 // AcceleratorHandler:
37 ui::mojom::EventResult OnAccelerator(uint32_t id,
38 const ui::Event& event) override;
39
40 // ui::AcceleratorManagerDelegate:
41 void OnAcceleratorRegistered(const ui::Accelerator& accelerator) override;
42 void OnAcceleratorUnregistered(const ui::Accelerator& accelerator) override;
43
44 private:
45 // The flow of accelerators in ash is:
46 // . wm::AcceleratorFilter() sees events first as it's a pre-target handler.
47 // . AcceleratorFilter forwards to its delegate, which indirectly is
48 // implemented by AcceleratorRouter.
49 // . AcceleratorRouter may early out, if not it calls through to
50 // AcceleratorController. This stop may stop propagation entirely.
51 // . If focus is on a Widget, then NativeWidgetAura gets the key event, calls
52 // to Widget::OnKeyEvent(), which calls to FocusManager::OnKeyEvent(), which
53 // calls to AshFocusManagerFactory::Delegate::ProcessAccelerator() finally
54 // ending up in AcceleratorController::Process().
55 // . OTOH if focus is on a content, then
56 // RenderWidgetHostViewAura::OnKeyEvent() is called and may end up consuming
57 // the event.
58 //
59 // To get this behavior for mash we register accelerators for both pre and
60 // post. Pre gives the behavior of AcceleratorRouter and post that of
61 // AshFocusManagerFactory.
62 //
63 // These ids all use the namespace |id_namespace_|.
64 struct Ids {
65 uint16_t pre_id;
66 uint16_t post_id;
67 };
68
69 // Returns the next local id for an accelerator, or false if the max number of
70 // accelerators have been registered.
71 bool GenerateIds(Ids* ids);
72
73 // Used internally by GenerateIds(). Returns the next local id (as well as
74 // updating |ids_|). This *must* be called from GenerateIds().
75 uint16_t GetNextLocalAcceleratorId();
76
77 WindowManager* window_manager_;
78
79 const uint16_t id_namespace_;
80
81 // Id to use for the next accelerator.
82 uint16_t next_id_;
83
84 std::unique_ptr<AcceleratorRouter> router_;
85
86 // Set of registered local ids.
87 std::set<uint16_t> ids_;
88
89 // Maps from accelerator to the two ids registered for it.
90 std::map<ui::Accelerator, Ids> accelerator_to_ids_;
91
92 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerRegistrar);
93 };
94
95 } // namespace mus
96 } // namespace ash
97
98 #endif // ASH_MUS_ACCELERATORS_ACCELERATOR_CONTROLLER_REGISTRAR_H_
OLDNEW
« no previous file with comments | « ash/mus/BUILD.gn ('k') | ash/mus/accelerators/accelerator_controller_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698