Skip to content
Permalink
Browse files
Fix a bug that mousedown without mouseup in a frame disturbs click ev…
…ent in another frame

Fix a bug that mousedown without mouseup in a frame disturbs click event in another frame
https://bugs.webkit.org/show_bug.cgi?id=119305

Reviewed by Ryosuke Niwa.

Merge - https://src.chromium.org/viewvc/blink?revision=154698&view=revision

If a mouse button is clicked but mouseup event for it is not dispatched (it happens
frequently because of context menus) and mousedown in another frame is default-prevented,
'click' event for the latter mouse click is not dispatched.

EventHandler::handleMousePressEvent wrongly continues to hold a node for the first click,
and it prevents hit-testing for the second click. We should always clear
m_capturingMouseEventsElement in mousedown handling code.

* Source/WebCore/page/EventHandler.cpp:
(EventHandler::handleMousePressEvent): Add condition to return "nullptr"
* LayoutTests/fast/events/click-after-mousedown-cancel.html: Add Test Case
* LayoutTests/fast/events/click-after-mousedown-cancel-expected.txt: Add Test Case Expectation
* LayoutTests/platform/ios/TestExpectations: Updated to skip added test on iOS due to lack of mouse event support

Canonical link: https://commits.webkit.org/258055@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Dec 17, 2022
1 parent 3837614 commit c2dd7ba9890874670b16f914a46afb7c420da9ce
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
@@ -0,0 +1,10 @@
Mousedown without mouseup in a sub frame should not confuse a click in another frame.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS Click event was dispatched.
PASS successfullyParsed is true

TEST COMPLETE
Button
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<iframe src="data:text/html,"></iframe>
<button type="button">Button</button>
<script>
description('Mousedown without mouseup in a sub frame should not confuse a click in another frame.');
jsTestIsAsync = true;
window.onload = function() {
var button = document.querySelector('button');
button.addEventListener('mousedown', function(event) {
event.preventDefault();
}, false);
button.addEventListener('click', function(event) {
testPassed('Click event was dispatched.');
finishJSTest();
}, false);

var iframe = document.querySelector('iframe');
// Mousedown on the iframe, but no mouseup.
eventSender.mouseMoveTo(iframe.offsetLeft + iframe.offsetWidth / 2, iframe.offsetTop + iframe.offsetHeight / 2);
eventSender.mouseDown(1);
// Click on the button in the main document.
eventSender.mouseMoveTo(button.offsetLeft + button.offsetWidth / 2, button.offsetTop + button.offsetHeight / 2);
eventSender.mouseDown(0);
setTimeout(function() {
testFailed('Click event was not dispatched.');
finishJSTest();
}, 100);
eventSender.mouseUp(0);
}
</script>
@@ -490,6 +490,7 @@ fast/events/autoscroll-when-zoomed.html [ Skip ]
fast/events/before-input-events-prevent-drag-and-drop.html [ Skip ]
fast/events/capture-on-target.html [ Skip ]
fast/events/check-defocus-event-order-when-triggered-by-mouse-click.html [ Skip ]
fast/events/click-after-mousedown-cancel.html [ Skip ]
fast/events/click-count.html [ Skip ]
fast/events/click-focus-anchor.html [ Skip ]
fast/events/click-focus-control.html [ Skip ]
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006-2022 Apple Inc. All rights reserved.
* Copyright (C) 2013 Google Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
* Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
*
@@ -1746,6 +1747,9 @@ bool EventHandler::handleMousePressEvent(const PlatformMouseEvent& platformMouse
#if !ENABLE(IOS_TOUCH_EVENTS)
cancelFakeMouseMoveEvent();
#endif
if (m_eventHandlerWillResetCapturingMouseEventsElement)
m_capturingMouseEventsElement = nullptr;

m_mousePressed = true;
m_capturesDragging = true;
setLastKnownMousePosition(platformMouseEvent);

0 comments on commit c2dd7ba

Please sign in to comment.