Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 GetTouchRadiusFromXEvent(XEvent* xev, TouchFactory::TouchParam tp) { |
| 249 float diameter = 0.0; | 249 float diameter = 2.0; |
| 250 | 250 |
| 251 #if defined(HAVE_XINPUT2) | 251 #if defined(HAVE_XINPUT2) |
| 252 TouchFactory* touch_factory = TouchFactory::GetInstance(); | 252 TouchFactory* touch_factory = TouchFactory::GetInstance(); |
| 253 touch_factory->ExtractTouchParam(*xev, TouchFactory::TP_TOUCH_MAJOR, | 253 touch_factory->ExtractTouchParam(*xev, tp, &diameter); |
| 254 &diameter); | |
| 255 #endif | 254 #endif |
|
sadrul
2011/06/08 17:30:14
Let's have:
float GetTouchParamFromXEvent(XEvent*
Yufeng Shen (Slow to review)
2011/06/08 19:39:24
Done.
| |
| 256 | 255 |
| 257 return diameter / 2.0; | 256 return diameter / 2.0; |
| 258 } | 257 } |
| 259 | 258 |
| 260 float GetTouchAngleFromXEvent(XEvent* xev) { | 259 float GetTouchAngleFromXEvent(XEvent* xev) { |
| 261 float angle = 0.0; | 260 float angle = 0.0; |
| 262 | 261 |
| 263 #if defined(HAVE_XINPUT2) | 262 #if defined(HAVE_XINPUT2) |
| 264 TouchFactory* touch_factory = TouchFactory::GetInstance(); | 263 TouchFactory* touch_factory = TouchFactory::GetInstance(); |
| 265 touch_factory->ExtractTouchParam(*xev, TouchFactory::TP_ORIENTATION, | 264 touch_factory->ExtractTouchParam(*xev, TouchFactory::TP_ORIENTATION, |
| 266 &angle); | 265 &angle); |
| 267 #endif | 266 #endif |
| 268 | 267 |
| 269 return angle; | 268 return angle; |
| 270 } | 269 } |
| 271 | 270 |
| 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 } | |
| 296 | |
| 297 } // namespace | 271 } // namespace |
| 298 | 272 |
| 299 //////////////////////////////////////////////////////////////////////////////// | 273 //////////////////////////////////////////////////////////////////////////////// |
| 300 // Event, private: | 274 // Event, private: |
| 301 | 275 |
| 302 void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, | 276 void Event::InitWithNativeEvent2(NativeEvent2 native_event_2, |
| 303 FromNativeEvent2) { | 277 FromNativeEvent2) { |
| 304 native_event_ = NULL; | 278 native_event_ = NULL; |
| 305 // TODO(beng): remove once we rid views of Gtk/Gdk. | 279 // TODO(beng): remove once we rid views of Gtk/Gdk. |
| 306 native_event_2_ = native_event_2; | 280 native_event_2_ = native_event_2; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 } | 388 } |
| 415 | 389 |
| 416 //////////////////////////////////////////////////////////////////////////////// | 390 //////////////////////////////////////////////////////////////////////////////// |
| 417 // TouchEvent, public: | 391 // TouchEvent, public: |
| 418 | 392 |
| 419 #if defined(HAVE_XINPUT2) | 393 #if defined(HAVE_XINPUT2) |
| 420 TouchEvent::TouchEvent(NativeEvent2 native_event_2, | 394 TouchEvent::TouchEvent(NativeEvent2 native_event_2, |
| 421 FromNativeEvent2 from_native) | 395 FromNativeEvent2 from_native) |
| 422 : LocatedEvent(native_event_2, from_native), | 396 : LocatedEvent(native_event_2, from_native), |
| 423 touch_id_(GetTouchIDFromXEvent(native_event_2)), | 397 touch_id_(GetTouchIDFromXEvent(native_event_2)), |
| 424 radius_(GetTouchRadiusFromXEvent(native_event_2)), | 398 radiusX_(GetTouchRadiusFromXEvent(native_event_2, |
| 425 angle_(GetTouchAngleFromXEvent(native_event_2)), | 399 TouchFactory::TP_TOUCH_MAJOR)), |
| 426 ratio_(GetTouchRatioFromXEvent(native_event_2)) { | 400 radiusY_(GetTouchRadiusFromXEvent(native_event_2, |
| 401 TouchFactory::TP_TOUCH_MINOR)), | |
| 402 angle_(GetTouchAngleFromXEvent(native_event_2)) { | |
| 427 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { | 403 if (type() == ui::ET_TOUCH_PRESSED || type() == ui::ET_TOUCH_RELEASED) { |
| 428 TouchFactory* factory = TouchFactory::GetInstance(); | 404 TouchFactory* factory = TouchFactory::GetInstance(); |
| 429 float slot; | 405 float slot; |
| 430 if (factory->ExtractTouchParam(*native_event_2, | 406 if (factory->ExtractTouchParam(*native_event_2, |
| 431 TouchFactory::TP_SLOT_ID, &slot)) { | 407 TouchFactory::TP_SLOT_ID, &slot)) { |
| 432 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); | 408 factory->SetSlotUsed(slot, type() == ui::ET_TOUCH_PRESSED); |
| 433 } | 409 } |
| 434 } | 410 } |
| 435 } | 411 } |
| 436 #endif | 412 #endif |
| 437 | 413 |
| 438 } // namespace views | 414 } // namespace views |
| OLD | NEW |