Added support for paste to the VT100, but browser idiosyncrasies (eg, Chrome) are proving irksome; for now, you'll have more luck with Firefox, or sticking to machines that use a textarea for their I/O instead the VT100 if you need to do a lot of pasting

This commit is contained in:
Jeff Parsons 2016-11-25 18:28:57 -08:00 committed by Jeff Parsons
commit 66f82736c9
6 changed files with 417 additions and 364 deletions

View file

@ -353,6 +353,9 @@ Keyboard8080.prototype.setBinding = function(sHTMLType, sBinding, control, sValu
control.onkeypress = function onKeyPress(event) {
return kbd.onKeyPress(event);
};
control.onpaste = function onKeyPaste(event) {
return kbd.onPaste(event);
};
return true;
default:
@ -423,6 +426,8 @@ Keyboard8080.prototype.initBus = function(cmp, bus, cpu, dbg)
this.chipset = /** @type {ChipSet8080} */ (cmp.getMachineComponent("ChipSet"));
this.serial = /** @type {SerialPort8080} */ (cmp.getMachineComponent("SerialPort"));
bus.addPortInputTable(this, this.config.portsInput);
bus.addPortOutputTable(this, this.config.portsOutput);
};
@ -612,11 +617,17 @@ Keyboard8080.prototype.checkModifierKeys = function(softCode, fDown, fRight)
{
var bit = 0;
switch(softCode) {
case Keys.KEYCODE.SHIFT:
bit = fRight? Keyboard8080.STATE.RSHIFT : Keyboard8080.STATE.SHIFT;
break;
case Keys.KEYCODE.CTRL:
bit = fRight? Keyboard8080.STATE.RCTRL : Keyboard8080.STATE.CTRL;
break;
case Keys.KEYCODE.SHIFT:
bit = fRight? Keyboard8080.STATE.RSHIFT : Keyboard8080.STATE.SHIFT;
case Keys.KEYCODE.ALT:
bit = fRight? Keyboard8080.STATE.RALT : Keyboard8080.STATE.ALT;
break;
case Keys.KEYCODE.CMD:
bit = fRight? Keyboard8080.STATE.RCMD : Keyboard8080.STATE.CMD;
break;
case Keys.KEYCODE.CAPS_LOCK:
bit = Keyboard8080.STATE.CAPS_LOCK;
@ -674,19 +685,22 @@ Keyboard8080.prototype.onKeyDown = function(event, fDown)
* for a new pair of services to eventually be implemented: simulateKeysDown() and simulateKeysUp().
*/
this.checkModifierKeys(softCode, fDown, event.location == Keys.LOCATION.RIGHT);
fPass = this.onSoftKeyDown(softCode, fDown);
/*
* As onKeyPress() explains, the only key presses we're interested in are letters, which provide
* an important clue regarding the CAPS-LOCK state. For all other keys, we call preventDefault(),
* which "suppresses" the keyPress event.
*/
if (softCode < Keys.ASCII.A || softCode > Keys.ASCII.Z) {
event.preventDefault();
if (!event.metaKey) {
fPass = this.onSoftKeyDown(softCode, fDown);
/*
* As onKeyPress() explains, the only key presses we're interested in are letters, which provide
* an important clue regarding the CAPS-LOCK state. For all other keys, we call preventDefault(),
* which "suppresses" the keyPress event.
*/
if (!(softCode >= Keys.ASCII.A && softCode <= Keys.ASCII.Z)) {
event.preventDefault();
}
}
}
if (!COMPILED && this.messageEnabled(Messages8080.KEYS)) {
this.printMessage("onKey" + (fDown? "Down" : "Up") + "(" + keyCode + "): softCode=" + softCode + ", pass=" + (fPass? "true" : "false"), true);
this.printMessage("onKey" + (fDown? "Down" : "Up") + "(" + keyCode + "): softCode=" + softCode + ", pass=" + fPass, true);
}
return fPass;
@ -721,6 +735,39 @@ Keyboard8080.prototype.onKeyPress = function(event)
return true;
};
/**
* onPaste(event)
*
* @this {Keyboard8080}
* @param {Object} event
* @return {boolean} true to pass the event along, false to consume it
*/
Keyboard8080.prototype.onPaste = function(event) {
/*
* TODO: In a perfect world, we would have implemented simulateKeysDown() and simulateKeysUp(),
* which would transform any given text into the appropriate keystrokes. But for now, we're going
* to leapfrog all that and try invoking the SerialPort's sendData() function, which if available,
* is nothing more than a call into a connected machine's receiveData() function.
*
* Besides, paste functionality doesn't seem to be consistently implemented across all browsers
* (partly out of security concerns, apparently) so it may not make sense to expend much more
* effort on this right now. If you want to paste a lot of text into a machine, you're better off
* pasting into a machine that's been configured to use a textarea as part of its Control Panel.
* A visible textarea seems to have less issues than the hidden textarea overlaid on top of our
* Video display.
*/
if (this.serial && this.serial.sendData) {
if (event.stopPropagation) event.stopPropagation();
if (event.preventDefault) event.preventDefault();
var clipboardData = event.clipboardData || window.clipboardData;
if (clipboardData) {
this.serial.transmitData(clipboardData.getData('Text'));
return false;
}
}
return true;
};
/**
* indexOfSoftKey(softCode)
*

View file

@ -751,7 +751,7 @@ SerialPort8080.prototype.transmitByte = function(b)
};
/**
* transmitData()
* transmitData(sData)
*
* Helper for clocking transmitted data at the expected XMIT_RATE.
*
@ -759,10 +759,16 @@ SerialPort8080.prototype.transmitByte = function(b)
* set XMIT_READY (and XMIT_EMPTY), which signals the firmware that another byte can be transmitted.
*
* @this {SerialPort8080}
* @param {string} [sData]
* @return {boolean} true if successful, false if not
*/
SerialPort8080.prototype.transmitData = function()
SerialPort8080.prototype.transmitData = function(sData)
{
this.bStatus |= (SerialPort8080.UART8251.STATUS.XMIT_READY | SerialPort8080.UART8251.STATUS.XMIT_EMPTY);
if (sData) {
return this.sendData? this.sendData.call(this.connection, sData) : false;
}
return true;
};
/**

View file

@ -215,7 +215,7 @@ function Video8080(parmsVideo, canvas, context, textarea, container)
if ('on' + sEvent in document) {
var onFullScreenChange = function() {
var fFullScreen = (document['fullscreenElement'] || document['msFullscreenElement'] || document['mozFullScreenElement'] || document['webkitFullscreenElement']);
video.notifyFullScreen(fFullScreen? true : false);
video.notifyFullScreen(!!fFullScreen);
};
document.addEventListener(sEvent, onFullScreenChange, false);
break;