preventDefault on body mousemove doesn't work
Categories
(Core :: DOM: Selection, defect, P3)
Tracking
()
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.
![]() |
||
Updated•5 years ago
|
Comment 1•5 years ago
|
||
I wonder what Chrome actually prevents from happening there as the mouse certainly still moves (and with tricks you can still select text).
Updated•5 years ago
|
Reporter | ||
Comment 2•5 years ago
|
||
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>
.
Comment 3•5 years ago
|
||
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 :)
Updated•5 years ago
|
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.
Reporter | ||
Comment 6•5 years ago
|
||
@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.mp4How 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.
Reporter | ||
Comment 8•5 years ago
|
||
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.
Depends on D106082
Comment 11•4 years ago
|
||
Comment 13•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/580b096a83ea
https://hg.mozilla.org/mozilla-central/rev/697bd822d1ee
Reverted by bug 1712339.
Comment 16•1 year ago
•
|
||
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?
Comment 17•1 year ago
|
||
(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. 🎉👍
Description
•