This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23240 - Normatively specify that right/middle mouse button presses do not cause click/dblclick events
Summary: Normatively specify that right/middle mouse button presses do not cause click...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - DOM3 Events (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Travis Leithead [MSFT]
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-13 16:34 UTC by Gary Kacmarcik
Modified: 2013-11-14 09:05 UTC (History)
7 users (show)

See Also:


Attachments

Description Gary Kacmarcik 2013-09-13 16:34:46 UTC
Simon Pieters writes:

What should happen when the user clicks the middle mouse button?

The current situation is as follows:

* Gecko always fires a click event on the document that bubbles and has as target the element being clicked.
* IE doesn't fire a click event if the target is a link, but does fire it if another element is clicked even if it's a descendant of a link.
* Blink/WebKit always fire a click event on the element being clicked.
* Presto never fires a click event for middle mouse.

There even might not be fired in some browsers if the click starts panning mode or some such.

The problem with Blink/WebKit's approach is that sites do something on click which doesn't make sense to do if the user clicks the link with the middle mouse button which should open the link in a new tab. Both actions happen which is not what the user expects.

IE's approach maybe works most of the time but fails when a link contains elements, so seems suboptimal.

Gecko's approach probably works pretty well but is a bit magic and would still fail on sites that put the listener on document or window but still assume the left button is being clicked.

Presto's approach works always AFAICT.

All browsers fire mousedown and mouseup as normal for middle mouse button, so e.g. games or mapping apps that really want to use the middle mouse button separately can still listen for it with these events.

Since click event for middle mouse button is already unreliable, it seems that sites can't depend on it being fired if they want to use the middle mouse button. As such it seems to me that the best approach is what Presto does, to never fire click for the middle mouse button.

Blink bug for this issue is https://code.google.com/p/chromium/issues/detail?id=255
Comment 1 Gary Kacmarcik 2013-09-13 16:36:52 UTC
Current spec states:

"The click event type must be dispatched on the topmost event target indicated by the pointer, when the user presses down and releases the pointer button, or otherwise activates the pointer in a manner that simulates such an action."

Proposed change to:

"The click event type must be dispatched on the topmost event target indicated by the pointer, when the user presses down and releases the *primary* pointer button (i.e., when MouseEvent.button = 0), or otherwise activates the pointer in a manner that simulates such an action."
Comment 2 Glenn Maynard 2013-09-13 19:14:27 UTC
> The problem with Blink/WebKit's approach is that sites do something on click which doesn't make sense to do if the user clicks the link with the middle mouse button which should open the link in a new tab. Both actions happen which is not what the user expects.

The developer needs to check if e.button == 0.  Developers already need to do this, or they'll misbehave when the user right clicks.

Click events should only have fired for left clicks in the first place (failing to check .button is one of the most common scripting bugs I've seen--even YouTube screws this up, right in the search results), but it doesn't make much sense for right click to fire clicks but not middle click.


(In reply to Gary Kacmarcik from comment #1)
> Proposed change to:
> 
> "The click event type must be dispatched on the topmost event target
> indicated by the pointer, when the user presses down and releases the
> *primary* pointer button (i.e., when MouseEvent.button = 0), or otherwise
> activates the pointer in a manner that simulates such an action."

Browsers have fired click for right-click for a long time.  If it was web-compatible to simply stop doing that, I think browsers would have made that change years ago.

Given the weird behaviors of browsers here, there are probably a bunch of strange web-compat things going on.  I don't think it makes sense to try to spec this until it's known what those are.
Comment 3 Ojan Vafai 2013-09-14 17:07:50 UTC
Chrome Linux/Mac do not fire click for right-clicks. I don't have Windows on hand to tell you for sure that Chrome Windows also does not.
Comment 4 Glenn Maynard 2013-09-14 17:56:50 UTC
Firefox definitely does.

> * Gecko always fires a click event on the document that bubbles and has as target the element being clicked.

(Wow, that's painfully broken.  The .target of an event *is* the element that the event is dispatched to.)
Comment 5 Simon Pieters 2013-09-14 19:21:31 UTC
(In reply to Glenn Maynard from comment #2)
> The developer needs to check if e.button == 0.  Developers already need to
> do this, or they'll misbehave when the user right clicks.
> 
> Click events should only have fired for left clicks in the first place
> (failing to check .button is one of the most common scripting bugs I've
> seen--even YouTube screws this up, right in the search results), but it
> doesn't make much sense for right click to fire clicks but not middle click.

Yeah, so then we shouldn't fire click for right click either.

> Browsers have fired click for right-click for a long time.  If it was
> web-compatible to simply stop doing that, I think browsers would have made
> that change years ago.

Presto doesn't fire click for right click.
Comment 6 Gary Kacmarcik 2013-10-21 20:28:26 UTC
Fixed in latest ED to specify that only the primary button fires click and dblclick events.
Comment 7 Gary Kacmarcik 2013-10-21 21:05:21 UTC
Looking at the text in the spec some more, it contains the following passage (which implies that click and dblclick should fire for all buttons):

The default action of the click event type varies based on the event target of the event and the value of the MouseEvent.button or MouseEvent.buttons attributes. Typical default actions of the click event type are as follows:

* Left click (MouseEvent.button value is 0, MouseEvent.buttons value is 1):
   * If the event target has associated activation behavior, the default action must be to execute that activation behavior (see Activation triggers and behavior).
   * If the event target is focusable, the default action must be to give that element document focus.

* Right click (MouseEvent.button value is 1, MouseEvent.buttons value is 2):
   * The default action must be to provide a context menu of options related to that event target.

* Middle click (MouseEvent.button value is 2, MouseEvent.buttons value is 4):
   * If the event target has associated activation behavior, the default action must be to execute that activation behavior in an alternate fashion (such as opening a link in a new tab or window).
   * If the event target has no associated activation behavior, a user agent may assign a custom default action such as an alternate scrolling or panning mode.
Comment 8 Gary Kacmarcik 2013-10-23 14:02:27 UTC
Since the original intent of this was to have these events fire for all buttons, I've updated the ED to be more explicit about this.

Also note that since the dblclick time is a OS user preference, there is no easy way for apps to properly synthesize their own dblclick events if we don't provide them.
Comment 9 Gary Kacmarcik 2013-10-23 20:25:05 UTC
Ojan wrote (on www-dom@):
>FWIW, Blink is planning on moving to not firing click events for middle mouse
>clicks and already doesn't fire them for right clicks. As best I can tell, this
>matches Gecko and IE as well.

I just tested this using:
https://dvcs.w3.org/hg/d4e/raw-file/tip/mouse-event-test.html

Q&D browser test:

                  Chrome    Firefox   IE   Saf
                 Win  Mac  Win   Mac  Win  Mac
left click        y    y    y     y    y    y
left dblclick     y    y    y     y    y    y
mid click         -    y    -     -    y    y
mid dblclick      -    y    -     -    -    y
right click       -    -    -     -    -    -
right dblclick    -    -    -     -    -    -

Middle click often led to scrolling-mode for browsers that didn't produce a click.
Right click always pulled up a context menu.
Comment 10 Gary Kacmarcik 2013-10-23 20:38:09 UTC
(In reply to Gary Kacmarcik from comment #9)
> Middle click often led to scrolling-mode for browsers that didn't produce a
> click.

More specifically:
CrWin FFMac FFWin and IEWin entered scroll-mode on a middle click. IEWin would also generate a middle click the second time the middle button was clicked. IEWin did not generate a dblclick

CrMac and SafMac generated middle click and dblclick.
Comment 11 Gary Kacmarcik 2013-10-23 20:44:04 UTC
bzbarsky wrote (on www-dom@):
> Note that Gecko will fire non-left clicks directly on the document, so
> depending on how you wrote your testcase you may have not seen the events.

Why does it send them to the document instead of the element (as it does for left clicks)?
Comment 12 Olli Pettay 2013-10-23 21:33:15 UTC
Because of some ancient reason to not break Camino.
Also, firing right or middle click on elements breaks pages easily.
Comment 13 Olli Pettay 2013-10-23 21:42:42 UTC
Some history:
https://bugzilla.mozilla.org/show_bug.cgi?id=71705
Comment 14 Olli Pettay 2013-10-23 21:53:47 UTC
(the less interesting Camino bug was https://bugzilla.mozilla.org/show_bug.cgi?id=329810)
Comment 15 Masayuki Nakano 2013-10-25 01:57:51 UTC
(In reply to Gary Kacmarcik from comment #11)
> bzbarsky wrote (on www-dom@):
> > Note that Gecko will fire non-left clicks directly on the document, so
> > depending on how you wrote your testcase you may have not seen the events.
> 
> Why does it send them to the document instead of the element (as it does for
> left clicks)?

(In reply to Olli Pettay from comment #12)
> Because of some ancient reason to not break Camino.
> Also, firing right or middle click on elements breaks pages easily.

Oh, I misunderstood Gecko's behavior...
Comment 16 Masayuki Nakano 2013-11-01 08:05:29 UTC
As I said in telecon, it's hard to emulate click event and dblclick event. Especially for dblclick event, web apps cannot retrieve the proper time between 2 clicks.

However, for not breaking current web apps, not dispatching click event and dblclidk event for non-left buttons is the best approach.

For solving these issues, how about to define new events, mouseclick and mousedblclick? They should be dispatched before click event and dblclick event and if their default are prevented, legacy click event and dblclick event should not be fired.
Comment 17 Glenn Maynard 2013-11-01 14:14:29 UTC
Exposing clicks for other buttons in some way seems reasonable.  It's nontrivial to emulate click using mousedown and mouseup, since the particular behavior (whether to fire a click or not) is up to the platform.  It probably makes more sense to have "rightclick" and "middleclick" events rather than reincarnating the .button property on a new event.

But, what are the use cases for doing this for dblclick?  I don't think I've ever seen a UI with "double-right-click".  (It's not even possible to double-right-click on Macbooks.)  A new event shouldn't be added just because it's hard to do manually, if nobody actually wants to do it.
Comment 18 Ojan Vafai 2013-11-01 18:11:12 UTC
right-click is already covered by the contextmenu event. I can't think of a reason a site would want to capture right click, but not the contextmenu keypress.

I don't really see the point of defining a click event for middle. It's extremely rare that a page wants to do something on click of middle buttons. It is getting even more rare as pages are designing for touch-based devices.
Comment 19 Olli Pettay 2013-11-01 18:16:25 UTC
I can certainly see reasons for middle/right capturing, at least in games.
Comment 20 Ojan Vafai 2013-11-01 18:30:04 UTC
Wouldn't games use mousedown/mouseup?
Comment 21 Gary Kacmarcik 2013-11-14 09:05:13 UTC
Fixed (again!) in latest WD to specify that only the primary button fires click and dblclick events.

This behavior is required because sending click and dblclick for other buttons breaks too much of the web.

The text in the spec that implies that click and dblclick can be sent for non-primary mouse buttons has been updated as well.