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_split.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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 403 |
400 #if defined(OS_WIN) | 404 #if defined(OS_WIN) |
401 // This value matches windows WHEEL_DELTA. | 405 // This value matches windows WHEEL_DELTA. |
402 // static | 406 // static |
403 const int MouseWheelEvent::kWheelDelta = 120; | 407 const int MouseWheelEvent::kWheelDelta = 120; |
404 #else | 408 #else |
405 // This value matches GTK+ wheel scroll amount. | 409 // This value matches GTK+ wheel scroll amount. |
406 const int MouseWheelEvent::kWheelDelta = 53; | 410 const int MouseWheelEvent::kWheelDelta = 53; |
407 #endif | 411 #endif |
408 | 412 |
| 413 #if defined(USE_XI2_MT) |
| 414 //////////////////////////////////////////////////////////////////////////////// |
| 415 // TouchCoordinatesCalibrator |
| 416 |
| 417 TouchCoordinatesCalibrator::TouchCoordinatesCalibrator() |
| 418 : left_border_touch_calibration(0), |
| 419 right_border_touch_calibration(0), |
| 420 top_border_touch_calibration(0), |
| 421 bottom_border_touch_calibration(0) { |
| 422 std::vector<std::string> parts; |
| 423 base::SplitString(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 424 switches::kTouchCalibration), ',', &parts); |
| 425 if (parts.size() >= 4) { |
| 426 if (!base::StringToInt(parts[0], &left_border_touch_calibration)) |
| 427 DLOG(ERROR) << "Incorrect left border calibration value passed."; |
| 428 if (!base::StringToInt(parts[1], &right_border_touch_calibration)) |
| 429 DLOG(ERROR) << "Incorrect right border calibration value passed."; |
| 430 if (!base::StringToInt(parts[2], &top_border_touch_calibration)) |
| 431 DLOG(ERROR) << "Incorrect top border calibration value passed."; |
| 432 if (!base::StringToInt(parts[3], &bottom_border_touch_calibration)) |
| 433 DLOG(ERROR) << "Incorrect bottom border calibration value passed."; |
| 434 } |
| 435 } |
| 436 |
| 437 TouchCoordinatesCalibrator* TouchCoordinatesCalibrator::GetInstance() { |
| 438 return Singleton<TouchCoordinatesCalibrator>::get(); |
| 439 } |
| 440 |
| 441 void TouchCoordinatesCalibrator::Calibrate(TouchEvent& event, |
| 442 const gfx::Rect& bounds) { |
| 443 int x = event.x(); |
| 444 int y = event.y(); |
| 445 |
| 446 if (!left_border_touch_calibration && !right_border_touch_calibration && |
| 447 !top_border_touch_calibration && !bottom_border_touch_calibration) |
| 448 return; |
| 449 |
| 450 const int resolution_x = bounds.width(); |
| 451 const int resolution_y = bounds.height(); |
| 452 // The "grace area" (10% in this case) is to make it easier for the user to |
| 453 // navigate to the corner. |
| 454 const double kGraceAreaFraction = 0.1; |
| 455 if (left_border_touch_calibration || right_border_touch_calibration) { |
| 456 // Offset the x position to the real |
| 457 x -= left_border_touch_calibration; |
| 458 // Check if we are in the grace area of the left side. |
| 459 // Note: We might not want to do this when the gesture is locked? |
| 460 if (x < 0 && x > -left_border_touch_calibration * kGraceAreaFraction) |
| 461 x = 0; |
| 462 // Check if we are in the grace area of the right side. |
| 463 // Note: We might not want to do this when the gesture is locked? |
| 464 if (x > resolution_x - left_border_touch_calibration && |
| 465 x < resolution_x - left_border_touch_calibration + |
| 466 right_border_touch_calibration * kGraceAreaFraction) |
| 467 x = resolution_x - left_border_touch_calibration; |
| 468 // Scale the screen area back to the full resolution of the screen. |
| 469 x = (x * resolution_x) / (resolution_x - (right_border_touch_calibration + |
| 470 left_border_touch_calibration)); |
| 471 } |
| 472 if (top_border_touch_calibration || bottom_border_touch_calibration) { |
| 473 // When there is a top bezel we add our border, |
| 474 y -= top_border_touch_calibration; |
| 475 |
| 476 // Check if we are in the grace area of the top side. |
| 477 // Note: We might not want to do this when the gesture is locked? |
| 478 if (y < 0 && y > -top_border_touch_calibration * kGraceAreaFraction) |
| 479 y = 0; |
| 480 |
| 481 // Check if we are in the grace area of the bottom side. |
| 482 // Note: We might not want to do this when the gesture is locked? |
| 483 if (y > resolution_y - top_border_touch_calibration && |
| 484 y < resolution_y - top_border_touch_calibration + |
| 485 bottom_border_touch_calibration * kGraceAreaFraction) |
| 486 y = resolution_y - top_border_touch_calibration; |
| 487 // Scale the screen area back to the full resolution of the screen. |
| 488 y = (y * resolution_y) / (resolution_y - (bottom_border_touch_calibration + |
| 489 top_border_touch_calibration)); |
| 490 } |
| 491 // Set the modified coordinate back to the event. |
| 492 if (event.root_location() == event.location()) |
| 493 event.set_root_location(gfx::Point(x, y)); |
| 494 event.set_location(gfx::Point(x, y)); |
| 495 } |
| 496 #endif |
| 497 |
409 //////////////////////////////////////////////////////////////////////////////// | 498 //////////////////////////////////////////////////////////////////////////////// |
410 // TouchEvent | 499 // TouchEvent |
411 | 500 |
412 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 501 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
413 : LocatedEvent(native_event), | 502 : LocatedEvent(native_event), |
414 touch_id_(GetTouchId(native_event)), | 503 touch_id_(GetTouchId(native_event)), |
415 radius_x_(GetTouchRadiusX(native_event)), | 504 radius_x_(GetTouchRadiusX(native_event)), |
416 radius_y_(GetTouchRadiusY(native_event)), | 505 radius_y_(GetTouchRadiusY(native_event)), |
417 rotation_angle_(GetTouchAngle(native_event)), | 506 rotation_angle_(GetTouchAngle(native_event)), |
418 force_(GetTouchForce(native_event)) { | 507 force_(GetTouchForce(native_event)) { |
(...skipping 29 matching lines...) Expand all Loading... |
448 } | 537 } |
449 | 538 |
450 TouchEvent::~TouchEvent() { | 539 TouchEvent::~TouchEvent() { |
451 } | 540 } |
452 | 541 |
453 void TouchEvent::Relocate(const gfx::Point& origin) { | 542 void TouchEvent::Relocate(const gfx::Point& origin) { |
454 location_ -= origin.OffsetFromOrigin(); | 543 location_ -= origin.OffsetFromOrigin(); |
455 root_location_ -= origin.OffsetFromOrigin(); | 544 root_location_ -= origin.OffsetFromOrigin(); |
456 } | 545 } |
457 | 546 |
| 547 #if defined(USE_XI2_MT) |
| 548 void TouchEvent::Calibrate(const gfx::Rect& bounds) { |
| 549 TouchCoordinatesCalibrator::GetInstance()->Calibrate(*this, bounds); |
| 550 } |
| 551 #endif |
| 552 |
458 void TouchEvent::UpdateForRootTransform(const gfx::Transform& root_transform) { | 553 void TouchEvent::UpdateForRootTransform(const gfx::Transform& root_transform) { |
459 LocatedEvent::UpdateForRootTransform(root_transform); | 554 LocatedEvent::UpdateForRootTransform(root_transform); |
460 gfx::DecomposedTransform decomp; | 555 gfx::DecomposedTransform decomp; |
461 bool success = gfx::DecomposeTransform(&decomp, root_transform); | 556 bool success = gfx::DecomposeTransform(&decomp, root_transform); |
462 DCHECK(success); | 557 DCHECK(success); |
463 if (decomp.scale[0]) | 558 if (decomp.scale[0]) |
464 radius_x_ /= decomp.scale[0]; | 559 radius_x_ /= decomp.scale[0]; |
465 if (decomp.scale[1]) | 560 if (decomp.scale[1]) |
466 radius_y_ /= decomp.scale[1]; | 561 radius_y_ /= decomp.scale[1]; |
467 } | 562 } |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 int GestureEvent::GetLowestTouchId() const { | 778 int GestureEvent::GetLowestTouchId() const { |
684 if (touch_ids_bitfield_ == 0) | 779 if (touch_ids_bitfield_ == 0) |
685 return -1; | 780 return -1; |
686 int i = -1; | 781 int i = -1; |
687 // Find the index of the least significant 1 bit | 782 // Find the index of the least significant 1 bit |
688 while (!(1 << ++i & touch_ids_bitfield_)); | 783 while (!(1 << ++i & touch_ids_bitfield_)); |
689 return i; | 784 return i; |
690 } | 785 } |
691 | 786 |
692 } // namespace ui | 787 } // namespace ui |
OLD | NEW |