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_MUS_EVENT_DISPATCHER_H_
6 #define COMPONENTS_MUS_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"
18 class ViewTreeHostImpl
;
20 // Handles dispatching events to the right location as well as updating focus.
21 class EventDispatcher
{
23 explicit EventDispatcher(ViewTreeHostImpl
* view_tree_host
);
26 void AddAccelerator(uint32_t id
,
27 mojo::KeyboardCode keyboard_code
,
28 mojo::EventFlags flags
);
29 void RemoveAccelerator(uint32_t id
);
31 void OnEvent(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 FindAccelerator(const mojo::Event
& event
, uint32_t* accelerator_id
);
55 // Returns the ServerView that should receive |event|. If |event| is a
56 // pointer-type event, then this function also updates the event location to
57 // make sure it is in the returned target's coordinate space.
58 ServerView
* FindEventTarget(mojo::Event
* event
);
60 ViewTreeHostImpl
* view_tree_host_
;
62 using Entry
= std::pair
<uint32_t, Accelerator
>;
63 std::map
<uint32_t, Accelerator
> accelerators_
;
65 DISALLOW_COPY_AND_ASSIGN(EventDispatcher
);
70 #endif // COMPONENTS_MUS_EVENT_DISPATCHER_H_