-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use MouseEvent.buttons for button state tracking #1921
base: master
Are you sure you want to change the base?
Conversation
278742b
to
0925be1
Compare
I've updated my branch and addressed all comments |
Instead of keeping track of button states ourselves by looking at MouseEvent.button, we can use the MouseEvent.buttons which already contains the state of all buttons.
0925be1
to
19c2b83
Compare
// Otherwise we treat this as a mouse click event. | ||
// Send the button down event here, as the button up | ||
// event is sent at the end of this function. | ||
this._sendMouse(x, y, bmask); | ||
this._sendMouse(x, y, this._mouseButtonMask); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the comment here has been considered. Can you still click in place with dragging active?
I guess that means we are lacking at least one unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This drag handling might be on the wrong layer. Perhaps it should be moved up one level in the stack.
this._handleMouseButton(pos.x, pos.y, true, 1 << 5); | ||
this._handleMouseButton(pos.x, pos.y, false, 1 << 5); | ||
this._handleMouseButton(pos.x, pos.y, true, bmask | 1 << 5); | ||
this._handleMouseButton(pos.x, pos.y, false, bmask); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Do we have unit tests that make sure that buttons + wheel work at the same time?
@@ -1307,33 +1333,36 @@ export default class RFB extends EventTargetMixin { | |||
case 'longpress': | |||
this._fakeMouseMove(ev, pos.x, pos.y); | |||
break; | |||
case 'twodrag': | |||
case 'twodrag': { | |||
let bmask = RFB._convertButtonMask(ev.detail.buttons); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no buttons
attribute for gesture events. I'm concerned that this passes the unit tests. Something must be missing/wrong there.
// Always scroll in the same position. | ||
// We don't know if the mouse was moved so we need to move it | ||
// every update. | ||
this._fakeMouseMove(ev, pos.x, pos.y); | ||
while ((ev.detail.magnitudeY - this._gestureLastMagnitudeY) > GESTURE_SCRLSENS) { | ||
this._handleMouseButton(pos.x, pos.y, true, 0x8); | ||
this._handleMouseButton(pos.x, pos.y, false, 0x8); | ||
this._handleMouseButton(pos.x, pos.y, true, bmask | 0x8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably rather keep using the known mouse state. I.e. this._mouseButtonMask
.
this._handleMouseButton(pos.x, pos.y, true, 0x8); | ||
this._handleMouseButton(pos.x, pos.y, false, 0x8); | ||
this._handleMouseButton(pos.x, pos.y, true, bmask | 0x8); | ||
this._handleMouseButton(pos.x, pos.y, false, 0x0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here.
Instead of keeping track of button states ourselves by looking at
MouseEvent.button
, we can use theMouseEvent.buttons
which already contains the state of all buttons.Note that in
MouseEvent.button
, button numbers are mapped as follows:But when looking at the
MouseEvent.buttons
property, the bits middle and right are switched, which is confusing:With this change, #1919 could be modified to work with Safari as well.
Unfortunately, the internal
_mouseButtonStateMask
state is not removed in this PR as it would require a large rewrite of the general architecture.Tested on: