Closed Bug 1674658 Opened 5 years ago Closed 11 months ago

preventDefault on body mousemove doesn't work

Categories

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

defect

Tracking

()

RESOLVED WONTFIX
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: 4 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

Perhaps Chromium's behavior changed (or is changing) here?

Testing the jsfiddle from comment 0: https://jsfiddle.net/zu0jpar2/ :

  • In Chrome 124 on Win11, I mostly am unable to select the text. (Clicking and dragging across the text has no effect. Double-clicking does select a word, but that's cheating.)
  • In Chrome 125 beta and 126dev on Win11, though, I'm able to select the text just fine. (Also Chrome 126dev on Ubuntu; haven't tested other Chrome versions there).

(My Windows 11 testing is via BrowserStack which should be a relatively "stock" Win11 setup; and my Ubuntu testing is on my local machine.)

So it looks like maybe Chrome 125 and newer have fixed this to match us, perhaps?

(I tested Epiphany (based on WebKit) on Ubuntu, too, and they match us as well; clicking-and-dragging selects the text just fine.)

Google sent Intent to Ship to match our behavior, which is now riding the train: https://groups.google.com/a/chromium.org/g/blink-dev/c/fyVzOAmQHzU, https://source.chromium.org/chromium/chromium/src/+/165b28d3f3e0e6f66fd680e39d751830afb0ed7d

Depending whether they land successfully, we'll be able to WONTFIX this.

Chrome now works just as Firefox does. 🎉👍

Status: REOPENED → RESOLVED
Closed: 4 years ago11 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: