Opened 12 years ago

Closed 10 years ago

Last modified 8 years ago

#3740 closed enhancement (fixed)

Add mouse button constants

Reported by: guest Owned by: Eugene Lazutkin
Priority: high Milestone: 1.4
Component: Events Version: 0.9
Keywords: Cc: jayant.b.sai@…
Blocked By: Blocking:

Description (last modified by bill)

Dojo provides constants for the keyboard keys; dojo.keys. Similarly I recommend adding constants for 'mouse buttons' also, or they can be rolled into dojo.keys.

dojo.mouseButtons = {
  LEFT: dojo.isIE ? 1 : 0,
  MIDDLE: dojo.isIE ? 4 : 1,
  RIGHT: 2
}

Change History (28)

comment:1 Changed 12 years ago by bill

Milestone: 1.0
Owner: changed from anonymous to sjmiles

Scott, what do you think? Sounds reasonable to me (although my mac only has one button). Although, come to think of it, how is ctrl-button reported on the mac? Does it get normalized to RIGHT?

comment:2 in reply to:  1 Changed 12 years ago by guest

Replying to bill:

Sounds reasonable to me (although my mac only has one button). Although, come to think of it, how is ctrl-button reported on the mac? Does it get normalized to RIGHT?

I put together a quick test page to test out bill's comment and tried Safari, Firefox & Opera on my mac.

event.button values:
Safari, Firefox & Opera : '0' for left mouse button.
Safari: '0' for mouse wheel, probably same for the middle mouse button.
Firefox & Opera : No event for middle mouse button.
No event fired on right mouse button or CTRL+click.

Safari & Firefox : '2' for 'oncontextmenu'.
Opera : Does not fire oncontextmenu at all.

<html>

<head>

<title>Mouse Buttons</title> <script type="text/javascript" src="js/dojo-0.9.0beta/dojo/dojo.js"></script> <script type="text/javascript">

function init() {

var clickclick = dojo.byId("clickclick"); dojo.connect(clickclick, "onclick", handler); dojo.connect(clickclick, "oncontextmenu", handler);

}

function handler(evt) {

dojo.byId("txf").value = evt.button;

}

dojo.addOnLoad(init);

</script>

</head> <body>

<div id="clickclick" style="border:1px solid #000;">Click Click</div> <input type="text" id="txf" />

</body>

</html>

thanks Jayant

comment:3 Changed 12 years ago by sjmiles

Milestone: 1.11.2

comment:4 Changed 11 years ago by bill

Component: GeneralEvents
Description: modified (diff)

comment:5 Changed 11 years ago by guest

I think the best thing would be to implement this in dojo.fixEvent

comment:6 Changed 11 years ago by sjmiles

Milestone: 1.21.2.1

comment:7 Changed 11 years ago by bill

Milestone: 1.2.11.3

1.2.1 is only for critical bugs that we find in the 1.2 release; nothing should be marked as 1.2.1 until after we release 1.2

comment:8 Changed 11 years ago by bill

Description: modified (diff)
Milestone: 1.3future
Owner: changed from sjmiles to James Burke

comment:9 Changed 11 years ago by bill

BTW, when fixing this be careful to get IE8 handling right. My guess is that IE8 in non-quirks mode uses the standard key codes (although I haven't tested it).

comment:10 Changed 11 years ago by Eugene Lazutkin

IE uses a bitset to represent all currently pressed buttons. It is not as simple as defining constants. I already had a problem with DnD when the end user pressed by mistake/clumsiness two or more buttons simultaneously and forced an app in the incorrect state.

See #8603 for relevant links.

comment:11 Changed 11 years ago by bill

Milestone: future1.4
Owner: changed from James Burke to Eugene Lazutkin

Eugene said he could do this for 1.4, so I'm taking him up on his offer :-).

Also, he said that he tested IE8 in quirks mode and standards and the buttons work the same as IE6, so we don't have to branch based on IE version.... so ignore my comment above.

comment:12 Changed 11 years ago by Eugene Lazutkin

Status: newassigned

comment:13 Changed 10 years ago by Eugene Lazutkin

(In [17946]) Migrating the detection of Macintosh to hostenv_browser.js, !strict, refs #3740. Required for the upcoming virtualization of control keys.

comment:14 Changed 10 years ago by Eugene Lazutkin

(In [17947]) Adding mouse-specific functions and a virtual key (a copy key), !strict, refs #3740.

comment:15 Changed 10 years ago by Eugene Lazutkin

(In [17948]) Switching DnD to new base facilities, !strict, refs #3740.

comment:16 Changed 10 years ago by Eugene Lazutkin

(In [17949]) Switching DnD to new base facilities, !strict, refs #3740.

comment:17 Changed 10 years ago by Eugene Lazutkin

(In [17950]) Switching DnD to new base facilities, !strict, refs #3740.

comment:18 Changed 10 years ago by Eugene Lazutkin

Resolution: fixed
Status: assignedclosed

While I tested all, please retest Tree DnD, Grid, and PlottedDnd to double check, and reopen the ticket if you find any negative deviations from the previous behavior.

comment:19 Changed 10 years ago by Eugene Lazutkin

(In [17951]) Saving a few bytes by shortening isCopyKeyPressed to isCopyKey, !strict, refs #3740.

comment:20 Changed 10 years ago by Eugene Lazutkin

(In [17952]) Saving a few bytes by shortening isCopyKeyPressed to isCopyKey, !strict, refs #3740.

comment:21 Changed 10 years ago by Eugene Lazutkin

(In [17953]) Saving a few bytes by shortening isCopyKeyPressed to isCopyKey, !strict, refs #3740.

comment:22 Changed 10 years ago by Eugene Lazutkin

Please chime in, if you think that names can be selected better, or you have any other comments.

comment:23 Changed 10 years ago by bill

(In [17960]) Use dojo.isMac in dijit. Refs #3740 and [17946] !strict.

comment:24 Changed 10 years ago by bill

I did a cursory check of Tree DnD, seems to be working well. Thanks for fixing this ticket. Oh, I also updated the API comment format in the DnD code to match our style guidelines.

comment:25 Changed 10 years ago by Eugene Lazutkin

(In [18124]) We need to streamline all functions, which run as a part of the event processing, !strict, refs #3740.

comment:26 Changed 8 years ago by jesus.crysist

I wanted to use dojo.mouseButtons to check if left mouse button is clicked and I found out that Chrome uses 1 for left, 2 for middle and 3 for right mouse button. So I get false value for it.

comment:27 Changed 8 years ago by jesus.crysist

Actually, I tested in Opera and Firefox on Ubuntu 11.04 (Chrome is also on the same system) and it's the same as described in my previous comment: left mb code is 1, middle 2 and right 3. I'd be glad to see this issue fixed as soon as possible.

comment:28 Changed 8 years ago by bill

Are you saying chrome, firefox, and opera all use different constants depending on the platform (windows/mac vs. ubuntu)??

Note: See TracTickets for help on using tickets.