Commit 7b5d30e9 authored by Riku Palomäki's avatar Riku Palomäki Committed by Marshall Greenblatt
Browse files

Add pen support for OSR (issue #1059)

parent 4cbcb461
......@@ -1715,6 +1715,17 @@ typedef enum {
CEF_TET_CANCELLED
} cef_touch_event_type_t;
///
// The device type that caused the event.
///
typedef enum {
CEF_POINTER_TYPE_TOUCH = 0,
CEF_POINTER_TYPE_MOUSE,
CEF_POINTER_TYPE_PEN,
CEF_POINTER_TYPE_ERASER,
CEF_POINTER_TYPE_UNKNOWN
} cef_pointer_type_t;
///
// Structure representing touch event information.
///
......@@ -1771,6 +1782,11 @@ typedef struct _cef_touch_event_t {
///
uint32 modifiers;
///
// The device type that caused the event.
///
cef_pointer_type_t pointer_type;
} cef_touch_event_t;
///
......
......@@ -10,6 +10,28 @@
#include "ui/events/base_event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
namespace {
ui::MotionEvent::ToolType CefPointerTypeToMotionEventToolType(
cef_pointer_type_t pointer_type) {
switch (pointer_type) {
case CEF_POINTER_TYPE_TOUCH:
return ui::MotionEvent::ToolType::FINGER;
case CEF_POINTER_TYPE_MOUSE:
return ui::MotionEvent::ToolType::MOUSE;
case CEF_POINTER_TYPE_PEN:
return ui::MotionEvent::ToolType::STYLUS;
case CEF_POINTER_TYPE_ERASER:
return ui::MotionEvent::ToolType::ERASER;
case CEF_POINTER_TYPE_UNKNOWN:
return ui::MotionEvent::ToolType::UNKNOWN;
}
NOTREACHED();
return ui::MotionEvent::ToolType::UNKNOWN;
}
} // namespace
CefMotionEventOSR::CefMotionEventOSR() {
std::fill(id_map_, id_map_ + blink::WebTouchEvent::kTouchesLengthCap, -1);
}
......@@ -205,14 +227,25 @@ ui::PointerProperties CefMotionEventOSR::GetPointerPropertiesFromTouchEvent(
pointer_properties.SetAxesAndOrientation(touch.radius_x, touch.radius_y,
touch.rotation_angle);
if (!pointer_properties.touch_major) {
pointer_properties.touch_major =
2.f * ui::GestureConfiguration::GetInstance()->default_radius();
pointer_properties.touch_minor =
2.f * ui::GestureConfiguration::GetInstance()->default_radius();
float default_size;
switch (touch.pointer_type) {
case CEF_POINTER_TYPE_PEN:
case CEF_POINTER_TYPE_ERASER:
// Default size for stylus events is 1x1.
default_size = 1;
break;
default:
default_size =
2.f * ui::GestureConfiguration::GetInstance()->default_radius();
break;
}
pointer_properties.touch_major = pointer_properties.touch_minor =
default_size;
pointer_properties.orientation = 0;
}
pointer_properties.tool_type = ui::MotionEvent::ToolType::FINGER;
pointer_properties.tool_type =
CefPointerTypeToMotionEventToolType(touch.pointer_type);
return pointer_properties;
}
......@@ -168,6 +168,8 @@ enum OSRTestType {
OSR_TEST_TOUCH_END,
// touchCancel is triggered on dismissing
OSR_TEST_TOUCH_CANCEL,
// CEF_POINTER_TYPE_PEN is mapped to pen pointer event
OSR_TEST_PEN,
// Define the range for popup tests.
OSR_TEST_POPUP_FIRST = OSR_TEST_POPUP_PAINT,
OSR_TEST_POPUP_LAST = OSR_TEST_POPUP_SCROLL_INSIDE,
......@@ -318,6 +320,28 @@ class OSRTestHandler : public RoutingTestHandler,
break;
}
} break;
case OSR_TEST_PEN: {
switch (touch_state_) {
case CEF_TET_CANCELLED:
// The first message expected is pointerdown.
EXPECT_STREQ(messageStr.c_str(), "osrpointerdown pen");
touch_state_ = CEF_TET_PRESSED;
break;
case CEF_TET_PRESSED:
EXPECT_STREQ(messageStr.c_str(), "osrpointermove pen");
touch_state_ = CEF_TET_MOVED;
break;
case CEF_TET_MOVED:
// There might be multiple pointermove events, ignore.
if (messageStr != "osrpointermove pen") {
EXPECT_STREQ(messageStr.c_str(), "osrpointerup pen");
DestroySucceededTestSoon();
}
break;
default:
break;
}
} break;
default:
// Intentionally left blank
break;
......@@ -1062,6 +1086,27 @@ class OSRTestHandler : public RoutingTestHandler,
browser->GetHost()->SendTouchEvent(touch_event2);
}
} break;
case OSR_TEST_PEN: {
if (StartTest()) {
const CefRect& pointerdiv = GetElementBounds("pointerdiv");
CefTouchEvent touch_event;
touch_event.x = MiddleX(pointerdiv) - 45;
touch_event.y = MiddleY(pointerdiv);
touch_event.type = CEF_TET_PRESSED;
touch_event.pointer_type = CEF_POINTER_TYPE_PEN;
browser->GetHost()->SendTouchEvent(touch_event);
touch_event.type = CEF_TET_MOVED;
for (size_t i = 0; i < 40; i++) {
touch_event.x++;
browser->GetHost()->SendTouchEvent(touch_event);
}
touch_event.type = CEF_TET_RELEASED;
browser->GetHost()->SendTouchEvent(touch_event);
}
} break;
default:
break;
}
......@@ -1552,3 +1597,4 @@ OSR_TEST(TouchEnd, OSR_TEST_TOUCH_END, 1.0f);
OSR_TEST(TouchEnd2X, OSR_TEST_TOUCH_END, 2.0f);
OSR_TEST(TouchCancel, OSR_TEST_TOUCH_CANCEL, 1.0f);
OSR_TEST(TouchCancel2X, OSR_TEST_TOUCH_CANCEL, 2.0f);
OSR_TEST(PenEvent, OSR_TEST_PEN, 1.0f);
......@@ -25,7 +25,7 @@
left: 7px;
opacity: 0.4;
}
#touchdiv {
#touchdiv, #pointerdiv {
width: 100px;
height: 50px;
background-color: red;
......@@ -61,6 +61,7 @@
elems.push(getElementBounds('dropdiv'));
elems.push(getElementBounds('dragdiv'));
elems.push(getElementBounds('touchdiv'));
elems.push(getElementBounds('pointerdiv'));
if (window.testQuery)
window.testQuery({request: JSON.stringify(param)});
......@@ -138,6 +139,12 @@
window.testQuery({request: param});
}
function onPointerEvent(ev) {
var param = 'osr' + ev.type + ' ' + ev.pointerType;
if (window.testQuery)
window.testQuery({request: param});
}
</script>
<body onfocus='onEventTest(event)' onblur='onEventTest(event)' onload='load();'>
<h1 id='LI00' onclick="onEventTest(event)">
......@@ -178,6 +185,8 @@
</div>
<div id="touchdiv" ontouchstart="onTouchEvent(event)" ontouchend="onTouchEvent(event)" ontouchmove="onTouchEvent(event)" ontouchcancel="onTouchEvent(event)">
</div>
<div id="pointerdiv" onpointerdown="onPointerEvent(event)" onpointerup="onPointerEvent(event)" onpointermove="onPointerEvent(event)" onpointercancel="onPointerEvent(event)">
</div>
<br />
<br />
<br />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment