Skip to content

Commit

Permalink
Add a WPT for pointerevent user activation trigger.
Browse files Browse the repository at this point in the history
Related to HTML issue: whatwg/html#3849

Also fix double-activation in Chrome's gesture tap.

Bug: 826293, 1265587
Change-Id: I3bc3bcbcfeda242512fb777a1c8881c475fed5fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3254213
Reviewed-by: Robert Flack <flackr@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Mustaq Ahmed <mustaq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#940118}
NOKEYCHECK=True
GitOrigin-RevId: 34b3146d8dfc1e44715703e4cf97779fc7c8688d
  • Loading branch information
mustaqahmed authored and Copybara-Service committed Nov 10, 2021
1 parent 829a1db commit eb0dc94
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 16 deletions.
7 changes: 4 additions & 3 deletions blink/renderer/core/input/gesture_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ WebInputEventResult GestureManager::HandleGestureTap(
FlooredIntPoint(gesture_event.PositionInRootFrame());
Node* tapped_node = current_hit_test.InnerNode();
Element* tapped_element = current_hit_test.InnerElement();
LocalFrame::NotifyUserActivation(
tapped_node ? tapped_node->GetDocument().GetFrame() : nullptr,
mojom::blink::UserActivationNotificationType::kInteraction);

mouse_event_manager_->SetClickElement(tapped_element);

Expand Down Expand Up @@ -403,6 +400,10 @@ WebInputEventResult GestureManager::HandleGestureLongPress(
return WebInputEventResult::kNotHandled;
}

// For touch pointer interactions, pointerup is an activation triggering
// event. A long-press gesture doesn't fire a pointerup event (fires a
// pointercancel instead), but for compat reasons we need user activation
// here.
LocalFrame::NotifyUserActivation(
inner_node ? inner_node->GetDocument().GetFrame() : nullptr,
mojom::blink::UserActivationNotificationType::kInteraction);
Expand Down
39 changes: 34 additions & 5 deletions blink/renderer/core/input/ime_on_focus_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,40 @@ class ImeOnFocusTest : public testing::Test {
const AtomicString& focus_element = g_null_atom,
String frame = "");

private:
std::unique_ptr<WebPointerEvent> CreateTouchPointerEvent(
WebInputEvent::Type type,
gfx::PointF position,
float size);
String base_url_;
frame_test_helpers::WebViewHelper web_view_helper_;
Persistent<Document> document_;
};

void ImeOnFocusTest::SendGestureTap(WebViewImpl* web_view,
gfx::Point client_point) {
gfx::PointF position(client_point);
float size = 10;

// GestureTap comes after a pointerdown/up.
web_view->MainFrameWidget()->HandleInputEvent(WebCoalescedInputEvent(
CreateTouchPointerEvent(WebInputEvent::Type::kPointerDown, position,
size),
{}, {}, ui::LatencyInfo()));

web_view->MainFrameWidget()->HandleInputEvent(WebCoalescedInputEvent(
CreateTouchPointerEvent(WebInputEvent::Type::kPointerUp, position, size),
{}, {}, ui::LatencyInfo()));

WebGestureEvent web_gesture_event(WebInputEvent::Type::kGestureTap,
WebInputEvent::kNoModifiers,
WebInputEvent::GetStaticTimeStampForTests(),
WebGestureDevice::kTouchscreen);
// GestureTap is only ever from touch screens.
web_gesture_event.SetPositionInWidget(gfx::PointF(client_point));
web_gesture_event.SetPositionInScreen(gfx::PointF(client_point));
web_gesture_event.SetPositionInWidget(position);
web_gesture_event.SetPositionInScreen(position);
web_gesture_event.data.tap.tap_count = 1;
web_gesture_event.data.tap.width = 10;
web_gesture_event.data.tap.height = 10;
web_gesture_event.data.tap.width = size;
web_gesture_event.data.tap.height = size;

web_view->MainFrameViewWidget()->HandleInputEvent(
WebCoalescedInputEvent(web_gesture_event, ui::LatencyInfo()));
Expand Down Expand Up @@ -113,6 +130,18 @@ void ImeOnFocusTest::RunImeOnFocusTest(
web_view_helper_.Reset();
}

std::unique_ptr<WebPointerEvent> ImeOnFocusTest::CreateTouchPointerEvent(
WebInputEvent::Type type,
gfx::PointF position,
float size) {
return std::make_unique<WebPointerEvent>(
type,
WebPointerProperties(1, WebPointerProperties::PointerType::kTouch,
WebPointerProperties::Button::kLeft, position,
position, 0, 0),
size, size);
}

TEST_F(ImeOnFocusTest, OnLoad) {
RunImeOnFocusTest("ime-on-focus-on-load.html", 0);
}
Expand Down
8 changes: 3 additions & 5 deletions blink/renderer/core/input/pointer_event_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,9 @@ WebInputEventResult PointerEventManager::HandlePointerEvent(
// Any finger lifting is a user gesture only when it wasn't associated with a
// scroll.
// https://docs.google.com/document/d/1oF1T3O7_E4t1PYHV6gyCwHxOi3ystm0eSL5xZu7nvOg/edit#
// Re-use the same UserGesture for touchend and pointerup (but not for the
// mouse events generated by GestureTap).
// For the rare case of multi-finger scenarios spanning documents, it
// seems extremely unlikely to matter which document the gesture is
// associated with so just pick the pointer event that comes.
// For the rare case of multi-finger scenarios spanning documents, it seems
// extremely unlikely to matter which document the gesture is associated with
// so just pick the pointer event that comes.
if (event.GetType() == WebInputEvent::Type::kPointerUp &&
!non_hovering_pointers_canceled_ && pointer_event_target.target_frame) {
LocalFrame::NotifyUserActivation(
Expand Down
1 change: 1 addition & 0 deletions blink/web_tests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,7 @@ crbug.com/626703 external/wpt/css/css-grid/grid-model/grid-areas-overflowing-gri
crbug.com/626703 external/wpt/css/css-sizing/fit-content-length-percentage-002.html [ Failure ]
crbug.com/626703 [ Mac10.14 ] external/wpt/pointerevents/pointerevent_pointercapture_in_frame.html?pen [ Timeout ]
crbug.com/626703 [ Mac11 ] external/wpt/pointerevents/pointerevent_pointercapture_in_frame.html?pen [ Timeout ]
crbug.com/1265587 external/wpt/html/user-activation/activation-trigger-pointerevent.html?pen [ Failure ]
crbug.com/626703 external/wpt/html/cross-origin-opener-policy/iframe-popup-same-origin-to-unsafe-none.https.html [ Skip Timeout ]
crbug.com/626703 external/wpt/css/css-sizing/fit-content-length-percentage-006.html [ Failure ]
crbug.com/626703 external/wpt/css/css-sizing/fit-content-length-percentage-007.html [ Failure ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ <h1>Test for right-click activation trigger</h1>
<script>
promise_test(async () => {
var actions = new test_driver.Actions();
actions_promise = actions
.pointerMove(0, 0, {origin: document.body})
actions.pointerMove(0, 0, {origin: document.body})
.pointerDown({button: actions.ButtonType.RIGHT})
.pointerUp({button: actions.ButtonType.RIGHT})
.send();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<meta name="variant" content="?mouse">
<meta name="variant" content="?pen">
<meta name="variant" content="?touch">
<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>
<script src="resources/utils.js"></script>
</head>
<body>
<h1>Test for pointerevent click activation trigger</h1>
<p>Tests user activation from a pointer click.</p>
<ol id="instructions">
<li>Click anywhere in the document.
</ol>
<script>
let pointer_type = location.search.substring(1);

promise_test(async () => {
const test_pointer = pointer_type + "TestPointer";

new test_driver.Actions().addPointer(test_pointer, pointer_type)
.pointerMove(0, 0, {origin:document.body, sourceName:test_pointer})
.pointerDown({sourceName:test_pointer})
.pointerUp({sourceName:test_pointer})
.send();

let pointerdown_event = getEvent('pointerdown');
let pointerup_event = getEvent('pointerup');
let click_event = getEvent('click');

await pointerdown_event;
let consumed_pointerdown = await consumeTransientActivation();
await pointerup_event;
let consumed_pointerup = await consumeTransientActivation();
await click_event;
let consumed_click = await consumeTransientActivation();

if (pointer_type === "mouse") {
assert_true(consumed_pointerdown,
pointer_type + " pointerdown event should result in activation");
assert_false(consumed_pointerup,
pointer_type + " pointerup should have no activation after pointerdown consumption");
assert_false(consumed_click,
pointer_type + " click should have no activation after pointerdown consumption");
} else {
assert_false(consumed_pointerdown,
pointer_type + " pointerdown event should not result in activation");
assert_true(consumed_pointerup,
pointer_type + " pointerup event should result in activation");
assert_false(consumed_click,
pointer_type + " click should have no activation after pointerup consumption");
}
}, "Activation through " + pointer_type + " pointerevent click");
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
var bounds = document.querySelector('#target').getBoundingClientRect();
var x = bounds.left + bounds.width / 2;
var y = bounds.top + bounds.height / 2;

// TODO(beccahughes): for some reasons, using pointerActanionSequence fails.
eventSender.gestureTap(x, y);
eventSender.clearTouchPoints();
eventSender.addTouchPoint(x, y);
eventSender.touchStart();

eventSender.releaseTouchPoint(0);
eventSender.touchEnd();

document.location.href = 'resources/test-autoplay.html';
</script>

0 comments on commit eb0dc94

Please sign in to comment.