Added scroll delta mode constants.

This commit is contained in:
Beka Westberg
2019-02-21 07:35:44 -08:00
parent 570eecbff8
commit 4e7e712549
5 changed files with 48 additions and 23 deletions

View File

@@ -304,6 +304,32 @@ Blockly.utils.mouseToSvg = function(e, svg, matrix) {
return svgPoint.matrixTransform(matrix);
};
/**
* Get the scroll delta of a mouse event in pixel units.
* @param {!Event} e Mouse event.
* @return {{x: number, y: number}} Scroll delta object with .x and .y
* properties.
*/
Blockly.utils.getScrollDeltaPixels = function(e) {
switch (e.deltaMode) {
case 0x00: // Pixel mode.
return {
x: e.deltaX,
y: e.deltaY
};
case 0x01: // Line mode.
return {
x: e.deltaX * Blockly.LINE_MODE_MULTIPLIER,
y: e.deltaY * Blockly.LINE_MODE_MULTIPLIER
};
case 0x02: // Page mode.
return {
x: e.deltaX * Blockly.PAGE_MODE_MULTIPLIER,
y: e.deltaY * Blockly.PAGE_MODE_MULTIPLIER
};
}
};
/**
* Given an array of strings, return the length of the shortest one.
* @param {!Array.<string>} array Array of strings.