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 COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ | |
6 #define COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ | |
7 | |
8 #include <map> | |
9 | |
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" | |
14 | |
15 namespace view_manager { | |
16 | |
17 class ServerView; | |
18 class ViewTreeHostImpl; | |
19 | |
20 // Handles dispatching events to the right location as well as updating focus. | |
21 class EventDispatcher { | |
22 public: | |
23 explicit EventDispatcher(ViewTreeHostImpl* view_tree_host); | |
24 ~EventDispatcher(); | |
25 | |
26 void AddAccelerator(uint32_t id, | |
27 mojo::KeyboardCode keyboard_code, | |
28 mojo::EventFlags flags); | |
29 void RemoveAccelerator(uint32_t id); | |
30 | |
31 void OnEvent(mojo::EventPtr event); | |
32 | |
33 private: | |
34 struct Accelerator { | |
35 Accelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags) | |
36 : keyboard_code(keyboard_code), flags(flags) {} | |
37 | |
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; | |
43 } | |
44 | |
45 mojo::KeyboardCode keyboard_code; | |
46 mojo::EventFlags flags; | |
47 }; | |
48 | |
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); | |
54 | |
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); | |
59 | |
60 ViewTreeHostImpl* view_tree_host_; | |
61 | |
62 using Entry = std::pair<uint32_t, Accelerator>; | |
63 std::map<uint32_t, Accelerator> accelerators_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | |
66 }; | |
67 | |
68 } // namespace view_manager | |
69 | |
70 #endif // COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ | |
OLD | NEW |