UNCONFIRMED 81853
DOM 3 Event, mousedown and mouseup default actions
https://bugs.webkit.org/show_bug.cgi?id=81853
Summary DOM 3 Event, mousedown and mouseup default actions
Brandon Andrews
Reported 2012-03-21 17:58:45 PDT
After receiving a response and specification change for the DOM 3 Event Specification from this discussion: https://www.w3.org/Bugs/Public/show_bug.cgi?id=8406 The following changes need either discussion or changes in webkit. http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#event-type-mousedown http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#event-type-mouseup Both now have cancelable default actions. This basically allows a developer to effortlessly prevent a context menu or a middle mouse scroll/pan operation among other things that can now be cancelled. For instance, if a user wanted to stop the context menu they just have to call event.preventDefault(); to stop it. If they want to stop say the middle mouse pan because they're using the middle mouse button they can just called event.preventDefault() on the mousedown event to stop either the momentary scroll or the toggled scroll. (The momentary being when the user holds down the middle mouse button and the toggle one is when the user clicks the middle mouse wheel activating the scroll until they disable it). This also makes the non-standard contextmenu event kind of worthless. Not sure how webkit feels implementing the editor draft like this. (Note they still haven't implemented the MouseEvent "buttons" member. I'll submit another bug since this one can probably use it when choosing when you preventDefault()).
Attachments
Alexey Proskuryakov
Comment 1 2012-03-22 10:53:26 PDT
Do you have a test case that works in other browsers, but not in WebKit?
Brandon Andrews
Comment 2 2012-04-06 17:43:40 PDT
(In reply to comment #1) > Do you have a test case that works in other browsers, but not in WebKit? No, this was just added to the spec recently within the past month so other browsers haven't implemented it yet either. Trying to stir discussion about whether this change is accepted and if it is then I'm trying to see get it implemented in all browsers so they all act the same with the mouse.
Alexey Proskuryakov
Comment 3 2012-04-07 00:23:34 PDT
This seems questionable for performance reasons - much of mouse event handling happens in UI process, which can not consult JavaScript event handlers without a potentially huge performance penalty. Scrolling in particular needs to be responsive.
Brandon Andrews
Comment 4 2012-04-10 20:55:59 PDT
It would only effect the mouse on the mousedown and mouseup events where the user can cancel the default UI behavior of the contextmenu or the middle mouse panning action. The context menu can already be canceled via the non-standard oncontextmenu event so we've seen there is no performance impact with allowing preventDefault to do it upon mouseup for right click. For the middle mouse button down calling preventDefault would just tell the UI not to start a pan action on that mouse down or mouse up. Both have no real performance impact since all the user-agent has to do is check if the default action was cancelled before it does its own action. If it was then they don't execute the implementation specific action for mouseup/mousedown. If it wasn't prevented then they can do whatever. Hopefully that makes sense. (preventDefault for middle mousedown/mouseup does not effect the wheel scroll if that isn't clear. The wheel event's preventDefault has existed in the dom 3 events forever and was discussed years ago and accepted).
Brandon Andrews
Comment 5 2012-07-15 20:59:38 PDT
Here's a test case quickly: http://sirisian.com/javascript/dom3mouse.html source: <!doctype html> <html lang="en"> <head> <title>Dom 3 Mouse</title> <script type="text/javascript"> "use strict"; window.onload = function() { var target = document.getElementById("region"); target.addEventListener("mousedown", function(e) { e.preventDefault(); }, false); target.addEventListener("mouseup", function(e) { e.preventDefault(); }, false); }; </script> </head> <body style="margin: 0;padding: 0;"> <div id="region" style="width:2000px; height:2000px; background-color:#f0f;"></div> </body> </html> The mousedown for the middle mouse works flawlessly. e.preventDefault stops the middle mouse pan from starting. The right click does not. So the fix that needs to be implemented for the mouseup is that if javascript calls e.preventDefault() then don't execute the default action of creating a context menu.
Ahmad Saleem
Comment 6 2022-07-21 16:13:48 PDT
Based on test case from Comment 05, when I use trackpad to scroll up and down in Safari 15.6 on macOS 12.6 console, I don't get any warning or error (within Console) but in case of Chrome Canary 105, I get following message on both event (mousedown and mouseup): [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL> Similarly, in Firefox Nightly 104, I get this message in Console: Ignoring ‘preventDefault()’ call on event of type ‘wheel’ from a listener registered as ‘passive’. I am not sure whether WPT UI Event have coverage for these events: https://wpt.fyi/results/uievents?label=master&label=experimental&aligned&q=uievent Although - Draft do mention that the work is on-going for WPT (in Tests section): https://w3c.github.io/uievents/ Just wanted to share - what I learnt so far about. Thanks!
Note You need to log in before you can comment on or make changes to this bug.