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

View File

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

View File

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

View File

@ -82,14 +82,14 @@ None
### 2.3.1 Configuration Attributes ### 2.3.1 Configuration Attributes
| name | type | mode | default | description | name | type | mode | default | description
| ----------- | ----- | ---- | ------- | ------------ | ------------ | ----- | ---- | ------- | ------------
| logo | raw | RW | | Logo to display when cleared: {"width": width, "height": height, "type": mime-type, "data": data} | 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 | scale | float | RW | 1.0 | Display area scale factor 0.0 - 1.0
| viewport | bool | RW | false | Use viewport clipping | clipViewport | bool | RW | false | Use viewport clipping
| width | int | RO | | Display area width | width | int | RO | | Display area width
| height | int | RO | | Display area height | height | int | RO | | Display area height
| isClipped | bool | RO | | Is the remote display is larger than the client display | isClipped | bool | RO | | Is the remote display is larger than the client display
### 2.3.2 Methods ### 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). [`MouseEvent.button`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button).
Is set to `1` by default. Is set to `1` by default.
`scale` `viewportScale`
- Is a `double` indicating how the framebuffer contents should be - Is a `double` indicating how the framebuffer contents should be
scaled before being rendered on to the canvas. See also scaled before being rendered on to the canvas. See also
[`RFB.autoscale()`](#rfbautoscale). Is set to `1.0` by default. [`RFB.autoscale()`](#rfbautoscale). Is set to `1.0` by default.
`viewport` `clipViewport`
- Is a `boolean` indicating if the canvas should be clipped to its - Is a `boolean` indicating if the canvas should be clipped to its
container. When disabled the container must be able to handle the container. When disabled the container must be able to handle the
resulting overflow. Disabled by default. resulting overflow. Disabled by default.
`viewportDrag` `dragViewport`
- Is a `boolean` indicating if mouse events should control the - Is a `boolean` indicating if mouse events should control the
relative position of a clipped canvas. Only relevant if `viewport` relative position of a clipped canvas. Only relevant if
is enabled. Disabled by default. `clipViewport` is enabled. Disabled by default.
`isClipped` *Read only* `isClipped` *Read only*
- Is a `boolean` indicating if the framebuffer is larger than the - Is a `boolean` indicating if the framebuffer is larger than the
@ -130,7 +130,8 @@ protocol stream.
- Send clipboard contents to server. - Send clipboard contents to server.
[`RFB.autoscale()`](#rfbautoscale) [`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) [`RFB.requestDesktopSize()`](#rfbrequestDesktopSize)
- Send a request to change the remote desktop size. - Send a request to change the remote desktop size.
@ -409,7 +410,7 @@ to the remote server.
#### RFB.autoscale() #### RFB.autoscale()
The `RFB.autoscale()` method is used to automatically adjust The `RFB.autoscale()` method is used to automatically adjust
`RFB.scale` to fit given dimensions. `RFB.viewportScale` to fit given dimensions.
##### Syntax ##### Syntax
@ -453,7 +454,7 @@ actually changes dimensions.
The `RFB.viewportChangeSize()` method is used to change the size of the The `RFB.viewportChangeSize()` method is used to change the size of the
canvas rather than the underlying framebuffer. 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 ##### Syntax

View File

@ -40,7 +40,7 @@ describe('Display/Canvas Helper', function () {
var display; var display;
beforeEach(function () { beforeEach(function () {
display = new Display(document.createElement('canvas')); display = new Display(document.createElement('canvas'));
display.viewport = true; display.clipViewport = true;
display.resize(5, 5); display.resize(5, 5);
display.viewportChangeSize(3, 3); display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1); display.viewportChangePos(1, 1);
@ -101,7 +101,7 @@ describe('Display/Canvas Helper', function () {
}); });
it('should show the entire framebuffer when disabling the viewport', 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.absX(0)).to.equal(0);
expect(display.absY(0)).to.equal(0); expect(display.absY(0)).to.equal(0);
expect(display._target.width).to.equal(5); 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() { it('should ignore viewport changes when the viewport is disabled', function() {
display.viewport = false; display.clipViewport = false;
display.viewportChangeSize(2, 2); display.viewportChangeSize(2, 2);
display.viewportChangePos(1, 1); display.viewportChangePos(1, 1);
expect(display.absX(0)).to.equal(0); 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() { it('should show the entire framebuffer just after enabling the viewport', function() {
display.viewport = false; display.clipViewport = false;
display.viewport = true; display.clipViewport = true;
expect(display.absX(0)).to.equal(0); expect(display.absX(0)).to.equal(0);
expect(display.absY(0)).to.equal(0); expect(display.absY(0)).to.equal(0);
expect(display._target.width).to.equal(5); expect(display._target.width).to.equal(5);
@ -132,7 +132,7 @@ describe('Display/Canvas Helper', function () {
var display; var display;
beforeEach(function () { beforeEach(function () {
display = new Display(document.createElement('canvas')); display = new Display(document.createElement('canvas'));
display.viewport = false; display.clipViewport = false;
display.resize(4, 4); display.resize(4, 4);
}); });
@ -157,7 +157,7 @@ describe('Display/Canvas Helper', function () {
describe('viewport', function () { describe('viewport', function () {
beforeEach(function () { beforeEach(function () {
display.viewport = true; display.clipViewport = true;
display.viewportChangeSize(3, 3); display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1); display.viewportChangePos(1, 1);
}); });
@ -195,7 +195,7 @@ describe('Display/Canvas Helper', function () {
beforeEach(function () { beforeEach(function () {
canvas = document.createElement('canvas'); canvas = document.createElement('canvas');
display = new Display(canvas); display = new Display(canvas);
display.viewport = true; display.clipViewport = true;
display.resize(4, 4); display.resize(4, 4);
display.viewportChangeSize(3, 3); display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1); display.viewportChangePos(1, 1);
@ -236,7 +236,7 @@ describe('Display/Canvas Helper', function () {
beforeEach(function () { beforeEach(function () {
canvas = document.createElement('canvas'); canvas = document.createElement('canvas');
display = new Display(canvas); display = new Display(canvas);
display.viewport = true; display.clipViewport = true;
display.resize(4, 3); display.resize(4, 3);
document.body.appendChild(canvas); 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 () { it('should not send button messages when initiating viewport dragging', function () {
client._viewportDrag = true; client.dragViewport = true;
client._handleMouseButton(13, 9, 0x001); client._handleMouseButton(13, 9, 0x001);
expect(client._sock.flush).to.not.have.been.called; expect(client._sock.flush).to.not.have.been.called;
}); });
it('should be initiate viewport dragging on a button down event, if enabled', function () { 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); client._handleMouseButton(13, 9, 0x001);
expect(client._viewportDragging).to.be.true; expect(client._viewportDragging).to.be.true;
expect(client._viewportDragPos).to.deep.equal({ x: 13, y: 9 }); expect(client._viewportDragPos).to.deep.equal({ x: 13, y: 9 });
}); });
it('should terminate viewport dragging on a button up event, if enabled', function () { it('should terminate viewport dragging on a button up event, if enabled', function () {
client._viewportDrag = true; client.dragViewport = true;
client._viewportDragging = true; client._viewportDragging = true;
client._handleMouseButton(13, 9, 0x000); client._handleMouseButton(13, 9, 0x000);
expect(client._viewportDragging).to.be.false; expect(client._viewportDragging).to.be.false;
@ -1917,7 +1917,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
var newX = 123 + 11 * window.devicePixelRatio; var newX = 123 + 11 * window.devicePixelRatio;
var newY = 109 + 4 * window.devicePixelRatio; var newY = 109 + 4 * window.devicePixelRatio;
client._viewportDrag = true; client.dragViewport = true;
client._viewportDragging = true; client._viewportDragging = true;
client._viewportHasMoved = false; client._viewportHasMoved = false;
client._viewportDragPos = { x: oldX, y: oldY }; client._viewportDragPos = { x: oldX, y: oldY };