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 "components/view_manager/public/interfaces/native_viewport.mojom.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" |
12 | 14 |
13 namespace view_manager { | 15 namespace view_manager { |
14 | 16 |
15 class ConnectionManager; | 17 class ConnectionManager; |
16 | 18 |
17 // Handles dispatching events to the right location as well as updating focus. | 19 // Handles dispatching events to the right location as well as updating focus. |
18 class EventDispatcher : public mojo::NativeViewportEventDispatcher { | 20 class EventDispatcher { |
19 public: | 21 public: |
20 explicit EventDispatcher(ConnectionManager* connection_manager); | 22 explicit EventDispatcher(ConnectionManager* connection_manager); |
21 ~EventDispatcher() override; | 23 ~EventDispatcher(); |
22 | 24 |
23 void AddAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags); | 25 void AddAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags); |
24 void RemoveAccelerator(mojo::KeyboardCode keyboard_code, | 26 void RemoveAccelerator(mojo::KeyboardCode keyboard_code, |
25 mojo::EventFlags flags); | 27 mojo::EventFlags flags); |
26 | 28 |
27 // NativeViewportEventDispatcher: | 29 void OnEvent(mojo::EventPtr event, |
28 void OnEvent(mojo::EventPtr event, const OnEventCallback& callback) override; | 30 const mojo::Callback<void()>& callback); |
29 | 31 |
30 private: | 32 private: |
31 struct Accelerator { | 33 struct Accelerator { |
32 Accelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags) | 34 Accelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags) |
33 : keyboard_code(keyboard_code), flags(flags) {} | 35 : keyboard_code(keyboard_code), flags(flags) {} |
34 | 36 |
35 // So we can use this in a set. | 37 // So we can use this in a set. |
36 bool operator<(const Accelerator& other) const { | 38 bool operator<(const Accelerator& other) const { |
37 if (keyboard_code == other.keyboard_code) | 39 if (keyboard_code == other.keyboard_code) |
38 return flags < other.flags; | 40 return flags < other.flags; |
39 return keyboard_code < other.keyboard_code; | 41 return keyboard_code < other.keyboard_code; |
40 } | 42 } |
41 | 43 |
42 mojo::KeyboardCode keyboard_code; | 44 mojo::KeyboardCode keyboard_code; |
43 mojo::EventFlags flags; | 45 mojo::EventFlags flags; |
44 }; | 46 }; |
45 | 47 |
46 ConnectionManager* connection_manager_; | 48 ConnectionManager* connection_manager_; |
47 | 49 |
48 std::set<Accelerator> accelerators_; | 50 std::set<Accelerator> accelerators_; |
49 | 51 |
50 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 52 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
51 }; | 53 }; |
52 | 54 |
53 } // namespace view_manager | 55 } // namespace view_manager |
54 | 56 |
55 #endif // COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ | 57 #endif // COMPONENTS_VIEW_MANAGER_EVENT_DISPATCHER_H_ |
OLD | NEW |