OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ | 5 #ifndef COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ |
6 #define COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ | 6 #define COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "ui/mojo/events/input_event_constants.mojom.h" | 11 #include "components/view_manager/public/interfaces/native_viewport.mojom.h" |
12 #include "ui/mojo/events/input_events.mojom.h" | |
13 #include "ui/mojo/events/input_key_codes.mojom.h" | |
14 | 12 |
15 namespace view_manager { | 13 namespace view_manager { |
16 | 14 |
17 class ConnectionManager; | 15 class ConnectionManager; |
18 | 16 |
19 // Handles dispatching events to the right location as well as updating focus. | 17 // Handles dispatching events to the right location as well as updating focus. |
20 class EventDispatcher { | 18 class EventDispatcher : public mojo::NativeViewportEventDispatcher { |
21 public: | 19 public: |
22 explicit EventDispatcher(ConnectionManager* connection_manager); | 20 explicit EventDispatcher(ConnectionManager* connection_manager); |
23 ~EventDispatcher(); | 21 ~EventDispatcher() override; |
24 | 22 |
25 void AddAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags); | 23 void AddAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags); |
26 void RemoveAccelerator(mojo::KeyboardCode keyboard_code, | 24 void RemoveAccelerator(mojo::KeyboardCode keyboard_code, |
27 mojo::EventFlags flags); | 25 mojo::EventFlags flags); |
28 | 26 |
29 void OnEvent(mojo::EventPtr event); | 27 // NativeViewportEventDispatcher: |
| 28 void OnEvent(mojo::EventPtr event, const OnEventCallback& callback) override; |
30 | 29 |
31 private: | 30 private: |
32 struct Accelerator { | 31 struct Accelerator { |
33 Accelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags) | 32 Accelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags) |
34 : keyboard_code(keyboard_code), flags(flags) {} | 33 : keyboard_code(keyboard_code), flags(flags) {} |
35 | 34 |
36 // So we can use this in a set. | 35 // So we can use this in a set. |
37 bool operator<(const Accelerator& other) const { | 36 bool operator<(const Accelerator& other) const { |
38 if (keyboard_code == other.keyboard_code) | 37 if (keyboard_code == other.keyboard_code) |
39 return flags < other.flags; | 38 return flags < other.flags; |
40 return keyboard_code < other.keyboard_code; | 39 return keyboard_code < other.keyboard_code; |
41 } | 40 } |
42 | 41 |
43 mojo::KeyboardCode keyboard_code; | 42 mojo::KeyboardCode keyboard_code; |
44 mojo::EventFlags flags; | 43 mojo::EventFlags flags; |
45 }; | 44 }; |
46 | 45 |
47 ConnectionManager* connection_manager_; | 46 ConnectionManager* connection_manager_; |
48 | 47 |
49 std::set<Accelerator> accelerators_; | 48 std::set<Accelerator> accelerators_; |
50 | 49 |
51 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 50 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
52 }; | 51 }; |
53 | 52 |
54 } // namespace view_manager | 53 } // namespace view_manager |
55 | 54 |
56 #endif // COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ | 55 #endif // COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ |
OLD | NEW |