Avoid scrolling on RFB object focus

Chrome scrolls the view to show as much as possible of the canvas when
we call focus(), which is likely not the desired behaviour.

This also exposes the ability to pass on future options when focusing
the RFB object manually.
This commit is contained in:
Pierre Ossman 2021-11-16 09:38:14 +01:00
parent 096449da35
commit 301714928b
3 changed files with 18 additions and 4 deletions

View File

@ -432,8 +432,8 @@ export default class RFB extends EventTargetMixin {
}
}
focus() {
this._canvas.focus();
focus(options) {
this._canvas.focus(options);
}
blur() {
@ -609,7 +609,7 @@ export default class RFB extends EventTargetMixin {
return;
}
this.focus();
this.focus({ preventScroll: true });
}
_setDesktopName(name) {

View File

@ -328,7 +328,14 @@ Keyboard events will be sent to the remote server after this point.
##### Syntax
RFB.focus( );
RFB.focus( [options] );
###### Parameters
**`options`** *Optional*
- A `object` providing options to control how the focus will be
performed. Please see [`HTMLElement.focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus)
for available options.
#### RFB.blur()

View File

@ -392,6 +392,13 @@ describe('Remote Frame Buffer Protocol Client', function () {
client.focus();
expect(client._canvas.focus).to.have.been.calledOnce;
});
it('should include focus options', function () {
client._canvas.focus = sinon.spy();
client.focus({ foobar: 12, gazonk: true });
expect(client._canvas.focus).to.have.been.calledOnce;
expect(client._canvas.focus).to.have.been.calledWith({ foobar: 12, gazonk: true});
});
});
describe('#blur', function () {