Open Bug 1674658 Opened 4 years ago Updated 12 days ago

preventDefault on body mousemove doesn't work

Categories

(Core :: DOM: Selection, defect, P3)

defect

Tracking

()

REOPENED
88 Branch
Tracking Status
firefox88 --- fixed

People

(Reporter: mailnew4ster+github, Unassigned)

References

Details

(Keywords: parity-chrome)

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36 Edg/86.0.622.43

Steps to reproduce:

Used the following code:
JSFiddle: https://jsfiddle.net/zu0jpar2/

$('body').on('mousemove', function (event) {
event.preventDefault();
});

Actual results:

Mouse move operations are not prevented.

Expected results:

Mouse move should be prevented like in Chrome.

Component: Untriaged → DOM: Events
Product: Firefox → Core

I wonder what Chrome actually prevents from happening there as the mouse certainly still moves (and with tricks you can still select text).

Status: UNCONFIRMED → NEW
Component: DOM: Events → DOM: UI Events & Focus Handling
Ever confirmed: true
Keywords: parity-chrome
Version: Firefox 82 → Trunk

For me the issue was with code implementing drag and drop, and while dragging, in Firefox there's weird stuff such as random text selected on the page. Doesn't happen in Chrome.

I assume the tricks you're referring to is when the mouse is outside of <body>.

I guess this is more about selection.
Could we possibly check the value of aEventStatus around here
https://searchfox.org/mozilla-central/rev/50215d649d4854812837f1343e8f47bd998dacb5/layout/generic/nsIFrame.cpp#4931

mirko, would you have time to look at this. This could be a really small change :)

Component: DOM: UI Events & Focus Handling → DOM: Selection
Flags: needinfo?(mbrodesser)
Severity: -- → S3
Priority: -- → P3

I'll take a look at this once the other bugs I'm currently working are fixed. Could take a few days though. Will keep the ni?-request.

(In reply to mailnew4ster from comment #2)

For me the issue was with code implementing drag and drop, and while dragging, in Firefox there's weird stuff such as random text selected on the page. Doesn't happen in Chrome.

I assume the tricks you're referring to is when the mouse is outside of <body>.

This issue has been discussed at https://bugs.chromium.org/p/chromium/issues/detail?id=346473 already a longer time ago.

@mailnew4ster: does the idea presented at https://bugs.chromium.org/p/chromium/issues/detail?id=346473#c4 fix your specific issue?
See also https://w3c.github.io/uievents/#event-type-mousedown.

Firefox could follow Chrome's behavior, but it would violate the spec. So in any case, the spec should be updated. I'll try a fix at the code which :smaug mentioned in #c3.

Flags: needinfo?(mbrodesser)
Assignee: nobody → mbrodesser

@mbrodesser I don't think so. My code is like the following:
https://jsfiddle.net/u4q6wbpg/

Here's what happens with Firefox:
https://i.imgur.com/MaEcqhc.mp4

How can I apply your quoted suggestion to fix this?

(In reply to mailnew4ster from comment #6)

@mbrodesser I don't think so. My code is like the following:
https://jsfiddle.net/u4q6wbpg/

Here's what happens with Firefox:
https://i.imgur.com/MaEcqhc.mp4

How can I apply your quoted suggestion to fix this?

Try changing the event listener for "mousedown" to:

div.addEventListener('mousedown', function(e) {
    isDown = true;
    offset = [
        div.offsetLeft - e.clientX,
        div.offsetTop - e.clientY
    ];
    e.preventDefault();
}, true);

Then, event.preventDefault() in mousemove becomes superfluous.

OK, now I understand what that guy meant. Yep, looks like that works, thanks.

Currently, the test violates the spec. See
https://github.com/w3c/uievents/issues/278. However, it's the behavior
of all major browsers and the desired one. The spec should be fixed
separately in above ticket.

Pushed by mbrodesser@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/580b096a83ea
part 1) Add WPT. r=smaug
https://hg.mozilla.org/integration/autoland/rev/697bd822d1ee
part 2) Don't peform the default action for `mousemove` events when it should be prevented. r=smaug
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/27741 for changes under testing/web-platform/tests
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 88 Branch
Upstream PR merged by moz-wptsync-bot
Regressions: 1712339

Reverted by bug 1712339.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Assignee: mbrodesser → nobody
See Also: → 1811771
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: