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

Side by Side Diff: ui/base/events/event.cc

Issue 12087124: Disable touch calibration on external touchscreen. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review + Rebase on top of 12321086 Created 7 years, 9 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
OLDNEW
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"
15 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "base/strings/string_split.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
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 base::SplitString(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
432 switches::kTouchCalibration), ',', &parts);
oshima 2013/03/14 01:23:27 please sync. This function is replaced by Tokenize
ynovikov 2013/03/14 20:27:04 Done.
433 if (parts.size() >= 4) {
434 if (!base::StringToInt(parts[0], &left_))
435 DLOG(ERROR) << "Incorrect left border calibration value passed.";
436 if (!base::StringToInt(parts[1], &right_))
437 DLOG(ERROR) << "Incorrect right border calibration value passed.";
438 if (!base::StringToInt(parts[2], &top_))
439 DLOG(ERROR) << "Incorrect top border calibration value passed.";
440 if (!base::StringToInt(parts[3], &bottom_))
441 DLOG(ERROR) << "Incorrect bottom border calibration value passed.";
sadrul 2013/03/14 00:20:13 Should you check for valid (non-negative) values f
ynovikov 2013/03/14 20:27:04 Done. I don't think negative values are invalid. I
442 }
443 }
444
445 TouchCoordinatesCalibrator* TouchCoordinatesCalibrator::GetInstance() {
446 return Singleton<TouchCoordinatesCalibrator>::get();
447 }
448
449 void TouchCoordinatesCalibrator::Calibrate(TouchEvent* event,
450 const gfx::Rect& bounds) {
451 int x = event->x();
452 int y = event->y();
453
454 if (!left_ && !right_ && !top_ && !bottom_)
455 return;
456
457 const int resolution_x = bounds.width();
458 const int resolution_y = bounds.height();
459 // The "grace area" (10% in this case) is to make it easier for the user to
460 // navigate to the corner.
461 const double kGraceAreaFraction = 0.1;
462 if (left_ || right_) {
463 // Offset the x position to the real
464 x -= left_;
465 // Check if we are in the grace area of the left side.
466 // Note: We might not want to do this when the gesture is locked?
467 if (x < 0 && x > -left_ * kGraceAreaFraction)
468 x = 0;
469 // Check if we are in the grace area of the right side.
470 // Note: We might not want to do this when the gesture is locked?
471 if (x > resolution_x - left_ &&
472 x < resolution_x - left_ + right_ * kGraceAreaFraction)
473 x = resolution_x - left_;
474 // Scale the screen area back to the full resolution of the screen.
475 x = (x * resolution_x) / (resolution_x - (right_ + left_));
476 }
477 if (top_ || bottom_) {
478 // When there is a top bezel we add our border,
479 y -= top_;
480
481 // Check if we are in the grace area of the top side.
482 // Note: We might not want to do this when the gesture is locked?
483 if (y < 0 && y > -top_ * kGraceAreaFraction)
484 y = 0;
485
486 // Check if we are in the grace area of the bottom side.
487 // Note: We might not want to do this when the gesture is locked?
488 if (y > resolution_y - top_ &&
489 y < resolution_y - top_ + bottom_ * kGraceAreaFraction)
490 y = resolution_y - top_;
491 // Scale the screen area back to the full resolution of the screen.
492 y = (y * resolution_y) / (resolution_y - (bottom_ + top_));
493 }
494
495 // Set the modified coordinate back to the event.
496 if (event->root_location() == event->location())
497 // Usually those will be equal,
498 // if not, I am not sure what the correct value should be.
499 event->set_root_location(gfx::Point(x, y));
sadrul 2013/03/14 00:20:13 Use braces
ynovikov 2013/03/14 20:27:04 Done.
500 event->set_location(gfx::Point(x, y));
501 }
502 #endif
sadrul 2013/03/14 00:20:13 #endif // defined(USE_XI2_MT)
ynovikov 2013/03/14 20:27:04 Done.
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
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
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
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
OLDNEW
« ui/base/events/event.h ('K') | « ui/base/events/event.h ('k') | ui/base/x/events_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698