Improve naming for viewport properties

This commit is contained in:
Pierre Ossman 2017-10-20 13:12:30 +02:00
parent a80aa41628
commit 0460e5fdbe
7 changed files with 51 additions and 50 deletions

View File

@ -1224,7 +1224,7 @@ var UI = {
if (screen && UI.connected) {
var resizeMode = UI.getSetting('resize');
UI.rfb.scale = 1.0;
UI.rfb.viewportScale = 1.0;
// Make sure the viewport is adjusted first
UI.updateViewClip();
@ -1306,7 +1306,7 @@ var UI = {
updateViewClip: function() {
if (!UI.rfb) return;
var cur_clip = UI.rfb.viewport;
var cur_clip = UI.rfb.clipViewport;
var new_clip = UI.getSetting('view_clip');
var resizeSetting = UI.getSetting('resize');
@ -1319,7 +1319,7 @@ var UI = {
}
if (cur_clip !== new_clip) {
UI.rfb.viewport = new_clip;
UI.rfb.clipViewport = new_clip;
}
var size = UI.screenSize();
@ -1357,7 +1357,7 @@ var UI = {
toggleViewDrag: function() {
if (!UI.rfb) return;
var drag = UI.rfb.viewportDrag;
var drag = UI.rfb.dragViewport;
UI.setViewDrag(!drag);
},
@ -1365,7 +1365,7 @@ var UI = {
setViewDrag: function(drag) {
if (!UI.rfb) return;
UI.rfb.viewportDrag = drag;
UI.rfb.dragViewport = drag;
UI.updateViewDrag();
},
@ -1377,21 +1377,21 @@ var UI = {
// Check if viewport drag is possible. It is only possible
// if the remote display is clipping the client display.
if (UI.rfb.viewport && UI.rfb.isClipped) {
if (UI.rfb.clipViewport && UI.rfb.isClipped) {
clipping = true;
}
var viewDragButton = document.getElementById('noVNC_view_drag_button');
if (!clipping &&
UI.rfb.viewportDrag) {
UI.rfb.dragViewport) {
// The size of the remote display is the same or smaller
// than the client display. Make sure viewport drag isn't
// active when it can't be used.
UI.rfb.viewportDrag = false;
UI.rfb.dragViewport = false;
}
if (UI.rfb.viewportDrag) {
if (UI.rfb.dragViewport) {
viewDragButton.classList.add("noVNC_selected");
} else {
viewDragButton.classList.remove("noVNC_selected");

View File

@ -89,10 +89,10 @@ Display.prototype = {
this._rescale(scale);
},
_viewport: false,
get viewport() { return this._viewport; },
set viewport(viewport) {
this._viewport = viewport;
_clipViewport: false,
get clipViewport() { return this._clipViewport; },
set clipViewport(viewport) {
this._clipViewport = viewport;
// May need to readjust the viewport dimensions
var vp = this._viewportLoc;
this.viewportChangeSize(vp.w, vp.h);
@ -124,7 +124,7 @@ Display.prototype = {
deltaX = Math.floor(deltaX);
deltaY = Math.floor(deltaY);
if (!this._viewport) {
if (!this._clipViewport) {
deltaX = -vp.w; // clamped later of out of bounds
deltaY = -vp.h;
}
@ -163,7 +163,7 @@ Display.prototype = {
viewportChangeSize: function(width, height) {
if (!this._viewport ||
if (!this._clipViewport ||
typeof(width) === "undefined" ||
typeof(height) === "undefined") {

View File

@ -217,7 +217,7 @@ RFB.prototype = {
// ===== PROPERTIES =====
disconnectTimeout: 3,
viewportDrag: false,
dragViewport: false,
_localCursor: false,
get localCursor() { return this._localCursor; },
@ -262,11 +262,11 @@ RFB.prototype = {
get touchButton() { return this._mouse.touchButton; },
set touchButton(button) { this._mouse.touchButton = button; },
get scale() { return this._display.scale; },
set scale(scale) { this._display.scale = scale; },
get viewportScale() { return this._display.scale; },
set viewportScale(scale) { this._display.scale = scale; },
get viewport() { return this._display.viewport; },
set viewport(viewport) { this._display.viewport = viewport; },
get clipViewport() { return this._display.clipViewport; },
set clipViewport(viewport) { this._display.clipViewport = viewport; },
get isClipped() { return this._display.isClipped; },
@ -679,7 +679,7 @@ RFB.prototype = {
this._mouse_buttonMask &= ~bmask;
}
if (this._viewportDrag) {
if (this.dragViewport) {
if (down && !this._viewportDragging) {
this._viewportDragging = true;
this._viewportDragPos = {'x': x, 'y': y};

View File

@ -82,14 +82,14 @@ None
### 2.3.1 Configuration Attributes
| name | type | mode | default | description
| ----------- | ----- | ---- | ------- | ------------
| logo | raw | RW | | Logo to display when cleared: {"width": width, "height": height, "type": mime-type, "data": data}
| scale | float | RW | 1.0 | Display area scale factor 0.0 - 1.0
| viewport | bool | RW | false | Use viewport clipping
| width | int | RO | | Display area width
| height | int | RO | | Display area height
| isClipped | bool | RO | | Is the remote display is larger than the client display
| name | type | mode | default | description
| ------------ | ----- | ---- | ------- | ------------
| logo | raw | RW | | Logo to display when cleared: {"width": width, "height": height, "type": mime-type, "data": data}
| scale | float | RW | 1.0 | Display area scale factor 0.0 - 1.0
| clipViewport | bool | RW | false | Use viewport clipping
| width | int | RO | | Display area width
| height | int | RO | | Display area height
| isClipped | bool | RO | | Is the remote display is larger than the client display
### 2.3.2 Methods

View File

@ -31,20 +31,20 @@ protocol stream.
[`MouseEvent.button`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button).
Is set to `1` by default.
`scale`
`viewportScale`
- Is a `double` indicating how the framebuffer contents should be
scaled before being rendered on to the canvas. See also
[`RFB.autoscale()`](#rfbautoscale). Is set to `1.0` by default.
`viewport`
`clipViewport`
- Is a `boolean` indicating if the canvas should be clipped to its
container. When disabled the container must be able to handle the
resulting overflow. Disabled by default.
`viewportDrag`
`dragViewport`
- Is a `boolean` indicating if mouse events should control the
relative position of a clipped canvas. Only relevant if `viewport`
is enabled. Disabled by default.
relative position of a clipped canvas. Only relevant if
`clipViewport` is enabled. Disabled by default.
`isClipped` *Read only*
- Is a `boolean` indicating if the framebuffer is larger than the
@ -130,7 +130,8 @@ protocol stream.
- Send clipboard contents to server.
[`RFB.autoscale()`](#rfbautoscale)
- Set `RFB.scale` so that the framebuffer fits a specified container.
- Set `RFB.viewportScale` so that the framebuffer fits a specified
container.
[`RFB.requestDesktopSize()`](#rfbrequestDesktopSize)
- Send a request to change the remote desktop size.
@ -409,7 +410,7 @@ to the remote server.
#### RFB.autoscale()
The `RFB.autoscale()` method is used to automatically adjust
`RFB.scale` to fit given dimensions.
`RFB.viewportScale` to fit given dimensions.
##### Syntax
@ -453,7 +454,7 @@ actually changes dimensions.
The `RFB.viewportChangeSize()` method is used to change the size of the
canvas rather than the underlying framebuffer.
This method has no effect if `RFB.viewport` is set to `false`.
This method has no effect if `RFB.clipViewport` is set to `false`.
##### Syntax

View File

@ -40,7 +40,7 @@ describe('Display/Canvas Helper', function () {
var display;
beforeEach(function () {
display = new Display(document.createElement('canvas'));
display.viewport = true;
display.clipViewport = true;
display.resize(5, 5);
display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1);
@ -101,7 +101,7 @@ describe('Display/Canvas Helper', function () {
});
it('should show the entire framebuffer when disabling the viewport', function() {
display.viewport = false;
display.clipViewport = false;
expect(display.absX(0)).to.equal(0);
expect(display.absY(0)).to.equal(0);
expect(display._target.width).to.equal(5);
@ -109,7 +109,7 @@ describe('Display/Canvas Helper', function () {
});
it('should ignore viewport changes when the viewport is disabled', function() {
display.viewport = false;
display.clipViewport = false;
display.viewportChangeSize(2, 2);
display.viewportChangePos(1, 1);
expect(display.absX(0)).to.equal(0);
@ -119,8 +119,8 @@ describe('Display/Canvas Helper', function () {
});
it('should show the entire framebuffer just after enabling the viewport', function() {
display.viewport = false;
display.viewport = true;
display.clipViewport = false;
display.clipViewport = true;
expect(display.absX(0)).to.equal(0);
expect(display.absY(0)).to.equal(0);
expect(display._target.width).to.equal(5);
@ -132,7 +132,7 @@ describe('Display/Canvas Helper', function () {
var display;
beforeEach(function () {
display = new Display(document.createElement('canvas'));
display.viewport = false;
display.clipViewport = false;
display.resize(4, 4);
});
@ -157,7 +157,7 @@ describe('Display/Canvas Helper', function () {
describe('viewport', function () {
beforeEach(function () {
display.viewport = true;
display.clipViewport = true;
display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1);
});
@ -195,7 +195,7 @@ describe('Display/Canvas Helper', function () {
beforeEach(function () {
canvas = document.createElement('canvas');
display = new Display(canvas);
display.viewport = true;
display.clipViewport = true;
display.resize(4, 4);
display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1);
@ -236,7 +236,7 @@ describe('Display/Canvas Helper', function () {
beforeEach(function () {
canvas = document.createElement('canvas');
display = new Display(canvas);
display.viewport = true;
display.clipViewport = true;
display.resize(4, 3);
document.body.appendChild(canvas);
});

View File

@ -1892,20 +1892,20 @@ describe('Remote Frame Buffer Protocol Client', function() {
});
it('should not send button messages when initiating viewport dragging', function () {
client._viewportDrag = true;
client.dragViewport = true;
client._handleMouseButton(13, 9, 0x001);
expect(client._sock.flush).to.not.have.been.called;
});
it('should be initiate viewport dragging on a button down event, if enabled', function () {
client._viewportDrag = true;
client.dragViewport = true;
client._handleMouseButton(13, 9, 0x001);
expect(client._viewportDragging).to.be.true;
expect(client._viewportDragPos).to.deep.equal({ x: 13, y: 9 });
});
it('should terminate viewport dragging on a button up event, if enabled', function () {
client._viewportDrag = true;
client.dragViewport = true;
client._viewportDragging = true;
client._handleMouseButton(13, 9, 0x000);
expect(client._viewportDragging).to.be.false;
@ -1917,7 +1917,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
var newX = 123 + 11 * window.devicePixelRatio;
var newY = 109 + 4 * window.devicePixelRatio;
client._viewportDrag = true;
client.dragViewport = true;
client._viewportDragging = true;
client._viewportHasMoved = false;
client._viewportDragPos = { x: oldX, y: oldY };