Commit a2a91a99 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Allow another touch start happen when there are active touch points

Now when there are active touch points and we dispatch a touch start, an
error "Must have no prior active touch points to start a new touch." will
throw out. We should allow this case happens:
Input.dispatchEvent({
    type: 'touchStart',
    touchPoints: [{
      x: 100,
      y: 100,
      id: 1
    }]
  });
Input.dispatchEvent({
    type: 'touchStart',
    touchPoints: [{
      x: 100,
      y: 100,
      id: 1
    }, {
      x: 150,
      y: 100,
      id: 2
    }]
  });

Bug: 1020674
Change-Id: Ib5cae40864312977f03b2c9671edd7c46637be7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1927951
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718846}
parent ead88287
...@@ -776,11 +776,6 @@ void InputHandler::DispatchWebTouchEvent( ...@@ -776,11 +776,6 @@ void InputHandler::DispatchWebTouchEvent(
"TouchEnd and TouchCancel must not have any touch points.")); "TouchEnd and TouchCancel must not have any touch points."));
return; return;
} }
if (type == blink::WebInputEvent::kTouchStart && !touch_points_.empty()) {
callback->sendFailure(Response::InvalidParams(
"Must have no prior active touch points to start a new touch."));
return;
}
if (type != blink::WebInputEvent::kTouchStart && touch_points_.empty()) { if (type != blink::WebInputEvent::kTouchStart && touch_points_.empty()) {
callback->sendFailure(Response::InvalidParams( callback->sendFailure(Response::InvalidParams(
"Must send a TouchStart first to start a new touch.")); "Must send a TouchStart first to start a new touch."));
...@@ -814,24 +809,18 @@ void InputHandler::DispatchWebTouchEvent( ...@@ -814,24 +809,18 @@ void InputHandler::DispatchWebTouchEvent(
std::vector<blink::WebTouchEvent> events; std::vector<blink::WebTouchEvent> events;
bool ok = true; bool ok = true;
for (auto& id_point : points) { for (auto& id_point : points) {
if (touch_points_.find(id_point.first) != touch_points_.end()) if (touch_points_.find(id_point.first) != touch_points_.end() &&
continue; touch_points_[id_point.first].PositionInWidget() ==
events.emplace_back(type, modifiers, timestamp); id_point.second.PositionInWidget()) {
ok &= GenerateTouchPoints(&events.back(), blink::WebInputEvent::kUndefined,
touch_points_, id_point.second);
touch_points_.insert(id_point);
}
for (auto& id_point : points) {
DCHECK(touch_points_.find(id_point.first) != touch_points_.end());
if (touch_points_[id_point.first].PositionInWidget() ==
id_point.second.PositionInWidget()) {
continue; continue;
} }
events.emplace_back(type, modifiers, timestamp); events.emplace_back(type, modifiers, timestamp);
ok &= GenerateTouchPoints(&events.back(), blink::WebInputEvent::kUndefined, ok &= GenerateTouchPoints(&events.back(), blink::WebInputEvent::kUndefined,
touch_points_, id_point.second); touch_points_, id_point.second);
touch_points_[id_point.first] = id_point.second; touch_points_[id_point.first] = id_point.second;
} }
if (type != blink::WebInputEvent::kTouchCancel) if (type != blink::WebInputEvent::kTouchCancel)
type = blink::WebInputEvent::kTouchEnd; type = blink::WebInputEvent::kTouchEnd;
for (auto it = touch_points_.begin(); it != touch_points_.end();) { for (auto it = touch_points_.begin(); it != touch_points_.end();) {
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>TestDriver actions: two touch points with one moving one pause</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
div#test1{
position: fixed;
top: 0;
left: 0;
width: 100px;
height: 100px;
background-color: blue;
}
</style>
<div id="test1">
</div>
<script>
let event_type = [];
let event_id = [];
async_test(t => {
let test1 = document.getElementById("test1");
document.getElementById("test1").addEventListener("pointerdown",
e => {event_type.push(e.type); event_id.push(e.pointerId);});
document.getElementById("test1").addEventListener("pointerup",
e => {event_type.push(e.type); event_id.push(e.pointerId);});
document.getElementById("test1").addEventListener("pointermove",
e => {event_type.push(e.type); event_id.push(e.pointerId);});
let actions = new test_driver.Actions()
.addPointer("touchPointer1", "touch")
.addPointer("touchPointer2", "touch")
.pointerMove(0, 0, {origin: test1, sourceName: "touchPointer1"})
.pointerMove(10, 0, {origin: test1, sourceName: "touchPointer2"})
.pointerDown({sourceName: "touchPointer1"})
.pointerMove(0, 5, {origin: test1, sourceName: "touchPointer1"})
.pointerDown({sourceName: "touchPointer2"})
.pointerUp({sourceName: "touchPointer1"})
.pointerUp({sourceName: "touchPointer2"});
actions.send()
.then(t.step_func_done(() => {
assert_array_equals(event_type, ["pointerdown", "pointermove", "pointerdown", "pointerup", "pointerup"]);
assert_array_equals(event_id, [2, 2, 3, 2, 3]);
}))
.catch(e => t.step_func(() => assert_unreached("Actions sequence failed " + e)));
});
</script>
...@@ -509,3 +509,95 @@ Dispatching event: ...@@ -509,3 +509,95 @@ Dispatching event:
type: touchcancel type: touchcancel
----Touches---- ----Touches----
------- Sequence ------
Dispatching event:
{
touchPoints : [
[0] : {
id : <number>
x : 100
y : 100
}
]
type : touchStart
}
-----Event-----
type: touchstart
----Touches----
id: 0
pageX: 100
pageY: 100
radiusX: 1
radiusY: 1
rotationAngle: 0
force: 1
Dispatching event:
{
touchPoints : [
[0] : {
id : <number>
x : 100
y : 100
}
[1] : {
id : <number>
x : 150
y : 100
}
]
type : touchStart
}
-----Event-----
type: touchstart
----Touches----
id: 0
pageX: 100
pageY: 100
radiusX: 1
radiusY: 1
rotationAngle: 0
force: 1
id: 1
pageX: 150
pageY: 100
radiusX: 1
radiusY: 1
rotationAngle: 0
force: 1
Dispatching event:
{
touchPoints : [
[0] : {
id : <number>
x : 100
y : 150
}
[1] : {
id : <number>
x : 150
y : 150
}
]
type : touchMove
}
-----Event-----
type: touchmove
----Touches----
id: 0
pageX: 100
pageY: 150
radiusX: 1
radiusY: 1
rotationAngle: 0
force: 1
id: 1
pageX: 150
pageY: 150
radiusX: 1
radiusY: 1
rotationAngle: 0
force: 1
...@@ -224,5 +224,39 @@ ...@@ -224,5 +224,39 @@
touchPoints: [] touchPoints: []
}); });
testRunner.log('\n------- Sequence ------');
await dispatchEvent({
type: 'touchStart',
touchPoints: [{
x: 100,
y: 100,
id: 1
}]
});
await dispatchEvent({
type: 'touchStart',
touchPoints: [{
x: 100,
y: 100,
id: 1
}, {
x: 150,
y: 100,
id: 2
}]
});
await dispatchEvent({
type: 'touchMove',
touchPoints: [{
x: 100,
y: 150,
id: 1
}, {
x: 150,
y: 150,
id: 2
}]
});
testRunner.completeTest(); testRunner.completeTest();
}) })
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