Commit a48b88b4 authored by Navid Zolghadr's avatar Navid Zolghadr Committed by Commit Bot

Send click event to the nearest common ancestor

Send click event even when the targets of down and up
are different and across different interactive elements.

Bug: 869919
Change-Id: Ie90c2d7c7dbb1b873f2a0f8b8ef489ee951489fe
Reviewed-on: https://chromium-review.googlesource.com/1161164Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarElla Ge <eirage@chromium.org>
Commit-Queue: Navid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580554}
parent 0856d23e
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Click targets the nearest common ancestor</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
div {
padding: 10px;
margin: 5px;
}
</style>
</head>
<body id='body'>
<h1>Click targeting when targets of down and up are different</h1>
<ul>
<li>Press down the primary button on red div and move to blue box and release.</li>
<li>Press down the primary button on button b1 and move to button b2 and release.</li>
<li>Press down the primary button on link 1 and move to link 2 and release.</li>
<li>Click done.</li>
</ul>
<div id="div_container" style="background: green">
<div id="red_div" style="background: red">
</div>
<div id="blue_div" style="background: blue">
</div>
</div>
<div id="button_container" style="background: green">
<button id="button1"> b1
</button>
<button id="button2"> b2
</button>
</div>
<div id="link_container" style="background: green">
<a id="link1" href="#">link1
</a>
<br/>
<a id="link2" href="#">link2
</a>
</div>
<button id="done">Done</button>
<script>
var test_click_target = async_test("Click targets the nearest common ancestor");
// Prevent drag to avoid interfering with the click.
document.addEventListener('dragstart', (e) => e.preventDefault());
var events = [];
var nodes = ['div_container', 'red_div', 'blue_div', 'button_container', 'button1', 'button2', 'link_container', 'link1', 'link2', 'body'];
for (var i = 0; i < nodes.length; i++) {
['mousedown', 'mouseup', 'click'].forEach((eventName) => {
document.getElementById(nodes[i]).addEventListener(eventName, (e) => {
if (e.eventPhase == Event.AT_TARGET)
events.push(e.type + '@' + e.target.id);
});
});
}
document.getElementById('done').addEventListener('click', () => {
test_click_target.step(() => {
assert_equals (events.join(','),
"mousedown@red_div,mouseup@blue_div,click@div_container,mousedown@button1,mouseup@button2,click@button_container,mousedown@link1,mouseup@link2,click@link_container",
"Click should be sent to the nearest common ancestor");
});
test_click_target.done();
});
</script>
</body>
</html>
importAutomationScript('/pointerevents/pointerevent_common_input.js');
function inject_input() {
return mouseDragInTargets(['#red_div', '#blue_div']).then(function() {
return mouseDragInTargets(['#button1', '#button2']);
}).then(function() {
return mouseDragInTargets(['#link1', '#link2']);
}).then(function() {
return mouseClickInTarget('#done');
});
}
When selecting from non-anchor Node to anchor node in ShadowDOM, client should not cause page jump.
Selecting from a node to another node in ShadowDOM. This should not start page navigation.
PASS lastClickTarget is null
PASS lastClickTarget is host
Clicking a node in ShadowDOM.
PASS lastClickTarget is host
......
......@@ -31,7 +31,7 @@ mouseMoveTo(shadowRoot.firstChild);
eventSender.mouseDown();
mouseMoveTo(shadowRoot.firstChild.nextSibling);
eventSender.mouseUp();
shouldBeNull('lastClickTarget');
shouldBe('lastClickTarget', 'host');
debug('');
lastClickTarget = null;
......
......@@ -23,7 +23,7 @@ PASS lastClickTarget is button1
Click on disappearing INPUT value:
PASS lastClickTarget is input1
Mousedown on a form control, and mouseup on an element outside:
PASS lastClickTarget is null
PASS lastClickTarget is document.body
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -131,7 +131,7 @@ eventSender.mouseMoveTo(inputRect.left + 8, (inputRect.top + inputRect.bottom) /
eventSender.mouseDown();
eventSender.mouseMoveTo((spanRect.left + spanRect.right) / 2, spanRect.top + 1);
eventSender.mouseUp();
shouldBeNull('lastClickTarget');
shouldBe('lastClickTarget', 'document.body');
lastClickTarget = null;
container.remove();
......
......@@ -100,11 +100,6 @@ ScrollableArea* AssociatedScrollableArea(const PaintLayer* layer) {
}
ContainerNode* ParentForClickEvent(const Node& node) {
// IE doesn't dispatch click events for mousedown/mouseup events across form
// controls.
if (node.IsHTMLElement() && ToHTMLElement(node).IsInteractiveContent())
return nullptr;
return FlatTreeTraversal::Parent(node);
}
......
......@@ -906,15 +906,14 @@ bool MouseEventManager::HandleDrag(const MouseEventWithHitTestResults& event,
return true;
}
// Once we're past the drag threshold, we don't want to treat this gesture as
// a click.
InvalidateClick();
if (!TryStartDrag(event)) {
// Something failed to start the drag, clean up.
ClearDragDataTransfer();
ResetDragState();
} else {
// Once the drag operation is initiated, we don't want to treat this
// gesture as a click.
InvalidateClick();
// Since drag operation started we need to send a pointercancel for the
// corresponding pointer.
if (initiator == DragInitiator::kMouse) {
......
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