OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/aura/dispatcher_linux.h" | 5 #include "ui/aura/dispatcher_linux.h" |
6 | 6 |
7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
8 | 8 |
9 #include "ui/base/events.h" | 9 #include "ui/base/events.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 namespace aura { | 38 namespace aura { |
39 | 39 |
40 DispatcherLinux::DispatcherLinux() { | 40 DispatcherLinux::DispatcherLinux() { |
41 base::MessagePumpX::SetDefaultDispatcher(this); | 41 base::MessagePumpX::SetDefaultDispatcher(this); |
| 42 MessageLoopForUI::current()->AddObserver(this); |
42 } | 43 } |
43 | 44 |
44 DispatcherLinux::~DispatcherLinux() { | 45 DispatcherLinux::~DispatcherLinux() { |
| 46 MessageLoopForUI::current()->RemoveObserver(this); |
45 base::MessagePumpX::SetDefaultDispatcher(NULL); | 47 base::MessagePumpX::SetDefaultDispatcher(NULL); |
46 } | 48 } |
47 | 49 |
48 void DispatcherLinux::WindowDispatcherCreated( | 50 void DispatcherLinux::WindowDispatcherCreated( |
49 ::Window window, | 51 ::Window window, |
50 MessageLoop::Dispatcher* dispatcher) { | 52 MessageLoop::Dispatcher* dispatcher) { |
51 dispatchers_.insert(std::make_pair(window, dispatcher)); | 53 dispatchers_.insert(std::make_pair(window, dispatcher)); |
52 } | 54 } |
53 | 55 |
54 void DispatcherLinux::WindowDispatcherDestroying(::Window window) { | 56 void DispatcherLinux::WindowDispatcherDestroying(::Window window) { |
55 dispatchers_.erase(window); | 57 dispatchers_.erase(window); |
56 } | 58 } |
57 | 59 |
58 bool DispatcherLinux::Dispatch(const base::NativeEvent& xev) { | 60 bool DispatcherLinux::Dispatch(const base::NativeEvent& xev) { |
59 PreprocessXEvent(xev); | |
60 | |
61 // XI_HierarchyChanged events are special. There is no window associated with | 61 // XI_HierarchyChanged events are special. There is no window associated with |
62 // these events. So process them directly from here. | 62 // these events. So process them directly from here. |
63 if (xev->type == GenericEvent && | 63 if (xev->type == GenericEvent && |
64 xev->xgeneric.evtype == XI_HierarchyChanged) { | 64 xev->xgeneric.evtype == XI_HierarchyChanged) { |
65 ui::UpdateDeviceList(); | 65 ui::UpdateDeviceList(); |
66 return true; | 66 return true; |
67 } | 67 } |
68 | 68 |
69 // MappingNotify events (meaning that the keyboard or pointer buttons have | 69 // MappingNotify events (meaning that the keyboard or pointer buttons have |
70 // been remapped) aren't associated with a window; send them to all | 70 // been remapped) aren't associated with a window; send them to all |
71 // dispatchers. | 71 // dispatchers. |
72 if (xev->type == MappingNotify) { | 72 if (xev->type == MappingNotify) { |
73 for (DispatchersMap::const_iterator it = dispatchers_.begin(); | 73 for (DispatchersMap::const_iterator it = dispatchers_.begin(); |
74 it != dispatchers_.end(); ++it) { | 74 it != dispatchers_.end(); ++it) { |
75 it->second->Dispatch(xev); | 75 it->second->Dispatch(xev); |
76 } | 76 } |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev); | 80 MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev); |
81 return dispatcher ? dispatcher->Dispatch(xev) : true; | 81 return dispatcher ? dispatcher->Dispatch(xev) : true; |
82 } | 82 } |
83 | 83 |
| 84 base::EventStatus DispatcherLinux::WillProcessEvent( |
| 85 const base::NativeEvent& event) { |
| 86 PreprocessXEvent(event); |
| 87 return base::EVENT_CONTINUE; |
| 88 } |
| 89 |
| 90 void DispatcherLinux::DidProcessEvent(const base::NativeEvent& event) { |
| 91 } |
| 92 |
84 MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent( | 93 MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent( |
85 XEvent* xev) const { | 94 XEvent* xev) const { |
86 ::Window window = xev->xany.window; | 95 ::Window window = xev->xany.window; |
87 if (xev->type == GenericEvent) { | 96 if (xev->type == GenericEvent) { |
88 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 97 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
89 window = xievent->event; | 98 window = xievent->event; |
90 } | 99 } |
91 DispatchersMap::const_iterator it = dispatchers_.find(window); | 100 DispatchersMap::const_iterator it = dispatchers_.find(window); |
92 return it != dispatchers_.end() ? it->second : NULL; | 101 return it != dispatchers_.end() ? it->second : NULL; |
93 } | 102 } |
94 | 103 |
95 MessageLoop::Dispatcher* CreateDispatcher() { | 104 MessageLoop::Dispatcher* CreateDispatcher() { |
96 return new DispatcherLinux; | 105 return new DispatcherLinux; |
97 } | 106 } |
98 | 107 |
99 } // namespace aura | 108 } // namespace aura |
OLD | NEW |