MCPcopy Create free account
hub / github.com/apache/cloudstack / _handleWheel

Method _handleWheel

systemvm/agent/noVNC/core/rfb.js:1383–1438  ·  view source on GitHub ↗
(ev)

Source from the content-addressed store, hash-verified

1381 }
1382
1383 _handleWheel(ev) {
1384 if (this._rfbConnectionState !== 'connected') { return; }
1385 if (this._viewOnly) { return; } // View only, skip mouse events
1386
1387 ev.stopPropagation();
1388 ev.preventDefault();
1389
1390 let pos = clientToElement(ev.clientX, ev.clientY,
1391 this._canvas);
1392
1393 let bmask = RFB._convertButtonMask(ev.buttons);
1394 let dX = ev.deltaX;
1395 let dY = ev.deltaY;
1396
1397 // Pixel units unless it's non-zero.
1398 // Note that if deltamode is line or page won't matter since we aren't
1399 // sending the mouse wheel delta to the server anyway.
1400 // The difference between pixel and line can be important however since
1401 // we have a threshold that can be smaller than the line height.
1402 if (ev.deltaMode !== 0) {
1403 dX *= WHEEL_LINE_HEIGHT;
1404 dY *= WHEEL_LINE_HEIGHT;
1405 }
1406
1407 // Mouse wheel events are sent in steps over VNC. This means that the VNC
1408 // protocol can't handle a wheel event with specific distance or speed.
1409 // Therefor, if we get a lot of small mouse wheel events we combine them.
1410 this._accumulatedWheelDeltaX += dX;
1411 this._accumulatedWheelDeltaY += dY;
1412
1413
1414 // Generate a mouse wheel step event when the accumulated delta
1415 // for one of the axes is large enough.
1416 if (Math.abs(this._accumulatedWheelDeltaX) >= WHEEL_STEP) {
1417 if (this._accumulatedWheelDeltaX < 0) {
1418 this._handleMouseButton(pos.x, pos.y, bmask | 1 << 5);
1419 this._handleMouseButton(pos.x, pos.y, bmask);
1420 } else if (this._accumulatedWheelDeltaX > 0) {
1421 this._handleMouseButton(pos.x, pos.y, bmask | 1 << 6);
1422 this._handleMouseButton(pos.x, pos.y, bmask);
1423 }
1424
1425 this._accumulatedWheelDeltaX = 0;
1426 }
1427 if (Math.abs(this._accumulatedWheelDeltaY) >= WHEEL_STEP) {
1428 if (this._accumulatedWheelDeltaY < 0) {
1429 this._handleMouseButton(pos.x, pos.y, bmask | 1 << 3);
1430 this._handleMouseButton(pos.x, pos.y, bmask);
1431 } else if (this._accumulatedWheelDeltaY > 0) {
1432 this._handleMouseButton(pos.x, pos.y, bmask | 1 << 4);
1433 this._handleMouseButton(pos.x, pos.y, bmask);
1434 }
1435
1436 this._accumulatedWheelDeltaY = 0;
1437 }
1438 }
1439
1440 _fakeMouseMove(ev, elementX, elementY) {

Callers

nothing calls this directly

Calls 3

_handleMouseButtonMethod · 0.95
clientToElementFunction · 0.90
_convertButtonMaskMethod · 0.80

Tested by

no test coverage detected