Skip to content

Commit

Permalink
Treat long-press gesture as a user activation.
Browse files Browse the repository at this point in the history
Also add a web-platform-test for this change, which is already
supported by Firefox.

Intent to ship: https://groups.google.com/a/chromium.org/d/msg/blink-dev/-2AyrUFwXvY/Q_wCUmKSAgAJ
Spec change PR: whatwg/html#3659

Bug: 836401
Change-Id: Ia710190857211684ce5ce7d4ff835b874f658b29
Reviewed-on: https://chromium-review.googlesource.com/1039265
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Commit-Queue: Mustaq Ahmed <mustaq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555450}
  • Loading branch information
mustaqahmed authored and Commit Bot committed May 2, 2018
1 parent d8a31d4 commit 8a2c87f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html>
<head>
<title>User activation with 'contextmenu' event</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<link rel="author" title="Google" href="http://www.google.com "/>
<link rel="help" href="https://html.spec.whatwg.org/#triggered-by-user-activation">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#target {
width: 250px;
height: 150px;
float: left;
background-color: green;
}

#done {
float: left;
padding: 20px;
margin: 10px;
}
</style>
<script type="text/javascript">
let activation_event_fired = false;

function run() {
let success = false;
let test_contextmenu = async_test("'contextmenu' can call vibrate.");

on_event(document.getElementById("done"), "click", () => {
test_contextmenu.step(() => {
assert_true(activation_event_fired, "activation event has fired");
});
test_contextmenu.done();
});

on_event(document.getElementById("target"), "contextmenu", (e) => {
test_contextmenu.step(() => {
e.preventDefault();
assert_true(navigator.vibrate(200), "navigator.vibrate is successful");
activation_event_fired = true;
});
});
}
</script>
</head>
<body onload="run()">
<h1>User activation with 'contextmenu' event</h1>
<h4>Tests that a 'contextmenu' event is treated like a user activation.</h4>
<ol>
<li>Right-click or long-press on green.</li>
<li>Click or tap on Done.</li>
</ol>
<div id="target"></div>
<input type="button" id="done" value="Done" />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
importAutomationScript('/pointerevents/pointerevent_common_input.js');

function inject_input() {
return mouseClickInTarget('#target', undefined, 'right').then(function() {
return mouseClickInTarget('#done');
});
}
3 changes: 3 additions & 0 deletions third_party/blink/renderer/core/input/gesture_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ WebInputEventResult GestureManager::HandleGestureLongPress(
return WebInputEventResult::kNotHandled;
}

std::unique_ptr<UserGestureIndicator> gesture_indicator =
Frame::NotifyUserActivation(
inner_node ? inner_node->GetDocument().GetFrame() : nullptr);
return SendContextMenuEventForGesture(targeted_event);
}

Expand Down

0 comments on commit 8a2c87f

Please sign in to comment.