diff options
author | dnicoara <dnicoara@chromium.org> | 2014-11-17 12:46:18 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-17 20:47:02 +0000 |
commit | ddf9b877f69a4437d58e30292f160e9bd7d7995c (patch) | |
tree | 25efc304605eaa8a4287ee86d7792078e5a1bab2 /ui/events | |
parent | 74bccf2326dd04f3c5e0745f2fefa46dc21a5b85 (diff) | |
download | chromium_src-ddf9b877f69a4437d58e30292f160e9bd7d7995c.zip chromium_src-ddf9b877f69a4437d58e30292f160e9bd7d7995c.tar.gz chromium_src-ddf9b877f69a4437d58e30292f160e9bd7d7995c.tar.bz2 |
[Ozone] Keep track of window -> displays mapping
This allows us to figure out which window a touch event needs to be
reported to and allows the event dispatcher to properly report the touch
events in the window's coordinate system.
BUG=425258
NOTRY=true
Review URL: https://codereview.chromium.org/698373003
Cr-Commit-Position: refs/heads/master@{#304472}
Diffstat (limited to 'ui/events')
4 files changed, 35 insertions, 81 deletions
diff --git a/ui/events/ozone/evdev/event_factory_evdev.cc b/ui/events/ozone/evdev/event_factory_evdev.cc index 483319a..d32aedf 100644 --- a/ui/events/ozone/evdev/event_factory_evdev.cc +++ b/ui/events/ozone/evdev/event_factory_evdev.cc @@ -90,9 +90,12 @@ scoped_ptr<EventConverterEvdev> CreateConverter( #endif // Touchscreen: use TouchEventConverterEvdev. - if (devinfo.HasMTAbsXY()) - return make_scoped_ptr<EventConverterEvdev>(new TouchEventConverterEvdev( - fd, params.path, params.id, devinfo, params.dispatch_callback)); + if (devinfo.HasMTAbsXY()) { + scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( + fd, params.path, params.id, params.dispatch_callback)); + converter->Initialize(devinfo); + return converter.Pass(); + } // Everything else: use EventConverterEvdevImpl. return make_scoped_ptr<EventConverterEvdevImpl>( @@ -302,7 +305,7 @@ void EventFactoryEvdev::NotifyHotplugEventObserver( for (auto it = converters_.begin(); it != converters_.end(); ++it) { if (it->second->HasTouchscreen()) { InputDeviceType device_type = InputDeviceType::INPUT_DEVICE_EXTERNAL; - if (converter.IsInternal()) + if (it->second->IsInternal()) device_type = InputDeviceType::INPUT_DEVICE_INTERNAL; touchscreens.push_back( diff --git a/ui/events/ozone/evdev/touch_event_converter_evdev.cc b/ui/events/ozone/evdev/touch_event_converter_evdev.cc index a0de30d..baa2ccc 100644 --- a/ui/events/ozone/evdev/touch_event_converter_evdev.cc +++ b/ui/events/ozone/evdev/touch_event_converter_evdev.cc @@ -27,7 +27,6 @@ #include "ui/events/event.h" #include "ui/events/event_constants.h" #include "ui/events/event_switches.h" -#include "ui/gfx/screen.h" namespace { @@ -55,20 +54,6 @@ void GetTouchCalibration(TouchCalibration* cal) { } } -float TuxelsToPixels(float val, - float min_tuxels, - float num_tuxels, - float min_pixels, - float num_pixels) { - // Map [min_tuxels, min_tuxels + num_tuxels) to - // [min_pixels, min_pixels + num_pixels). - return min_pixels + (val - min_tuxels) * num_pixels / num_tuxels; -} - -float TuxelToPixelSize(float val, float num_tuxels, float num_pixels) { - return val * num_pixels / num_tuxels; -} - } // namespace namespace ui { @@ -88,7 +73,6 @@ TouchEventConverterEvdev::TouchEventConverterEvdev( int fd, base::FilePath path, int id, - const EventDeviceInfo& info, const EventDispatchCallback& callback) : EventConverterEvdev(fd, path, id), callback_(callback), @@ -96,7 +80,6 @@ TouchEventConverterEvdev::TouchEventConverterEvdev( is_type_a_(false), current_slot_(0), is_internal_(IsTouchscreenInternal(path)) { - Init(info); } TouchEventConverterEvdev::~TouchEventConverterEvdev() { @@ -104,44 +87,30 @@ TouchEventConverterEvdev::~TouchEventConverterEvdev() { close(fd_); } -void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) { - gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); - if (!screen) - return; // No scaling. - gfx::Display display = screen->GetPrimaryDisplay(); - gfx::Size size = display.GetSizeInPixel(); - +void TouchEventConverterEvdev::Initialize(const EventDeviceInfo& info) { pressure_min_ = info.GetAbsMinimum(ABS_MT_PRESSURE); pressure_max_ = info.GetAbsMaximum(ABS_MT_PRESSURE); x_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_X); x_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_X) - x_min_tuxels_ + 1; y_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_Y); y_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1; - native_size_ = gfx::Size(x_num_tuxels_, y_num_tuxels_); - - // Map coordinates onto screen. - x_min_pixels_ = 0; - y_min_pixels_ = 0; - x_num_pixels_ = size.width(); - y_num_pixels_ = size.height(); - - VLOG(1) << "mapping touch coordinates to screen coordinates: " - << base::StringPrintf("%dx%d", size.width(), size.height()); // Apply --touch-calibration. - TouchCalibration cal = {}; - GetTouchCalibration(&cal); - x_min_tuxels_ += cal.bezel_left; - x_num_tuxels_ -= cal.bezel_left + cal.bezel_right; - y_min_tuxels_ += cal.bezel_top; - y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom; + if (is_internal_) { + TouchCalibration cal = {}; + GetTouchCalibration(&cal); + x_min_tuxels_ += cal.bezel_left; + x_num_tuxels_ -= cal.bezel_left + cal.bezel_right; + y_min_tuxels_ += cal.bezel_top; + y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom; + + VLOG(1) << "applying touch calibration: " + << base::StringPrintf("[%d, %d, %d, %d]", cal.bezel_left, + cal.bezel_right, cal.bezel_top, + cal.bezel_bottom); + } - VLOG(1) << "applying touch calibration: " - << base::StringPrintf("[%d, %d, %d, %d]", - cal.bezel_left, - cal.bezel_right, - cal.bezel_top, - cal.bezel_bottom); + native_size_ = gfx::Size(x_num_tuxels_, y_num_tuxels_); for (int i = 0; i < std::min<int>(info.GetAbsMaximum(ABS_MT_SLOT) + 1, MAX_FINGERS); @@ -160,7 +129,7 @@ void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) { bool TouchEventConverterEvdev::Reinitialize() { EventDeviceInfo info; if (info.Initialize(fd_)) { - Init(info); + Initialize(info); return true; } return false; @@ -225,29 +194,19 @@ void TouchEventConverterEvdev::ProcessAbs(const input_event& input) { // TODO(spang): If we have all of major, minor, and orientation, // we can scale the ellipse correctly. However on the Pixel we get // neither minor nor orientation, so this is all we can do. - events_[current_slot_].radius_x_ = - TuxelToPixelSize(input.value, x_num_tuxels_, x_num_pixels_) / 2.0f; + events_[current_slot_].radius_x_ = input.value / 2.0f; break; case ABS_MT_TOUCH_MINOR: altered_slots_.set(current_slot_); - events_[current_slot_].radius_y_ = - TuxelToPixelSize(input.value, y_num_tuxels_, y_num_pixels_) / 2.0f; + events_[current_slot_].radius_y_ = input.value / 2.0f; break; case ABS_MT_POSITION_X: altered_slots_.set(current_slot_); - events_[current_slot_].x_ = TuxelsToPixels(input.value, - x_min_tuxels_, - x_num_tuxels_, - x_min_pixels_, - x_num_pixels_); + events_[current_slot_].x_ = input.value; break; case ABS_MT_POSITION_Y: altered_slots_.set(current_slot_); - events_[current_slot_].y_ = TuxelsToPixels(input.value, - y_min_tuxels_, - y_num_tuxels_, - y_min_pixels_, - y_num_pixels_); + events_[current_slot_].y_ = input.value; break; case ABS_MT_TRACKING_ID: altered_slots_.set(current_slot_); diff --git a/ui/events/ozone/evdev/touch_event_converter_evdev.h b/ui/events/ozone/evdev/touch_event_converter_evdev.h index 6b18ce0..bbeb46a 100644 --- a/ui/events/ozone/evdev/touch_event_converter_evdev.h +++ b/ui/events/ozone/evdev/touch_event_converter_evdev.h @@ -28,7 +28,6 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev TouchEventConverterEvdev(int fd, base::FilePath path, int id, - const EventDeviceInfo& info, const EventDispatchCallback& dispatch); ~TouchEventConverterEvdev() override; @@ -37,11 +36,12 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev gfx::Size GetTouchscreenSize() const override; bool IsInternal() const override; + // Unsafe part of initialization. + virtual void Initialize(const EventDeviceInfo& info); + private: friend class MockTouchEventConverterEvdev; - // Unsafe part of initialization. - void Init(const EventDeviceInfo& info); // Overidden from base::MessagePumpLibevent::Watcher. void OnFileCanReadWithoutBlocking(int fd) override; @@ -75,14 +75,6 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev float y_min_tuxels_; float y_num_tuxels_; - // Output range for x-axis. - float x_min_pixels_; - float x_num_pixels_; - - // Output range for y-axis. - float y_min_pixels_; - float y_num_pixels_; - // Size of the touchscreen as reported by the driver. gfx::Size native_size_; diff --git a/ui/events/ozone/evdev/touch_event_converter_evdev_unittest.cc b/ui/events/ozone/evdev/touch_event_converter_evdev_unittest.cc index 0c5d6d4..fe371d0 100644 --- a/ui/events/ozone/evdev/touch_event_converter_evdev_unittest.cc +++ b/ui/events/ozone/evdev/touch_event_converter_evdev_unittest.cc @@ -63,6 +63,7 @@ class MockTouchEventConverterEvdev : public TouchEventConverterEvdev { dispatched_events_.push_back(event.release()); } + void Initialize(const EventDeviceInfo& device_info) override {} bool Reinitialize() override { return true; } private: @@ -80,17 +81,16 @@ MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(int fd, fd, path, 1, - EventDeviceInfo(), base::Bind(&MockTouchEventConverterEvdev::DispatchCallback, base::Unretained(this))) { pressure_min_ = 30; pressure_max_ = 60; // TODO(rjkroege): Check test axes. - x_min_pixels_ = x_min_tuxels_ = 0; - x_num_pixels_ = x_num_tuxels_ = std::numeric_limits<int>::max(); - y_min_pixels_ = y_min_tuxels_ = 0; - y_num_pixels_ = y_num_tuxels_ = std::numeric_limits<int>::max(); + x_min_tuxels_ = 0; + x_num_tuxels_ = std::numeric_limits<int>::max(); + y_min_tuxels_ = 0; + y_num_tuxels_ = std::numeric_limits<int>::max(); int fds[2]; |