Prevent soft keyboard buttons from causing the page to scroll unnecessarily

This commit is contained in:
Jeff Parsons 2016-03-10 08:45:13 -08:00
commit d052b114c0

View file

@ -517,11 +517,15 @@ CPU.prototype.updateVideo = function(fForce)
}; };
/** /**
* setFocus() * setFocus(fScroll)
*
* NOTE: When soft keyboard buttons call us to return focus to the machine (and away from the button),
* the scroll feature has annoying effect on iOS, so we no longer do it by default (fScroll must be true).
* *
* @this {CPU} * @this {CPU}
* @param {boolean} [fScroll]
*/ */
CPU.prototype.setFocus = function() CPU.prototype.setFocus = function(fScroll)
{ {
if (this.aVideo.length) { if (this.aVideo.length) {
/* /*
@ -530,12 +534,12 @@ CPU.prototype.setFocus = function()
* is to ensure that keyboard input is fielded properly. * is to ensure that keyboard input is fielded properly.
*/ */
var x = 0, y = 0; var x = 0, y = 0;
if (window) { if (fScroll && window) {
x = window.scrollX; x = window.scrollX;
y = window.scrollY; y = window.scrollY;
} }
this.aVideo[0].setFocus(); this.aVideo[0].setFocus();
if (window) { if (fScroll && window) {
window.scrollTo(x, y); window.scrollTo(x, y);
} }
} }
@ -1127,7 +1131,7 @@ CPU.prototype.startCPU = function(fSetFocus)
var controlRun = this.bindings["run"]; var controlRun = this.bindings["run"];
if (controlRun) controlRun.textContent = "Halt"; if (controlRun) controlRun.textContent = "Halt";
this.updateStatus(true); this.updateStatus(true);
if (fSetFocus) this.setFocus(); if (fSetFocus) this.setFocus(true);
} }
}; };