Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7520 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] Incorrect isLeftClick code, plus isRightClick and isMiddleClick

Reported by: tdd Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: minor Keywords: 1.6.0 ready
Cc:

Description

* This can't be tested as of yet (no mouse/event simulation in unittest.js) * This is both a defect (isLeftClick) and an enhancement (isRight|MiddleClick)

Event.isLeftClick currently does:

    return (((event.which) && (event.which == 1)) ||
            ((event.button) && (event.button == 1)));

This works on non-IE browsers because they do support which as a compatibility standpoint, it seems (I checked on Gecko-based browsers). But the W3C spec for button goes from 0 to 2, not from 1 to 3, with 0 being "left."

So the attached patch fixes this (all existings tests pass properly, of course), and adds, for the hell of it, isMiddleClick and isRightClick.

Attachments

event_clicks.diff (0.9 kB) - added by tdd on 04/16/07 16:05:47.
Fixed the "undefined" error.
clicker.html (1.9 kB) - added by RQuadling on 04/24/07 09:46:47.
Example to show different values for Event.button and Event.which in IE and FF
event.button_detection.diff (1.5 kB) - added by RQuadling on 04/24/07 11:07:21.
Event.which and Event.button are both different in IE and FF.
button.fxtest.diff (11.5 kB) - added by tdd on 10/11/07 19:24:52.
Updated patch with full functional test against current trunk, extracted from the fx test in the events branch.
clicker_V1.6.0rc1.html (0.7 kB) - added by RQuadling on 10/17/07 11:39:25.
Show the event info when mouse clicking.
isButton.diff (1.6 kB) - added by RQuadling on 10/17/07 11:51:11.
Patch to fix left/right/middle clicks. Tested on IE7/FF2 WinXPSP2
button.diff (1.0 kB) - added by mislav on 10/17/07 13:13:12.
tested in IE7, Opera and FF (Windows)

Change History

04/16/07 03:57:08 changed by kangax

this patch throws _isSpecificButton is not defined (Line 2212)

to solve this change _isSpecificButton to Event._isSpecificButton in isLeftClick, isMiddleClick & isRightClick

04/16/07 16:05:47 changed by tdd

  • attachment event_clicks.diff added.

Fixed the "undefined" error.

04/16/07 16:06:17 changed by tdd

Now fixed!

04/18/07 09:08:22 changed by Tobie

TDD, can you please check if those changes are covered in the events branch ?

04/18/07 09:43:55 changed by tdd

Tobie: they're not AFAICS. It still uses the legacy, incorrect test, and it has no is(Right|Middle)Click methods.

04/18/07 10:00:58 changed by Tobie

You have commit rights to that branch... don't you ? ;-)

04/18/07 12:00:50 changed by tdd

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [6537].

04/18/07 12:01:06 changed by tdd

Still, to be merged in trunk.

04/18/07 12:01:18 changed by tdd

  • status changed from closed to reopened.
  • resolution deleted.

04/18/07 12:04:24 changed by tdd

  • keywords changed from tiny ready to tiny 1.5.2 ready branch.

Reopened because, er, it's not merged in trunk after all. It's in the events branch, though.

04/24/07 09:46:47 changed by RQuadling

  • attachment clicker.html added.

Example to show different values for Event.button and Event.which in IE and FF

04/24/07 10:48:59 changed by RQuadling

I see that the values of Event.button and Event.which are different from IE7 and FF2.

I've attached a fairly complete html script (uses prototype.js only).

But I hope you can see what I'm trying to prove. The extension to the Event object would need to be merged into event.js.

Just to recap.

On IE7

Left button clicked - Event.which = 1 and Event.button = 1 Right button clicked - Event.which = 1 and Event.button = 2 Middle button clicked - Event.which = 1 and Event.button = 4

The buttons can be OR'd to be used as a bitmask for multiple/simultaneous button pressing, but it seems that in my testing each button always produced its own mousedown event - the click event didn't populate Event.which or Event.button with different information for different buttons.

On FF2

Left button clicked - Event.which = 0 and Event.button = 1 Right button clicked - Event.which = 2 and Event.button = 3 Middle button clicked - Event.which = 1 and Event.button = 2

If using the click event rather than the mousedown event, only the primary button is captured but in this instance the values for Event.which and Event.button where consistent with the mousedown event values.

And for the first time, I used Opera9 and the results were interesting. I had to enable the "Allow Right Click" option first. Thereafter, the left and right buttons matched FF2. The middle button didn't respond at all. This is with the mousedown event. The click event only worked on the primary button but at least the value matched that of the mousedown event.

Phew. Quite a lot of work there. I hope this is useful.

Regards,

Richard Quadling.

04/24/07 11:07:21 changed by RQuadling

  • attachment event.button_detection.diff added.

Event.which and Event.button are both different in IE and FF.

10/11/07 19:24:52 changed by tdd

  • attachment button.fxtest.diff added.

Updated patch with full functional test against current trunk, extracted from the fx test in the events branch.

10/11/07 19:25:44 changed by tdd

  • keywords changed from tiny 1.5.2 ready branch to 1.6.0 ready.

Added the trunk-relevant parts of the events branch's functional tests. Works alright with both functional and unit tests.

10/11/07 19:26:00 changed by tdd

  • summary changed from [PATCH] Incorrect isLeftClick code, plus isRightClick and isMiddleClick to [TEST] [PATCH] Incorrect isLeftClick code, plus isRightClick and isMiddleClick.

10/12/07 10:25:50 changed by RQuadling

Being new here, do I need to to anything?

10/16/07 03:19:44 changed by sam

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [7926]) prototype: Cross-browser Event#isLeftClick with the addition of is(Middle|Right)Click. Closes #7520.

10/17/07 11:38:13 changed by RQuadling

  • status changed from closed to reopened.
  • resolution deleted.

Using a slightly amended clicker.html and using the new rc1, I'm still having a problem. Left clicking in IE7 responds as if middle click has been made. Middle clicking isn't recognised correctly at all.

See code at http://pastie.caboo.se/108034 and the newly attached clicker_V1.6.0rc1.html

I seem to have fixed this by making the isButton function a member function to the Event class.

I've also attached a patch for that based upon 1.6.0rc1.

10/17/07 11:39:25 changed by RQuadling

  • attachment clicker_V1.6.0rc1.html added.

Show the event info when mouse clicking.

10/17/07 11:51:11 changed by RQuadling

  • attachment isButton.diff added.

Patch to fix left/right/middle clicks. Tested on IE7/FF2 WinXPSP2

10/17/07 13:12:32 changed by mislav

  • summary changed from [TEST] [PATCH] Incorrect isLeftClick code, plus isRightClick and isMiddleClick to [PATCH] Incorrect isLeftClick code, plus isRightClick and isMiddleClick.

Richard, thanks for reporting. The solution in fact is much simpler and doesn't require merging browser-specific code to one function. I've attached a patch.

10/17/07 13:13:12 changed by mislav

  • attachment button.diff added.

tested in IE7, Opera and FF (Windows)

(follow-up: ↓ 19 ) 10/17/07 13:25:28 changed by RQuadling

Testing that at my end ...

And yippee!

Thanks.

I see that my attempt at fixing this was OK (i.e. turn isButton into a method). I merged the browser code at the same time as 'cause I didn't think ...

One final question..

return isButton(event, ..);

vs

return Event.pointer(event)..

Shouldn't it be ...

return Event.isButton(event, ...);

?

10/17/07 13:26:55 changed by sam

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [7954]) prototype: Fix Event#is(Left|Middle|Right)Click in IE. Closes #7520.

(in reply to: ↑ 17 ; follow-up: ↓ 20 ) 10/17/07 13:30:10 changed by mislav

Replying to RQuadling:

Shouldn't it be return Event.isButton(event, ...)

isButton here is a private method accessed through a closure - there isn't a need for making it public

(in reply to: ↑ 19 ) 10/17/07 15:15:28 changed by RQuadling

Replying to mislav:

Replying to RQuadling:

Shouldn't it be return Event.isButton(event, ...)

isButton here is a private method accessed through a closure - there isn't a need for making it public

Aha. I see. Thank you.