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.
5 #ifndef COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_
6 #define COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_
10 #include "base/basictypes.h"
11 #include "ui/mojo/events/input_event_constants.mojom.h"
12 #include "ui/mojo/events/input_events.mojom.h"
13 #include "ui/mojo/events/input_key_codes.mojom.h"
15 namespace view_manager
{
17 class ConnectionManager
;
20 // Handles dispatching events to the right location as well as updating focus.
21 class EventDispatcher
{
23 explicit EventDispatcher(ConnectionManager
* connection_manager
);
26 void AddAccelerator(uint32_t id
,
27 mojo::KeyboardCode keyboard_code
,
28 mojo::EventFlags flags
);
29 void RemoveAccelerator(uint32_t id
);
31 void OnEvent(ServerView
* root
, mojo::EventPtr event
);
35 Accelerator(mojo::KeyboardCode keyboard_code
, mojo::EventFlags flags
)
36 : keyboard_code(keyboard_code
), flags(flags
) {}
38 // So we can use this in a set.
39 bool operator<(const Accelerator
& other
) const {
40 if (keyboard_code
== other
.keyboard_code
)
41 return flags
< other
.flags
;
42 return keyboard_code
< other
.keyboard_code
;
45 mojo::KeyboardCode keyboard_code
;
46 mojo::EventFlags flags
;
49 // Looks to see if there is an accelerator bound to the specified code/flags.
50 // If there is one, sets |accelerator_id| to the id of the accelerator invoked
51 // and returns true. If there is none, returns false so normal key event
52 // processing can continue.
53 bool HandleAccelerator(mojo::KeyboardCode keyboard_code
,
54 mojo::EventFlags flags
,
55 uint32_t* accelerator_id
);
57 ConnectionManager
* connection_manager_
;
59 using Entry
= std::pair
<uint32_t, Accelerator
>;
60 std::map
<uint32_t, Accelerator
> accelerators_
;
62 DISALLOW_COPY_AND_ASSIGN(EventDispatcher
);
65 } // namespace view_manager
67 #endif // COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_