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

Unified Diff: ui/ozone/platform/egltest/ozone_platform_egltest.cc

Issue 746653002: [Ozone-Egltest] Scale touch events from device size to window size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/egltest/ozone_platform_egltest.cc
diff --git a/ui/ozone/platform/egltest/ozone_platform_egltest.cc b/ui/ozone/platform/egltest/ozone_platform_egltest.cc
index 08aa8ab75b7ffe7794fc88cdc31623fec9773d4a..51939eec5398b5f2e71f2d7cc6c9d381de31e956 100644
--- a/ui/ozone/platform/egltest/ozone_platform_egltest.cc
+++ b/ui/ozone/platform/egltest/ozone_platform_egltest.cc
@@ -11,6 +11,8 @@
#include "base/path_service.h"
#include "library_loaders/libeglplatform_shim.h"
#include "third_party/khronos/EGL/egl.h"
+#include "ui/events/devices/device_data_manager.h"
+#include "ui/events/event.h"
#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/events_ozone.h"
@@ -45,6 +47,27 @@ std::string GetShimLibraryName() {
return kEglplatformShimDefault;
}
+// Touch events are reported in device coordinates. This scales the event to the
+// window's coordinate space.
+void ScaleTouchEvent(TouchEvent* event, const gfx::SizeF& size) {
+ for (const auto& device :
+ DeviceDataManager::GetInstance()->touchscreen_devices()) {
+ if (device.id == static_cast<unsigned int>(event->source_device_id())) {
+ gfx::SizeF touchscreen_size = device.size;
+ gfx::PointF location = event->location_f();
+
+ location.Scale(size.width() / touchscreen_size.width(),
+ size.height() / touchscreen_size.height());
+ double ratio = std::sqrt(size.GetArea() / touchscreen_size.GetArea());
+
+ event->set_location(location);
+ event->set_radius_x(event->radius_x() * ratio);
+ event->set_radius_y(event->radius_y() * ratio);
+ return;
+ }
+ }
+}
+
class EgltestWindow : public PlatformWindow, public PlatformEventDispatcher {
public:
EgltestWindow(PlatformWindowDelegate* delegate,
@@ -150,6 +173,11 @@ bool EgltestWindow::CanDispatchEvent(const ui::PlatformEvent& ne) {
}
uint32_t EgltestWindow::DispatchEvent(const ui::PlatformEvent& native_event) {
+ DCHECK(native_event);
+ Event* event = static_cast<Event*>(native_event);
+ if (event->IsTouchEvent())
+ ScaleTouchEvent(static_cast<TouchEvent*>(event), bounds_.size());
+
DispatchEventFromNativeUiEvent(
native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent,
base::Unretained(delegate_)));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698