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

Side by Side Diff: views/events/event_x.cc

Issue 8070003: touchui: Convert XI2 MT tracking id to slot id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 2 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 | « ui/base/touch/touch_factory.cc ('k') | 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 "views/events/event.h" 5 #include "views/events/event.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 14 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
15 #include "ui/base/touch/touch_factory.h" 15 #include "ui/base/touch/touch_factory.h"
16 #include "views/widget/root_view.h" 16 #include "views/widget/root_view.h"
17 17
18 namespace views { 18 namespace views {
19 19
20 namespace { 20 namespace {
21 21
22 int GetTouchIDFromXEvent(XEvent* xev) { 22 int GetTouchIDFromXEvent(XEvent* xev) {
23 float id = 0; 23 float slot = 0;
24 #if defined(USE_XI2_MT)
25 // TODO(ningxin.hu@gmail.com): Make the id always start from 0 for a new
26 // touch-sequence when TRACKING_ID is used to extract the touch id.
27 ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_TRACKING_ID;
28 #else
29 ui::TouchFactory::TouchParam tp = ui::TouchFactory::TP_SLOT_ID;
30 #endif
31 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 24 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
32 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); 25 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
33 if (factory->IsRealTouchDevice(xievent->sourceid) && 26 if (!factory->IsRealTouchDevice(xievent->sourceid)) {
34 !factory->ExtractTouchParam(*xev, tp, &id)) 27 // TODO(sad): Come up with a way to generate touch-ids for multi-touch
35 LOG(ERROR) << "Could not get the touch ID for the event. Using 0."; 28 // events when touch-events are generated from a mouse.
36 return id; 29 return slot;
30 }
31
32 #if defined(USE_XI2_MT)
33 float tracking_id;
34 if (!factory->ExtractTouchParam(
35 *xev, ui::TouchFactory::TP_TRACKING_ID, &tracking_id))
36 LOG(ERROR) << "Could not get the slot ID for the event. Using 0.";
37 else
38 slot = factory->GetSlotForTrackingID(tracking_id);
39 #else
40 if (!factory->ExtractTouchParam(
41 *xev, ui::TouchFactory::TP_SLOT_ID, &slot))
42 LOG(ERROR) << "Could not get the slot ID for the event. Using 0.";
43 #endif
44 return slot;
37 } 45 }
38 46
39 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { 47 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) {
40 char buf[6]; 48 char buf[6];
41 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); 49 int bytes_written = XLookupString(key, buf, 6, NULL, NULL);
42 DCHECK_LE(bytes_written, 6); 50 DCHECK_LE(bytes_written, 6);
43 51
44 string16 result; 52 string16 result;
45 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && 53 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) &&
46 result.length() == 1) ? result[0] : 0; 54 result.length() == 1) ? result[0] : 0;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 radius_x_(GetTouchParamFromXEvent(native_event, 175 radius_x_(GetTouchParamFromXEvent(native_event,
168 ui::TouchFactory::TP_TOUCH_MAJOR, 176 ui::TouchFactory::TP_TOUCH_MAJOR,
169 2.0) / 2.0), 177 2.0) / 2.0),
170 radius_y_(GetTouchParamFromXEvent(native_event, 178 radius_y_(GetTouchParamFromXEvent(native_event,
171 ui::TouchFactory::TP_TOUCH_MINOR, 179 ui::TouchFactory::TP_TOUCH_MINOR,
172 2.0) / 2.0), 180 2.0) / 2.0),
173 rotation_angle_(GetTouchParamFromXEvent(native_event, 181 rotation_angle_(GetTouchParamFromXEvent(native_event,
174 ui::TouchFactory::TP_ORIENTATION, 182 ui::TouchFactory::TP_ORIENTATION,
175 0.0)), 183 0.0)),
176 force_(GetTouchForceFromXEvent(native_event)) { 184 force_(GetTouchForceFromXEvent(native_event)) {
177 #if !defined(USE_XI2_MT) 185 #if defined(USE_XI2_MT)
186 if (type() == ui::ET_TOUCH_RELEASED) {
187 // NOTE: The slot is allocated by TouchFactory for each XI_TouchBegin
188 // event, which carries a new tracking ID to identify a new touch
189 // sequence.
190 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
191 float tracking_id;
192 if (factory->ExtractTouchParam(*native_event,
193 ui::TouchFactory::TP_TRACKING_ID,
194 &tracking_id)) {
195 factory->ReleaseSlotForTrackingID(tracking_id);
196 }
197 }
198 #else
178 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { 199 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) {
179 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 200 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
180 float slot; 201 float slot;
181 if (factory->ExtractTouchParam(*native_event, 202 if (factory->ExtractTouchParam(*native_event,
182 ui::TouchFactory::TP_SLOT_ID, &slot)) { 203 ui::TouchFactory::TP_SLOT_ID, &slot)) {
183 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); 204 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED);
184 } 205 }
185 } 206 }
186 #endif 207 #endif
187 } 208 }
188 209
189 } // namespace views 210 } // namespace views
OLDNEW
« no previous file with comments | « ui/base/touch/touch_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698