Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: views/focus/accelerator_handler_touch.cc

Issue 6975045: touch: Always expect XInput2 availability. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/focus/accelerator_handler.h ('k') | views/touchui/touch_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/focus/accelerator_handler.h" 5 #include "views/focus/accelerator_handler.h"
6 6
7 #include <bitset> 7 #include <bitset>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #if defined(HAVE_XINPUT2)
10 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
11 #else
12 #include <X11/Xlib.h>
13 #endif
14 10
15 #include "views/accelerator.h" 11 #include "views/accelerator.h"
16 #include "views/events/event.h" 12 #include "views/events/event.h"
17 #include "views/focus/focus_manager.h" 13 #include "views/focus/focus_manager.h"
18 #include "views/ime/input_method.h" 14 #include "views/ime/input_method.h"
19 #include "views/touchui/touch_factory.h" 15 #include "views/touchui/touch_factory.h"
20 #include "views/view.h" 16 #include "views/view.h"
21 #include "views/widget/native_widget.h" 17 #include "views/widget/native_widget.h"
22 18
23 namespace views { 19 namespace views {
(...skipping 12 matching lines...) Expand all
36 32
37 if (!widget) { 33 if (!widget) {
38 DLOG(WARNING) << "no NativeWidgetGtk found for that GtkWidget"; 34 DLOG(WARNING) << "no NativeWidgetGtk found for that GtkWidget";
39 return NULL; 35 return NULL;
40 } 36 }
41 return widget; 37 return widget;
42 } 38 }
43 39
44 } // namespace 40 } // namespace
45 41
46 #if defined(HAVE_XINPUT2)
47 bool DispatchX2Event(Widget* widget, XEvent* xev) { 42 bool DispatchX2Event(Widget* widget, XEvent* xev) {
48 XGenericEventCookie* cookie = &xev->xcookie; 43 XGenericEventCookie* cookie = &xev->xcookie;
49 switch (cookie->evtype) { 44 switch (cookie->evtype) {
50 case XI_KeyPress: 45 case XI_KeyPress:
51 case XI_KeyRelease: { 46 case XI_KeyRelease: {
52 // TODO(sad): We don't capture XInput2 events from keyboard yet. 47 // TODO(sad): We don't capture XInput2 events from keyboard yet.
53 break; 48 break;
54 } 49 }
55 case XI_ButtonPress: 50 case XI_ButtonPress:
56 case XI_ButtonRelease: 51 case XI_ButtonRelease:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 mouseev.IsOnlyRightMouseButton()); 94 mouseev.IsOnlyRightMouseButton());
100 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); 95 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer);
101 96
102 return widget->OnMouseEvent(mouseev); 97 return widget->OnMouseEvent(mouseev);
103 } 98 }
104 } 99 }
105 } 100 }
106 return false; 101 return false;
107 } 102 }
108 103
109 #endif // HAVE_XINPUT2
110
111 bool DispatchXEvent(XEvent* xev) { 104 bool DispatchXEvent(XEvent* xev) {
112 GdkDisplay* gdisp = gdk_display_get_default(); 105 GdkDisplay* gdisp = gdk_display_get_default();
113 XID xwindow = xev->xany.window; 106 XID xwindow = xev->xany.window;
114 107
115 #if defined(HAVE_XINPUT2)
116 if (xev->type == GenericEvent) { 108 if (xev->type == GenericEvent) {
117 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) 109 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev))
118 return true; // Consume the event. 110 return true; // Consume the event.
119 111
120 XGenericEventCookie* cookie = &xev->xcookie; 112 XGenericEventCookie* cookie = &xev->xcookie;
121 if (cookie->evtype == XI_HierarchyChanged) { 113 if (cookie->evtype == XI_HierarchyChanged) {
122 TouchFactory::GetInstance()->UpdateDeviceList(cookie->display); 114 TouchFactory::GetInstance()->UpdateDeviceList(cookie->display);
123 return true; 115 return true;
124 } 116 }
125 117
126 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); 118 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data);
127 xwindow = xiev->event; 119 xwindow = xiev->event;
128 } 120 }
129 #endif
130 121
131 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); 122 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow);
132 Widget* widget = FindWidgetForGdkWindow(gwind); 123 Widget* widget = FindWidgetForGdkWindow(gwind);
133 if (widget) { 124 if (widget) {
134 Event::FromNativeEvent2 from_native; 125 Event::FromNativeEvent2 from_native;
135 switch (xev->type) { 126 switch (xev->type) {
136 case KeyPress: 127 case KeyPress:
137 case KeyRelease: { 128 case KeyRelease: {
138 KeyEvent keyev(xev, from_native); 129 KeyEvent keyev(xev, from_native);
139 InputMethod* ime = widget->GetInputMethod(); 130 InputMethod* ime = widget->GetInputMethod();
(...skipping 11 matching lines...) Expand all
151 // Scrolling the wheel triggers button press/release events. 142 // Scrolling the wheel triggers button press/release events.
152 MouseWheelEvent wheelev(xev, from_native); 143 MouseWheelEvent wheelev(xev, from_native);
153 return widget->OnMouseEvent(wheelev); 144 return widget->OnMouseEvent(wheelev);
154 } 145 }
155 // fallthrough 146 // fallthrough
156 case MotionNotify: { 147 case MotionNotify: {
157 MouseEvent mouseev(xev, from_native); 148 MouseEvent mouseev(xev, from_native);
158 return widget->OnMouseEvent(mouseev); 149 return widget->OnMouseEvent(mouseev);
159 } 150 }
160 151
161 #if defined(HAVE_XINPUT2)
162 case GenericEvent: { 152 case GenericEvent: {
163 return DispatchX2Event(widget, xev); 153 return DispatchX2Event(widget, xev);
164 } 154 }
165 #endif
166 } 155 }
167 } 156 }
168 157
169 return false; 158 return false;
170 } 159 }
171 160
172 #if defined(HAVE_XINPUT2)
173 void SetTouchDeviceList(std::vector<unsigned int>& devices) { 161 void SetTouchDeviceList(std::vector<unsigned int>& devices) {
174 TouchFactory::GetInstance()->SetTouchDeviceList(devices); 162 TouchFactory::GetInstance()->SetTouchDeviceList(devices);
175 } 163 }
176 #endif
177 164
178 AcceleratorHandler::AcceleratorHandler() {} 165 AcceleratorHandler::AcceleratorHandler() {}
179 166
180 #if defined(TOUCH_UI)
181 base::MessagePumpDispatcher::DispatchStatus 167 base::MessagePumpDispatcher::DispatchStatus
182 AcceleratorHandler::Dispatch(XEvent* xev) { 168 AcceleratorHandler::Dispatch(XEvent* xev) {
183 return DispatchXEvent(xev) ? 169 return DispatchXEvent(xev) ?
184 base::MessagePumpDispatcher::EVENT_PROCESSED : 170 base::MessagePumpDispatcher::EVENT_PROCESSED :
185 base::MessagePumpDispatcher::EVENT_IGNORED; 171 base::MessagePumpDispatcher::EVENT_IGNORED;
186 } 172 }
187 #else
188 bool AcceleratorHandler::Dispatch(GdkEvent* event) {
189 gtk_main_do_event(event);
190 return true;
191 }
192 #endif
193 173
194 } // namespace views 174 } // namespace views
OLDNEW
« no previous file with comments | « views/focus/accelerator_handler.h ('k') | views/touchui/touch_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698