Track touch vs mouse origins of field interactions

This commit is contained in:
Paul Kaplan 2019-07-26 13:55:21 -04:00
parent a9a9502543
commit 3ce3863ab6
4 changed files with 12 additions and 8 deletions

View file

@ -173,6 +173,14 @@ Blockly.Field.prototype.argType_ = null;
*/ */
Blockly.Field.prototype.validator_ = null; Blockly.Field.prototype.validator_ = null;
/**
* Whether to assume user is using a touch device for interactions.
* Used to show different UI for touch interactions, e.g.
* @type {boolean}
* @private
*/
Blockly.Field.prototype.useTouchInteraction_ = false;
/** /**
* Non-breaking space. * Non-breaking space.
* @const * @const
@ -740,6 +748,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) {
if (gesture) { if (gesture) {
gesture.setStartField(this); gesture.setStartField(this);
} }
this.useTouchInteraction_ = Blockly.Touch.getTouchIdentifierFromEvent(event) !== 'mouse';
}; };
/** /**

View file

@ -168,10 +168,8 @@ Blockly.FieldAngle.prototype.dispose_ = function() {
* @private * @private
*/ */
Blockly.FieldAngle.prototype.showEditor_ = function() { Blockly.FieldAngle.prototype.showEditor_ = function() {
var noFocus =
goog.userAgent.MOBILE || goog.userAgent.ANDROID || goog.userAgent.IPAD;
// Mobile browsers have issues with in-line textareas (focus & keyboards). // Mobile browsers have issues with in-line textareas (focus & keyboards).
Blockly.FieldAngle.superClass_.showEditor_.call(this, noFocus); Blockly.FieldAngle.superClass_.showEditor_.call(this, this.useTouchInteraction_);
// If there is an existing drop-down someone else owns, hide it immediately and clear it. // If there is an existing drop-down someone else owns, hide it immediately and clear it.
Blockly.DropDownDiv.hideWithoutAnimation(); Blockly.DropDownDiv.hideWithoutAnimation();
Blockly.DropDownDiv.clearContent(); Blockly.DropDownDiv.clearContent();

View file

@ -381,10 +381,8 @@ Blockly.FieldNote.prototype.dispose_ = function() {
* @private * @private
*/ */
Blockly.FieldNote.prototype.showEditor_ = function() { Blockly.FieldNote.prototype.showEditor_ = function() {
var noFocus =
goog.userAgent.MOBILE || goog.userAgent.ANDROID || goog.userAgent.IPAD;
// Mobile browsers have issues with in-line textareas (focus & keyboards). // Mobile browsers have issues with in-line textareas (focus & keyboards).
Blockly.FieldNote.superClass_.showEditor_.call(this, noFocus); Blockly.FieldNote.superClass_.showEditor_.call(this, this.useTouchInteraction_);
// If there is an existing drop-down someone else owns, hide it immediately and clear it. // If there is an existing drop-down someone else owns, hide it immediately and clear it.
Blockly.DropDownDiv.hideWithoutAnimation(); Blockly.DropDownDiv.hideWithoutAnimation();

View file

@ -165,8 +165,7 @@ Blockly.FieldNumber.prototype.setConstraints_ = function(opt_min, opt_max,
Blockly.FieldNumber.prototype.showEditor_ = function() { Blockly.FieldNumber.prototype.showEditor_ = function() {
Blockly.FieldNumber.activeField_ = this; Blockly.FieldNumber.activeField_ = this;
// Do not focus on mobile devices so we can show the num-pad // Do not focus on mobile devices so we can show the num-pad
var showNumPad = var showNumPad = this.useTouchInteraction_;
goog.userAgent.MOBILE || goog.userAgent.ANDROID || goog.userAgent.IPAD;
Blockly.FieldNumber.superClass_.showEditor_.call(this, false, showNumPad); Blockly.FieldNumber.superClass_.showEditor_.call(this, false, showNumPad);
// Show a numeric keypad in the drop-down on touch // Show a numeric keypad in the drop-down on touch