OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/event.h" | 5 #include "ui/base/events/event.h" |
6 | 6 |
7 #if defined(USE_X11) | 7 #if defined(USE_X11) |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <cmath> | 11 #include <cmath> |
12 #include <cstring> | 12 #include <cstring> |
13 | 13 |
| 14 #include "base/command_line.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/string_number_conversions.h" |
| 17 #include "base/string_util.h" |
15 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
16 #include "ui/base/events/event_utils.h" | 19 #include "ui/base/events/event_utils.h" |
17 #include "ui/base/keycodes/keyboard_code_conversion.h" | 20 #include "ui/base/keycodes/keyboard_code_conversion.h" |
| 21 #include "ui/base/ui_base_switches.h" |
18 #include "ui/gfx/point3_f.h" | 22 #include "ui/gfx/point3_f.h" |
19 #include "ui/gfx/point_conversions.h" | 23 #include "ui/gfx/point_conversions.h" |
20 #include "ui/gfx/transform.h" | 24 #include "ui/gfx/transform.h" |
21 #include "ui/gfx/transform_util.h" | 25 #include "ui/gfx/transform_util.h" |
22 | 26 |
23 #if defined(USE_X11) | 27 #if defined(USE_X11) |
24 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 28 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
25 #endif | 29 #endif |
26 | 30 |
27 namespace { | 31 namespace { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 411 |
408 #if defined(OS_WIN) | 412 #if defined(OS_WIN) |
409 // This value matches windows WHEEL_DELTA. | 413 // This value matches windows WHEEL_DELTA. |
410 // static | 414 // static |
411 const int MouseWheelEvent::kWheelDelta = 120; | 415 const int MouseWheelEvent::kWheelDelta = 120; |
412 #else | 416 #else |
413 // This value matches GTK+ wheel scroll amount. | 417 // This value matches GTK+ wheel scroll amount. |
414 const int MouseWheelEvent::kWheelDelta = 53; | 418 const int MouseWheelEvent::kWheelDelta = 53; |
415 #endif | 419 #endif |
416 | 420 |
| 421 #if defined(USE_XI2_MT) |
| 422 //////////////////////////////////////////////////////////////////////////////// |
| 423 // TouchCoordinatesCalibrator |
| 424 |
| 425 TouchCoordinatesCalibrator::TouchCoordinatesCalibrator() |
| 426 : left_(0), |
| 427 right_(0), |
| 428 top_(0), |
| 429 bottom_(0) { |
| 430 std::vector<std::string> parts; |
| 431 if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 432 switches::kTouchCalibration), ",", &parts) >= 4) { |
| 433 if (!base::StringToInt(parts[0], &left_)) |
| 434 DLOG(ERROR) << "Incorrect left border calibration value passed."; |
| 435 if (!base::StringToInt(parts[1], &right_)) |
| 436 DLOG(ERROR) << "Incorrect right border calibration value passed."; |
| 437 if (!base::StringToInt(parts[2], &top_)) |
| 438 DLOG(ERROR) << "Incorrect top border calibration value passed."; |
| 439 if (!base::StringToInt(parts[3], &bottom_)) |
| 440 DLOG(ERROR) << "Incorrect bottom border calibration value passed."; |
| 441 } |
| 442 } |
| 443 |
| 444 TouchCoordinatesCalibrator* TouchCoordinatesCalibrator::GetInstance() { |
| 445 return Singleton<TouchCoordinatesCalibrator>::get(); |
| 446 } |
| 447 |
| 448 void TouchCoordinatesCalibrator::Calibrate(TouchEvent* event, |
| 449 const gfx::Rect& bounds) { |
| 450 int x = event->x(); |
| 451 int y = event->y(); |
| 452 |
| 453 if (!left_ && !right_ && !top_ && !bottom_) |
| 454 return; |
| 455 |
| 456 const int resolution_x = bounds.width(); |
| 457 const int resolution_y = bounds.height(); |
| 458 // The "grace area" (10% in this case) is to make it easier for the user to |
| 459 // navigate to the corner. |
| 460 const double kGraceAreaFraction = 0.1; |
| 461 if (left_ || right_) { |
| 462 // Offset the x position to the real |
| 463 x -= left_; |
| 464 // Check if we are in the grace area of the left side. |
| 465 // Note: We might not want to do this when the gesture is locked? |
| 466 if (x < 0 && x > -left_ * kGraceAreaFraction) |
| 467 x = 0; |
| 468 // Check if we are in the grace area of the right side. |
| 469 // Note: We might not want to do this when the gesture is locked? |
| 470 if (x > resolution_x - left_ && |
| 471 x < resolution_x - left_ + right_ * kGraceAreaFraction) |
| 472 x = resolution_x - left_; |
| 473 // Scale the screen area back to the full resolution of the screen. |
| 474 x = (x * resolution_x) / (resolution_x - (right_ + left_)); |
| 475 } |
| 476 if (top_ || bottom_) { |
| 477 // When there is a top bezel we add our border, |
| 478 y -= top_; |
| 479 |
| 480 // Check if we are in the grace area of the top side. |
| 481 // Note: We might not want to do this when the gesture is locked? |
| 482 if (y < 0 && y > -top_ * kGraceAreaFraction) |
| 483 y = 0; |
| 484 |
| 485 // Check if we are in the grace area of the bottom side. |
| 486 // Note: We might not want to do this when the gesture is locked? |
| 487 if (y > resolution_y - top_ && |
| 488 y < resolution_y - top_ + bottom_ * kGraceAreaFraction) |
| 489 y = resolution_y - top_; |
| 490 // Scale the screen area back to the full resolution of the screen. |
| 491 y = (y * resolution_y) / (resolution_y - (bottom_ + top_)); |
| 492 } |
| 493 |
| 494 // Set the modified coordinate back to the event. |
| 495 if (event->root_location() == event->location()) { |
| 496 // Usually those will be equal, |
| 497 // if not, I am not sure what the correct value should be. |
| 498 event->set_root_location(gfx::Point(x, y)); |
| 499 } |
| 500 event->set_location(gfx::Point(x, y)); |
| 501 } |
| 502 #endif // defined(USE_XI2_MT) |
| 503 |
417 //////////////////////////////////////////////////////////////////////////////// | 504 //////////////////////////////////////////////////////////////////////////////// |
418 // TouchEvent | 505 // TouchEvent |
419 | 506 |
420 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 507 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
421 : LocatedEvent(native_event), | 508 : LocatedEvent(native_event), |
422 touch_id_(GetTouchId(native_event)), | 509 touch_id_(GetTouchId(native_event)), |
423 radius_x_(GetTouchRadiusX(native_event)), | 510 radius_x_(GetTouchRadiusX(native_event)), |
424 radius_y_(GetTouchRadiusY(native_event)), | 511 radius_y_(GetTouchRadiusY(native_event)), |
425 rotation_angle_(GetTouchAngle(native_event)), | 512 rotation_angle_(GetTouchAngle(native_event)), |
426 force_(GetTouchForce(native_event)) { | 513 force_(GetTouchForce(native_event)) { |
(...skipping 29 matching lines...) Expand all Loading... |
456 } | 543 } |
457 | 544 |
458 TouchEvent::~TouchEvent() { | 545 TouchEvent::~TouchEvent() { |
459 } | 546 } |
460 | 547 |
461 void TouchEvent::Relocate(const gfx::Point& origin) { | 548 void TouchEvent::Relocate(const gfx::Point& origin) { |
462 location_ -= origin.OffsetFromOrigin(); | 549 location_ -= origin.OffsetFromOrigin(); |
463 root_location_ -= origin.OffsetFromOrigin(); | 550 root_location_ -= origin.OffsetFromOrigin(); |
464 } | 551 } |
465 | 552 |
| 553 #if defined(USE_XI2_MT) |
| 554 void TouchEvent::Calibrate(const gfx::Rect& bounds) { |
| 555 TouchCoordinatesCalibrator::GetInstance()->Calibrate(this, bounds); |
| 556 } |
| 557 #endif // defined(USE_XI2_MT) |
| 558 |
466 void TouchEvent::UpdateForRootTransform(const gfx::Transform& root_transform) { | 559 void TouchEvent::UpdateForRootTransform(const gfx::Transform& root_transform) { |
467 LocatedEvent::UpdateForRootTransform(root_transform); | 560 LocatedEvent::UpdateForRootTransform(root_transform); |
468 gfx::DecomposedTransform decomp; | 561 gfx::DecomposedTransform decomp; |
469 bool success = gfx::DecomposeTransform(&decomp, root_transform); | 562 bool success = gfx::DecomposeTransform(&decomp, root_transform); |
470 DCHECK(success); | 563 DCHECK(success); |
471 if (decomp.scale[0]) | 564 if (decomp.scale[0]) |
472 radius_x_ /= decomp.scale[0]; | 565 radius_x_ /= decomp.scale[0]; |
473 if (decomp.scale[1]) | 566 if (decomp.scale[1]) |
474 radius_y_ /= decomp.scale[1]; | 567 radius_y_ /= decomp.scale[1]; |
475 } | 568 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 int GestureEvent::GetLowestTouchId() const { | 820 int GestureEvent::GetLowestTouchId() const { |
728 if (touch_ids_bitfield_ == 0) | 821 if (touch_ids_bitfield_ == 0) |
729 return -1; | 822 return -1; |
730 int i = -1; | 823 int i = -1; |
731 // Find the index of the least significant 1 bit | 824 // Find the index of the least significant 1 bit |
732 while (!(1 << ++i & touch_ids_bitfield_)); | 825 while (!(1 << ++i & touch_ids_bitfield_)); |
733 return i; | 826 return i; |
734 } | 827 } |
735 | 828 |
736 } // namespace ui | 829 } // namespace ui |
OLD | NEW |