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_MUS_EVENT_DISPATCHER_H_ | |
6 #define COMPONENTS_MUS_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 gfx { | |
16 class Point; | |
17 } | |
18 | |
19 namespace mus { | |
20 | |
21 class ServerView; | |
22 class ViewTreeHostImpl; | |
23 | |
24 // Handles dispatching events to the right location as well as updating focus. | |
25 class EventDispatcher { | |
26 public: | |
27 explicit EventDispatcher(ViewTreeHostImpl* view_tree_host); | |
28 ~EventDispatcher(); | |
29 | |
30 void AddAccelerator(uint32_t id, | |
31 mojo::KeyboardCode keyboard_code, | |
32 mojo::EventFlags flags); | |
33 void RemoveAccelerator(uint32_t id); | |
34 | |
35 void OnEvent(mojo::EventPtr event); | |
36 | |
37 private: | |
38 struct Accelerator { | |
39 Accelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags) | |
40 : keyboard_code(keyboard_code), flags(flags) {} | |
41 | |
42 // So we can use this in a set. | |
43 bool operator<(const Accelerator& other) const { | |
44 if (keyboard_code == other.keyboard_code) | |
45 return flags < other.flags; | |
46 return keyboard_code < other.keyboard_code; | |
47 } | |
48 | |
49 mojo::KeyboardCode keyboard_code; | |
50 mojo::EventFlags flags; | |
51 }; | |
52 | |
53 // Looks to see if there is an accelerator bound to the specified code/flags. | |
54 // If there is one, sets |accelerator_id| to the id of the accelerator invoked | |
55 // and returns true. If there is none, returns false so normal key event | |
56 // processing can continue. | |
57 bool FindAccelerator(const mojo::Event& event, uint32_t* accelerator_id); | |
58 | |
59 // Returns the ServerView that should receive |event|. If |event| is a | |
60 // pointer-type event, then this function also updates the event location to | |
61 // make sure it is in the returned target's coordinate space. | |
62 ServerView* FindEventTarget(mojo::Event* event); | |
63 | |
64 // Finds the deepest visible view that contains the specified location, and | |
65 // updates |location| to be in the returned view's coordinate space. | |
66 ServerView* FindDeepestVisibleView(ServerView* view, gfx::Point* location); | |
67 | |
68 // Finds the deepest visible view for the specified location based on surface | |
69 // hit-testing. Updates |location| to be in the returned view's coordinate | |
70 // space. | |
71 ServerView* FindDeepestVisibleViewFromSurface(gfx::Point* location); | |
72 | |
73 ViewTreeHostImpl* view_tree_host_; | |
74 | |
75 using Entry = std::pair<uint32_t, Accelerator>; | |
76 std::map<uint32_t, Accelerator> accelerators_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | |
79 }; | |
80 | |
81 } // namespace mus | |
82 | |
83 #endif // COMPONENTS_MUS_EVENT_DISPATCHER_H_ | |
OLD | NEW |