summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2021-11-16 09:38:14 +0100
committerPierre Ossman <ossman@cendio.se>2021-11-16 09:38:14 +0100
commit301714928bfd45a0f11d8cbaec8f9fe538cefe79 (patch)
treea1cc7e127fba840cfda8c9faa2b0400979675502
parent096449da35aaac925aa3e1da515cc1585e6b54f7 (diff)
downloadnovnc-301714928bfd45a0f11d8cbaec8f9fe538cefe79.tar.gz
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.
-rw-r--r--core/rfb.js6
-rw-r--r--docs/API.md9
-rw-r--r--tests/test.rfb.js7
3 files changed, 18 insertions, 4 deletions
diff --git a/core/rfb.js b/core/rfb.js
index ea3bf58..084a457 100644
--- a/core/rfb.js
+++ b/core/rfb.js
@@ -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) {
diff --git a/docs/API.md b/docs/API.md
index aa5aea7..066e895 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -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()
diff --git a/tests/test.rfb.js b/tests/test.rfb.js
index 5f50581..f70bc14 100644
--- a/tests/test.rfb.js
+++ b/tests/test.rfb.js
@@ -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 () {