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

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

Issue 7129008: Update rich touch information to conform to standard (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: addressing sky's comments Created 9 years, 6 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/events/event.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 #if defined(HAVE_XINPUT2) 9 #if defined(HAVE_XINPUT2)
10 #include <X11/extensions/XInput2.h> 10 #include <X11/extensions/XInput2.h>
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) { 238 uint16 GetCharacterFromXKeyEvent(XKeyEvent* key) {
239 char buf[6]; 239 char buf[6];
240 int bytes_written = XLookupString(key, buf, 6, NULL, NULL); 240 int bytes_written = XLookupString(key, buf, 6, NULL, NULL);
241 DCHECK_LE(bytes_written, 6); 241 DCHECK_LE(bytes_written, 6);
242 242
243 string16 result; 243 string16 result;
244 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && 244 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) &&
245 result.length() == 1) ? result[0] : 0; 245 result.length() == 1) ? result[0] : 0;
246 } 246 }
247 247
248 float GetTouchRadiusFromXEvent(XEvent* xev) { 248 float GetTouchParamFromXEvent(XEvent* xev,
249 float diameter = 0.0; 249 TouchFactory::TouchParam tp,
250 250 float default_value) {
251 #if defined(HAVE_XINPUT2) 251 #if defined(HAVE_XINPUT2)
252 TouchFactory* touch_factory = TouchFactory::GetInstance(); 252 TouchFactory::GetInstance()->ExtractTouchParam(*xev, tp, &default_value);
253 touch_factory->ExtractTouchParam(*xev, TouchFactory::TP_TOUCH_MAJOR,
254 &diameter);
255 #endif 253 #endif
256 254 return default_value;
257 return diameter / 2.0;
258 }
259
260 float GetTouchAngleFromXEvent(XEvent* xev) {
261 float angle = 0.0;
262
263 #if defined(HAVE_XINPUT2)
264 TouchFactory* touch_factory = TouchFactory::GetInstance();
265 touch_factory->ExtractTouchParam(*xev, TouchFactory::TP_ORIENTATION,
266 &angle);
267 #endif
268
269 return angle;
270 }
271
272
273 float GetTouchRatioFromXEvent(XEvent* xev) {
274 float ratio = 1.0;
275
276 #if defined(HAVE_XINPUT2)
277 TouchFactory* touch_factory = TouchFactory::GetInstance();
278 float major_v = -1.0;
279 float minor_v = -1.0;
280
281 if (!touch_factory->ExtractTouchParam(*xev,
282 TouchFactory::TP_TOUCH_MAJOR,
283 &major_v) ||
284 !touch_factory->ExtractTouchParam(*xev,
285 TouchFactory::TP_TOUCH_MINOR,
286 &minor_v))
287 return ratio;
288
289 // In case minor axis exists but is zero.
290 if (minor_v > 0.0)
291 ratio = major_v / minor_v;
292 #endif
293
294 return ratio;
295 } 255 }
296 256
297 } // namespace 257 } // namespace
298 258
299 //////////////////////////////////////////////////////////////////////////////// 259 ////////////////////////////////////////////////////////////////////////////////
300 // Event, private: 260 // Event, private:
301 261
302 void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, 262 void Event::InitWithNativeEvent2(NativeEvent2 native_event_2,
303 FromNativeEvent2) { 263 FromNativeEvent2) {
304 native_event_ = NULL; 264 native_event_ = NULL;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 374 }
415 375
416 //////////////////////////////////////////////////////////////////////////////// 376 ////////////////////////////////////////////////////////////////////////////////
417 // TouchEvent, public: 377 // TouchEvent, public:
418 378
419 #if defined(HAVE_XINPUT2) 379 #if defined(HAVE_XINPUT2)
420 TouchEvent::TouchEvent(NativeEvent2 native_event_2, 380 TouchEvent::TouchEvent(NativeEvent2 native_event_2,
421 FromNativeEvent2 from_native) 381 FromNativeEvent2 from_native)
422 : LocatedEvent(native_event_2, from_native), 382 : LocatedEvent(native_event_2, from_native),
423 touch_id_(GetTouchIDFromXEvent(native_event_2)), 383 touch_id_(GetTouchIDFromXEvent(native_event_2)),
424 radius_(GetTouchRadiusFromXEvent(native_event_2)), 384 radius_x_(GetTouchParamFromXEvent(native_event_2,
425 angle_(GetTouchAngleFromXEvent(native_event_2)), 385 TouchFactory::TP_TOUCH_MAJOR,
426 ratio_(GetTouchRatioFromXEvent(native_event_2)) { 386 2.0) / 2.0),
387 radius_y_(GetTouchParamFromXEvent(native_event_2,
388 TouchFactory::TP_TOUCH_MINOR,
389 2.0) / 2.0),
390 angle_(GetTouchParamFromXEvent(native_event_2,
391 TouchFactory::TP_ORIENTATION,
392 0.0)) {
427 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { 393 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) {
428 TouchFactory* factory = TouchFactory::GetInstance(); 394 TouchFactory* factory = TouchFactory::GetInstance();
429 float slot; 395 float slot;
430 if (factory->ExtractTouchParam(*native_event_2, 396 if (factory->ExtractTouchParam(*native_event_2,
431 TouchFactory::TP_SLOT_ID, &slot)) { 397 TouchFactory::TP_SLOT_ID, &slot)) {
432 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); 398 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED);
433 } 399 }
434 } 400 }
435 } 401 }
436 #endif 402 #endif
437 403
438 } // namespace views 404 } // namespace views
OLDNEW
« no previous file with comments | « views/events/event.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698