Remove max dimension handling
The viewport handling is now a lot clearer, so simply limit the size of the viewport in the caller rather than having this extra layer of checks.
This commit is contained in:
parent
e549ae074f
commit
3f781f2aa3
10
app/ui.js
10
app/ui.js
|
@ -1107,11 +1107,6 @@ var UI;
|
|||
// is finished we wait 0.5 seconds before sending the request.
|
||||
clearTimeout(UI.resizeTimeout);
|
||||
UI.resizeTimeout = setTimeout(function(){
|
||||
|
||||
// Limit the viewport to the size of the browser window
|
||||
display.set_maxWidth(screen.w);
|
||||
display.set_maxHeight(screen.h);
|
||||
|
||||
// Request a remote size covering the viewport
|
||||
if (UI.rfb.requestDesktopSize(screen.w, screen.h)) {
|
||||
Util.Debug('Requested new desktop size: ' +
|
||||
|
@ -1192,8 +1187,6 @@ var UI;
|
|||
if (new_clip && size) {
|
||||
// When clipping is enabled, the screen is limited to
|
||||
// the size of the browser window.
|
||||
display.set_maxWidth(size.w);
|
||||
display.set_maxHeight(size.h);
|
||||
|
||||
var screen = document.getElementById('noVNC_screen');
|
||||
var canvas = document.getElementById('noVNC_canvas');
|
||||
|
@ -1209,9 +1202,6 @@ var UI;
|
|||
|
||||
display.viewportChangeSize(new_w, size.h);
|
||||
} else {
|
||||
// Disable max dimensions
|
||||
display.set_maxWidth(0);
|
||||
display.set_maxHeight(0);
|
||||
display.viewportChangeSize();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -26,10 +26,6 @@
|
|||
this._fb_width = 0;
|
||||
this._fb_height = 0;
|
||||
|
||||
// the size limit of the viewport (start disabled)
|
||||
this._maxWidth = 0;
|
||||
this._maxHeight = 0;
|
||||
|
||||
// the visible "physical canvas" viewport
|
||||
this._viewportLoc = { 'x': 0, 'y': 0, 'w': 0, 'h': 0 };
|
||||
|
||||
|
@ -169,16 +165,6 @@
|
|||
|
||||
var vp = this._viewportLoc;
|
||||
if (vp.w !== width || vp.h !== height) {
|
||||
|
||||
if (this._viewport) {
|
||||
if (this._maxWidth !== 0 && width > this._maxWidth) {
|
||||
width = this._maxWidth;
|
||||
}
|
||||
if (this._maxHeight !== 0 && height > this._maxHeight) {
|
||||
height = this._maxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
vp.w = width;
|
||||
vp.h = height;
|
||||
|
||||
|
@ -553,16 +539,7 @@
|
|||
|
||||
clippingDisplay: function () {
|
||||
var vp = this._viewportLoc;
|
||||
|
||||
var fbClip = this._fb_width > vp.w || this._fb_height > vp.h;
|
||||
var limitedVp = this._maxWidth !== 0 && this._maxHeight !== 0;
|
||||
var clipping = false;
|
||||
|
||||
if (limitedVp) {
|
||||
clipping = vp.w > this._maxWidth || vp.h > this._maxHeight;
|
||||
}
|
||||
|
||||
return fbClip || (limitedVp && clipping);
|
||||
return this._fb_width > vp.w || this._fb_height > vp.h;
|
||||
},
|
||||
|
||||
// Overridden getters/setters
|
||||
|
@ -616,21 +593,9 @@
|
|||
// Private Methods
|
||||
_rescale: function (factor) {
|
||||
this._scale = factor;
|
||||
|
||||
var w;
|
||||
var h;
|
||||
|
||||
if (this._viewport &&
|
||||
this._maxWidth !== 0 && this._maxHeight !== 0) {
|
||||
w = Math.min(this._fb_width, this._maxWidth);
|
||||
h = Math.min(this._fb_height, this._maxHeight);
|
||||
} else {
|
||||
w = this._fb_width;
|
||||
h = this._fb_height;
|
||||
}
|
||||
|
||||
this._target.style.width = Math.round(factor * w) + 'px';
|
||||
this._target.style.height = Math.round(factor * h) + 'px';
|
||||
var vp = this._viewportLoc;
|
||||
this._target.style.width = Math.round(factor * vp.w) + 'px';
|
||||
this._target.style.height = Math.round(factor * vp.h) + 'px';
|
||||
},
|
||||
|
||||
_setFillColor: function (color) {
|
||||
|
@ -776,8 +741,6 @@
|
|||
['viewport', 'rw', 'bool'], // Use viewport clipping
|
||||
['width', 'ro', 'int'], // Display area width
|
||||
['height', 'ro', 'int'], // Display area height
|
||||
['maxWidth', 'rw', 'int'], // Viewport max width (0 if disabled)
|
||||
['maxHeight', 'rw', 'int'], // Viewport max height (0 if disabled)
|
||||
|
||||
['render_mode', 'ro', 'str'], // Canvas rendering mode (read-only)
|
||||
|
||||
|
|
|
@ -83,10 +83,10 @@ describe('Display/Canvas Helper', function () {
|
|||
expect(display).to.have.displayed(expected);
|
||||
});
|
||||
|
||||
if('should resize the target canvas when resizing the viewport', function() {
|
||||
it('should resize the target canvas when resizing the viewport', function() {
|
||||
display.viewportChangeSize(2, 2);
|
||||
expect(canvas.width).to.equal(2);
|
||||
expect(canvas.height).to.equal(2);
|
||||
expect(display._target.width).to.equal(2);
|
||||
expect(display._target.height).to.equal(2);
|
||||
});
|
||||
|
||||
it('should redraw when moving the viewport', function () {
|
||||
|
@ -100,40 +100,17 @@ describe('Display/Canvas Helper', function () {
|
|||
display.viewportChangeSize(2, 2);
|
||||
expect(display.flip).to.have.been.calledOnce;
|
||||
});
|
||||
});
|
||||
|
||||
describe('clipping', function () {
|
||||
var display;
|
||||
beforeEach(function () {
|
||||
display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
|
||||
display.resize(4, 3);
|
||||
});
|
||||
|
||||
it('should report true when no max-size and framebuffer > viewport', function () {
|
||||
display.viewportChangeSize(2,2);
|
||||
it('should report clipping when framebuffer > viewport', function () {
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.true;
|
||||
});
|
||||
|
||||
it('should report false when no max-size and framebuffer = viewport', function () {
|
||||
it('should report not clipping when framebuffer = viewport', function () {
|
||||
display.viewportChangeSize(5, 5);
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.false;
|
||||
});
|
||||
|
||||
it('should report true when viewport > max-size and framebuffer > viewport', function () {
|
||||
display.viewportChangeSize(2,2);
|
||||
display.set_maxWidth(1);
|
||||
display.set_maxHeight(2);
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.true;
|
||||
});
|
||||
|
||||
it('should report true when viewport > max-size and framebuffer = viewport', function () {
|
||||
display.set_maxWidth(1);
|
||||
display.set_maxHeight(2);
|
||||
var clipping = display.clippingDisplay();
|
||||
expect(clipping).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('resizing', function () {
|
||||
|
|
Loading…
Reference in New Issue