@@ -1091,46 +1091,61 @@ export default class RFB extends EventTargetMixin {
1091
1091
1092
1092
let bmask = RFB . _convertButtonMask ( ev . buttons ) ;
1093
1093
1094
+ let down = ev . type == 'mousedown' ;
1094
1095
switch ( ev . type ) {
1095
1096
case 'mousedown' :
1096
- setCapture ( this . _canvas ) ;
1097
- this . _handleMouseButton ( pos . x , pos . y , true , bmask ) ;
1098
- break ;
1099
1097
case 'mouseup' :
1100
- this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1098
+ if ( this . dragViewport ) {
1099
+ if ( down && ! this . _viewportDragging ) {
1100
+ this . _viewportDragging = true ;
1101
+ this . _viewportDragPos = { 'x' : pos . x , 'y' : pos . y } ;
1102
+ this . _viewportHasMoved = false ;
1103
+
1104
+ // Skip sending mouse events, instead save the current
1105
+ // mouse mask so we can send it later.
1106
+ this . _mouseButtonMask = bmask ;
1107
+ break ;
1108
+ } else {
1109
+ this . _viewportDragging = false ;
1110
+
1111
+ // If we actually performed a drag then we are done
1112
+ // here and should not send any mouse events
1113
+ if ( this . _viewportHasMoved ) {
1114
+ break ;
1115
+ }
1116
+
1117
+ // Otherwise we treat this as a mouse click event.
1118
+ // Send the previously saved button mask, followed
1119
+ // by the current button mask at the end of this
1120
+ // function.
1121
+ this . _sendMouse ( pos . x , pos . y , this . _mouseButtonMask ) ;
1122
+ }
1123
+ }
1124
+ setCapture ( this . _canvas ) ;
1125
+ this . _handleMouseButton ( pos . x , pos . y , bmask ) ;
1101
1126
break ;
1102
1127
case 'mousemove' :
1103
- this . _handleMouseMove ( pos . x , pos . y ) ;
1104
- break ;
1105
- }
1106
- }
1128
+ if ( this . _viewportDragging ) {
1129
+ const deltaX = this . _viewportDragPos . x - pos . x ;
1130
+ const deltaY = this . _viewportDragPos . y - pos . y ;
1107
1131
1108
- _handleMouseButton ( x , y , down , bmask ) {
1109
- if ( this . dragViewport ) {
1110
- if ( down && ! this . _viewportDragging ) {
1111
- this . _viewportDragging = true ;
1112
- this . _viewportDragPos = { 'x' : x , 'y' : y } ;
1113
- this . _viewportHasMoved = false ;
1132
+ if ( this . _viewportHasMoved || ( Math . abs ( deltaX ) > dragThreshold ||
1133
+ Math . abs ( deltaY ) > dragThreshold ) ) {
1134
+ this . _viewportHasMoved = true ;
1114
1135
1115
- // Skip sending mouse events
1116
- this . _mouseButtonMask = bmask ;
1117
- return ;
1118
- } else {
1119
- this . _viewportDragging = false ;
1136
+ this . _viewportDragPos = { 'x' : pos . x , 'y' : pos . y } ;
1137
+ this . _display . viewportChangePos ( deltaX , deltaY ) ;
1138
+ }
1120
1139
1121
- // If we actually performed a drag then we are done
1122
- // here and should not send any mouse events
1123
- if ( this . _viewportHasMoved ) {
1124
- return ;
1140
+ // Skip sending mouse events
1141
+ break ;
1125
1142
}
1126
-
1127
- // Otherwise we treat this as a mouse click event.
1128
- // Send the button down event here, as the button up
1129
- // event is sent at the end of this function.
1130
- this . _sendMouse ( x , y , this . _mouseButtonMask ) ;
1131
- }
1143
+ this . _handleMouseMove ( pos . x , pos . y ) ;
1144
+ break ;
1132
1145
}
1146
+ }
1133
1147
1148
+ _handleMouseButton ( x , y , bmask ) {
1134
1149
// Flush waiting move event first
1135
1150
if ( this . _mouseMoveTimer !== null ) {
1136
1151
clearTimeout ( this . _mouseMoveTimer ) ;
@@ -1143,22 +1158,6 @@ export default class RFB extends EventTargetMixin {
1143
1158
}
1144
1159
1145
1160
_handleMouseMove ( x , y ) {
1146
- if ( this . _viewportDragging ) {
1147
- const deltaX = this . _viewportDragPos . x - x ;
1148
- const deltaY = this . _viewportDragPos . y - y ;
1149
-
1150
- if ( this . _viewportHasMoved || ( Math . abs ( deltaX ) > dragThreshold ||
1151
- Math . abs ( deltaY ) > dragThreshold ) ) {
1152
- this . _viewportHasMoved = true ;
1153
-
1154
- this . _viewportDragPos = { 'x' : x , 'y' : y } ;
1155
- this . _display . viewportChangePos ( deltaX , deltaY ) ;
1156
- }
1157
-
1158
- // Skip sending mouse events
1159
- return ;
1160
- }
1161
-
1162
1161
this . _mousePos = { 'x' : x , 'y' : y } ;
1163
1162
1164
1163
// Limit many mouse move events to one every MOUSE_MOVE_DELAY ms
@@ -1227,22 +1226,22 @@ export default class RFB extends EventTargetMixin {
1227
1226
// for one of the axes is large enough.
1228
1227
if ( Math . abs ( this . _accumulatedWheelDeltaX ) >= WHEEL_STEP ) {
1229
1228
if ( this . _accumulatedWheelDeltaX < 0 ) {
1230
- this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 5 ) ;
1231
- this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1229
+ this . _handleMouseButton ( pos . x , pos . y , bmask | 1 << 5 ) ;
1230
+ this . _handleMouseButton ( pos . x , pos . y , bmask ) ;
1232
1231
} else if ( this . _accumulatedWheelDeltaX > 0 ) {
1233
- this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 6 ) ;
1234
- this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1232
+ this . _handleMouseButton ( pos . x , pos . y , bmask | 1 << 6 ) ;
1233
+ this . _handleMouseButton ( pos . x , pos . y , bmask ) ;
1235
1234
}
1236
1235
1237
1236
this . _accumulatedWheelDeltaX = 0 ;
1238
1237
}
1239
1238
if ( Math . abs ( this . _accumulatedWheelDeltaY ) >= WHEEL_STEP ) {
1240
1239
if ( this . _accumulatedWheelDeltaY < 0 ) {
1241
- this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 3 ) ;
1242
- this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1240
+ this . _handleMouseButton ( pos . x , pos . y , bmask | 1 << 3 ) ;
1241
+ this . _handleMouseButton ( pos . x , pos . y , bmask ) ;
1243
1242
} else if ( this . _accumulatedWheelDeltaY > 0 ) {
1244
- this . _handleMouseButton ( pos . x , pos . y , true , bmask | 1 << 4 ) ;
1245
- this . _handleMouseButton ( pos . x , pos . y , false , bmask ) ;
1243
+ this . _handleMouseButton ( pos . x , pos . y , bmask | 1 << 4 ) ;
1244
+ this . _handleMouseButton ( pos . x , pos . y , bmask ) ;
1246
1245
}
1247
1246
1248
1247
this . _accumulatedWheelDeltaY = 0 ;
@@ -1281,8 +1280,8 @@ export default class RFB extends EventTargetMixin {
1281
1280
this . _gestureLastTapTime = Date . now ( ) ;
1282
1281
1283
1282
this . _fakeMouseMove ( this . _gestureFirstDoubleTapEv , pos . x , pos . y ) ;
1284
- this . _handleMouseButton ( pos . x , pos . y , true , bmask ) ;
1285
- this . _handleMouseButton ( pos . x , pos . y , false , 0x0 ) ;
1283
+ this . _handleMouseButton ( pos . x , pos . y , bmask ) ;
1284
+ this . _handleMouseButton ( pos . x , pos . y , 0x0 ) ;
1286
1285
}
1287
1286
1288
1287
_handleGesture ( ev ) {
@@ -1303,12 +1302,26 @@ export default class RFB extends EventTargetMixin {
1303
1302
this . _handleTapEvent ( ev , 0x2 ) ;
1304
1303
break ;
1305
1304
case 'drag' :
1306
- this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1307
- this . _handleMouseButton ( pos . x , pos . y , true , 0x1 ) ;
1305
+ if ( this . dragViewport ) {
1306
+ this . _viewportHasMoved = false ;
1307
+ this . _viewportDragging = true ;
1308
+ this . _viewportDragPos = { 'x' : pos . x , 'y' : pos . y } ;
1309
+ } else {
1310
+ this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1311
+ this . _handleMouseButton ( pos . x , pos . y , 0x1 ) ;
1312
+ }
1308
1313
break ;
1309
1314
case 'longpress' :
1310
- this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1311
- this . _handleMouseButton ( pos . x , pos . y , true , 0x4 ) ;
1315
+ if ( this . dragViewport ) {
1316
+ // If dragViewport is true, we need to wait to see
1317
+ // if we have dragged outside the threshold before
1318
+ // sending any events to the server.
1319
+ this . _viewportHasMoved = false ;
1320
+ this . _viewportDragPos = { 'x' : pos . x , 'y' : pos . y } ;
1321
+ } else {
1322
+ this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1323
+ this . _handleMouseButton ( pos . x , pos . y , 0x4 ) ;
1324
+ }
1312
1325
break ;
1313
1326
case 'twodrag' :
1314
1327
this . _gestureLastMagnitudeX = ev . detail . magnitudeX ;
@@ -1331,6 +1344,22 @@ export default class RFB extends EventTargetMixin {
1331
1344
break ;
1332
1345
case 'drag' :
1333
1346
case 'longpress' :
1347
+ if ( this . dragViewport ) {
1348
+ this . _viewportDragging = true ;
1349
+ const deltaX = this . _viewportDragPos . x - pos . x ;
1350
+ const deltaY = this . _viewportDragPos . y - pos . y ;
1351
+
1352
+ if ( this . _viewportHasMoved || ( Math . abs ( deltaX ) > dragThreshold ||
1353
+ Math . abs ( deltaY ) > dragThreshold ) ) {
1354
+ this . _viewportHasMoved = true ;
1355
+
1356
+ this . _viewportDragPos = { 'x' : pos . x , 'y' : pos . y } ;
1357
+ this . _display . viewportChangePos ( deltaX , deltaY ) ;
1358
+ }
1359
+
1360
+ // Skip sending mouse events
1361
+ break ;
1362
+ }
1334
1363
this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1335
1364
break ;
1336
1365
case 'twodrag' :
@@ -1339,23 +1368,23 @@ export default class RFB extends EventTargetMixin {
1339
1368
// every update.
1340
1369
this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1341
1370
while ( ( ev . detail . magnitudeY - this . _gestureLastMagnitudeY ) > GESTURE_SCRLSENS ) {
1342
- this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x8 ) ;
1343
- this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x8 ) ;
1371
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask | 0x8 ) ;
1372
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask & ~ 0x8 ) ;
1344
1373
this . _gestureLastMagnitudeY += GESTURE_SCRLSENS ;
1345
1374
}
1346
1375
while ( ( ev . detail . magnitudeY - this . _gestureLastMagnitudeY ) < - GESTURE_SCRLSENS ) {
1347
- this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x10 ) ;
1348
- this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x10 ) ;
1376
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask | 0x10 ) ;
1377
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask & ~ 0x10 ) ;
1349
1378
this . _gestureLastMagnitudeY -= GESTURE_SCRLSENS ;
1350
1379
}
1351
1380
while ( ( ev . detail . magnitudeX - this . _gestureLastMagnitudeX ) > GESTURE_SCRLSENS ) {
1352
- this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x20 ) ;
1353
- this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x20 ) ;
1381
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask | 0x20 ) ;
1382
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask & ~ 0x20 ) ;
1354
1383
this . _gestureLastMagnitudeX += GESTURE_SCRLSENS ;
1355
1384
}
1356
1385
while ( ( ev . detail . magnitudeX - this . _gestureLastMagnitudeX ) < - GESTURE_SCRLSENS ) {
1357
- this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x40 ) ;
1358
- this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x40 ) ;
1386
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask | 0x40 ) ;
1387
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask & ~ 0x40 ) ;
1359
1388
this . _gestureLastMagnitudeX -= GESTURE_SCRLSENS ;
1360
1389
}
1361
1390
break ;
@@ -1368,13 +1397,13 @@ export default class RFB extends EventTargetMixin {
1368
1397
if ( Math . abs ( magnitude - this . _gestureLastMagnitudeX ) > GESTURE_ZOOMSENS ) {
1369
1398
this . _handleKeyEvent ( KeyTable . XK_Control_L , "ControlLeft" , true ) ;
1370
1399
while ( ( magnitude - this . _gestureLastMagnitudeX ) > GESTURE_ZOOMSENS ) {
1371
- this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x8 ) ;
1372
- this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x8 ) ;
1400
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask | 0x8 ) ;
1401
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask & ~ 0x8 ) ;
1373
1402
this . _gestureLastMagnitudeX += GESTURE_ZOOMSENS ;
1374
1403
}
1375
1404
while ( ( magnitude - this . _gestureLastMagnitudeX ) < - GESTURE_ZOOMSENS ) {
1376
- this . _handleMouseButton ( pos . x , pos . y , true , this . _mouseButtonMask | 0x10 ) ;
1377
- this . _handleMouseButton ( pos . x , pos . y , false , this . _mouseButtonMask & ~ 0x10 ) ;
1405
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask | 0x10 ) ;
1406
+ this . _handleMouseButton ( pos . x , pos . y , this . _mouseButtonMask & ~ 0x10 ) ;
1378
1407
this . _gestureLastMagnitudeX -= GESTURE_ZOOMSENS ;
1379
1408
}
1380
1409
}
@@ -1392,12 +1421,32 @@ export default class RFB extends EventTargetMixin {
1392
1421
case 'twodrag' :
1393
1422
break ;
1394
1423
case 'drag' :
1395
- this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1396
- this . _handleMouseButton ( pos . x , pos . y , false , 0x0 ) ;
1424
+ if ( this . dragViewport ) {
1425
+ this . _viewportDragging = false ;
1426
+ } else {
1427
+ this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1428
+ this . _handleMouseButton ( pos . x , pos . y , 0x0 ) ;
1429
+ }
1397
1430
break ;
1398
1431
case 'longpress' :
1399
- this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1400
- this . _handleMouseButton ( pos . x , pos . y , false , 0x0 ) ;
1432
+ if ( this . _viewportHasMoved ) {
1433
+ // We don't want to send any events if we have moved
1434
+ // our viewport
1435
+ break ;
1436
+ }
1437
+
1438
+ if ( this . dragViewport && ! this . _viewportHasMoved ) {
1439
+ this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1440
+ // If dragViewport is true, we need to wait to see
1441
+ // if we have dragged outside the threshold before
1442
+ // sending any events to the server.
1443
+ this . _handleMouseButton ( pos . x , pos . y , 0x4 ) ;
1444
+ this . _handleMouseButton ( pos . x , pos . y , 0x0 ) ;
1445
+ this . _viewportDragging = false ;
1446
+ } else {
1447
+ this . _fakeMouseMove ( ev , pos . x , pos . y ) ;
1448
+ this . _handleMouseButton ( pos . x , pos . y , 0x0 ) ;
1449
+ }
1401
1450
break ;
1402
1451
}
1403
1452
break ;
0 commit comments