mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
Ignore everything but the first touch stream
This commit is contained in:
@@ -120,6 +120,12 @@ Blockly.dragMode_ = Blockly.DRAG_NONE;
|
||||
*/
|
||||
Blockly.onTouchUpWrapper_ = null;
|
||||
|
||||
/**
|
||||
* Which touch events are we currently paying attention to?
|
||||
* @type {?DOMString}
|
||||
*/
|
||||
Blockly.touchIdentifier_ = null;
|
||||
|
||||
/**
|
||||
* Convert a hue (HSV model) into an RGB hex triplet.
|
||||
* @param {number} hue Hue on a colour wheel (0-360).
|
||||
@@ -149,6 +155,38 @@ Blockly.resizeSvgContents = function(workspace) {
|
||||
workspace.resizeContents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether the touch identifier on the event matches the current saved
|
||||
* identifier. If there is no identifier, that means it's a mouse event and
|
||||
* we'll use the identifier "mouse". This means we won't deal well with
|
||||
* multiple mice being used at the same time. That seems okay.
|
||||
* If the current identifier was unset, save the identifier from the
|
||||
* event.
|
||||
* @param {!Event} e Mouse event or touch event.
|
||||
* @return {boolean} Whether the identifier on the event matches the current
|
||||
* saved identifier.
|
||||
*/
|
||||
Blockly.checkTouchIdentifier = function(e) {
|
||||
var identifier = (e.changedTouches && e.changedTouches.item(0) &&
|
||||
e.changedTouches.item(0).identifier != undefined) ?
|
||||
e.changedTouches.item(0).identifier : "mouse";
|
||||
if (Blockly.touchIdentifier_ != null &&
|
||||
Blockly.touchIdentifier_ != undefined) {
|
||||
// We're already tracking some touch/mouse event. Is this from the same
|
||||
// source?
|
||||
return Blockly.touchIdentifier_ == identifier;
|
||||
}
|
||||
if (e.type == "mousedown" || e.type == "touchstart") {
|
||||
// No identifier set yet, and this is the start of a drag. Set it and
|
||||
// return.
|
||||
Blockly.touchIdentifier_ = identifier;
|
||||
return true;
|
||||
}
|
||||
// There was no identifier yet, but this wasn't a start event so we're going
|
||||
// to ignore it. This probably means that another drag finished while this
|
||||
// pointer was down.
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Size the SVG image to completely fill its container. Call this when the view
|
||||
@@ -188,6 +226,7 @@ Blockly.svgResize = function(workspace) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.onMouseUp_ = function(e) {
|
||||
Blockly.touchIdentifier_ = null;
|
||||
var workspace = Blockly.getMainWorkspace();
|
||||
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
|
||||
workspace.dragMode_ = Blockly.DRAG_NONE;
|
||||
@@ -208,9 +247,6 @@ Blockly.onMouseUp_ = function(e) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.onMouseMove_ = function(e) {
|
||||
if (e.touches && e.touches.length >= 2) {
|
||||
return; // Multi-touch gestures won't have e.clientX.
|
||||
}
|
||||
var workspace = Blockly.getMainWorkspace();
|
||||
if (workspace.dragMode_ != Blockly.DRAG_NONE) {
|
||||
var dx = e.clientX - workspace.startDragMouseX;
|
||||
|
||||
Reference in New Issue
Block a user