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

Side by Side Diff: ui/base/x/events_x.cc

Issue 8416056: Added support for chromeos usb mice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | « no previous file | no next file » | 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 "ui/base/events.h" 5 #include "ui/base/events.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 10 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 EventType EventTypeFromNative(const base::NativeEvent& native_event) { 141 EventType EventTypeFromNative(const base::NativeEvent& native_event) {
142 switch (native_event->type) { 142 switch (native_event->type) {
143 case KeyPress: 143 case KeyPress:
144 return ET_KEY_PRESSED; 144 return ET_KEY_PRESSED;
145 case KeyRelease: 145 case KeyRelease:
146 return ET_KEY_RELEASED; 146 return ET_KEY_RELEASED;
147 case ButtonPress: 147 case ButtonPress:
148 if (native_event->xbutton.button == 4 || 148 if (native_event->xbutton.button == 4 ||
149 native_event->xbutton.button == 5) 149 native_event->xbutton.button == 5)
150 return ET_MOUSEWHEEL; 150 return ET_MOUSEWHEEL;
151 #if defined (OS_CHROMEOS)
152 if (native_event->xbutton.button == 8 ||
153 native_event->xbutton.button == 9)
154 return ET_MOUSEWHEEL;
155 #endif
151 return ET_MOUSE_PRESSED; 156 return ET_MOUSE_PRESSED;
152 case ButtonRelease: 157 case ButtonRelease:
153 if (native_event->xbutton.button == 4 || 158 if (native_event->xbutton.button == 4 ||
154 native_event->xbutton.button == 5) 159 native_event->xbutton.button == 5)
155 return ET_MOUSEWHEEL; 160 return ET_MOUSEWHEEL;
161 #if defined (OS_CHROMEOS)
162 if (native_event->xbutton.button == 8 ||
163 native_event->xbutton.button == 9)
164 return ET_MOUSEWHEEL;
165 #endif
156 return ET_MOUSE_RELEASED; 166 return ET_MOUSE_RELEASED;
157 case MotionNotify: 167 case MotionNotify:
158 if (native_event->xmotion.state & 168 if (native_event->xmotion.state &
159 (Button1Mask | Button2Mask | Button3Mask)) 169 (Button1Mask | Button2Mask | Button3Mask))
160 return ET_MOUSE_DRAGGED; 170 return ET_MOUSE_DRAGGED;
161 return ET_MOUSE_MOVED; 171 return ET_MOUSE_MOVED;
162 case EnterNotify: 172 case EnterNotify:
163 return ET_MOUSE_ENTERED; 173 return ET_MOUSE_ENTERED;
164 case LeaveNotify: 174 case LeaveNotify:
165 return ET_MOUSE_EXITED; 175 return ET_MOUSE_EXITED;
166 case GenericEvent: { 176 case GenericEvent: {
167 XIDeviceEvent* xievent = 177 XIDeviceEvent* xievent =
168 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 178 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
169 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) 179 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid))
170 return GetTouchEventType(native_event); 180 return GetTouchEventType(native_event);
171 switch (xievent->evtype) { 181 switch (xievent->evtype) {
172 case XI_ButtonPress: 182 case XI_ButtonPress:
183 #if defined (OS_CHROMEOS)
184 if (xievent->detail == 8 || xievent->detail == 9)
185 return ET_MOUSEWHEEL;
186 #endif
173 return (xievent->detail == 4 || xievent->detail == 5) ? 187 return (xievent->detail == 4 || xievent->detail == 5) ?
174 ET_MOUSEWHEEL : ET_MOUSE_PRESSED; 188 ET_MOUSEWHEEL : ET_MOUSE_PRESSED;
175 case XI_ButtonRelease: 189 case XI_ButtonRelease:
190 #if defined (OS_CHROMEOS)
191 if (xievent->detail == 8 || xievent->detail == 9)
192 return ET_MOUSEWHEEL;
193 #endif
176 return (xievent->detail == 4 || xievent->detail == 5) ? 194 return (xievent->detail == 4 || xievent->detail == 5) ?
177 ET_MOUSEWHEEL : ET_MOUSE_RELEASED; 195 ET_MOUSEWHEEL : ET_MOUSE_RELEASED;
178 case XI_Motion: 196 case XI_Motion:
179 return GetButtonMaskForX2Event(xievent) ? 197 return GetButtonMaskForX2Event(xievent) ?
180 ET_MOUSE_DRAGGED : ET_MOUSE_MOVED; 198 ET_MOUSE_DRAGGED : ET_MOUSE_MOVED;
181 } 199 }
182 } 200 }
183 default: 201 default:
184 break; 202 break;
185 } 203 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 XIDeviceEvent* xievent = 265 XIDeviceEvent* xievent =
248 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 266 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
249 return xievent->evtype == XI_ButtonPress || 267 return xievent->evtype == XI_ButtonPress ||
250 xievent->evtype == XI_ButtonRelease || 268 xievent->evtype == XI_ButtonRelease ||
251 xievent->evtype == XI_Motion; 269 xievent->evtype == XI_Motion;
252 } 270 }
253 return false; 271 return false;
254 } 272 }
255 273
256 int GetMouseWheelOffset(const base::NativeEvent& native_event) { 274 int GetMouseWheelOffset(const base::NativeEvent& native_event) {
275 int button;
257 if (native_event->type == GenericEvent) { 276 if (native_event->type == GenericEvent) {
258 XIDeviceEvent* xiev = 277 XIDeviceEvent* xiev =
259 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 278 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
260 return xiev->detail == 4 ? kWheelScrollAmount : -kWheelScrollAmount; 279 button = xiev->detail;
280 } else {
281 button = native_event->xbutton.button;
261 } 282 }
262 return native_event->xbutton.button == 4 ? 283 #if defined(OS_CHROMEOS)
263 kWheelScrollAmount : -kWheelScrollAmount; 284 if (button == 8)
285 return kWheelScrollAmount;
286 else if (button == 9)
287 return -kWheelScrollAmount;
288 #endif
289 return button == 4 ? kWheelScrollAmount : -kWheelScrollAmount;
264 } 290 }
265 291
266 int GetTouchId(const base::NativeEvent& xev) { 292 int GetTouchId(const base::NativeEvent& xev) {
267 float slot = 0; 293 float slot = 0;
268 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 294 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
269 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); 295 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
270 if (!factory->IsRealTouchDevice(xievent->sourceid)) { 296 if (!factory->IsRealTouchDevice(xievent->sourceid)) {
271 // TODO(sad): Come up with a way to generate touch-ids for multi-touch 297 // TODO(sad): Come up with a way to generate touch-ids for multi-touch
272 // events when touch-events are generated from a mouse. 298 // events when touch-events are generated from a mouse.
273 return slot; 299 return slot;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 unsigned int deviceid = 336 unsigned int deviceid =
311 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid; 337 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid;
312 // Force is normalized to fall into [0, 1] 338 // Force is normalized to fall into [0, 1]
313 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam( 339 if (!ui::TouchFactory::GetInstance()->NormalizeTouchParam(
314 deviceid, ui::TouchFactory::TP_PRESSURE, &force)) 340 deviceid, ui::TouchFactory::TP_PRESSURE, &force))
315 force = 0.0; 341 force = 0.0;
316 return force; 342 return force;
317 } 343 }
318 344
319 } // namespace ui 345 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698