Change some attributes to arguments

Some attributes are better suited as arguments, primarily because they
are associated with a specific method and cannot be changed later.
This commit is contained in:
Pierre Ossman
2017-10-14 13:06:03 +02:00
parent dd0db4d460
commit 3d7bb02036
13 changed files with 144 additions and 152 deletions
+3 -2
View File
@@ -15,7 +15,7 @@ import { set_defaults, make_properties } from './util/properties.js';
import * as Log from './util/logging.js';
import Base64 from "./base64.js";
export default function Display(defaults) {
export default function Display(target, defaults) {
this._drawCtx = null;
this._c_forceCanvas = false;
@@ -42,6 +42,8 @@ export default function Display(defaults) {
Log.Debug(">> Display.constructor");
// The visible canvas
this._target = target;
if (!this._target) {
throw new Error("Target must be set");
}
@@ -691,7 +693,6 @@ Display.prototype = {
};
make_properties(Display, [
['target', 'wo', 'dom'], // Canvas element for rendering
['context', 'ro', 'raw'], // Canvas 2D context for rendering (read-only)
['logo', 'rw', 'raw'], // Logo to display when cleared: {"width": w, "height": h, "type": mime-type, "data": data}
['scale', 'rw', 'float'], // Display area scale factor 0.0 - 1.0
+4 -6
View File
@@ -18,14 +18,14 @@ import KeyTable from "./keysym.js";
// Keyboard event handler
//
export default function Keyboard(defaults) {
export default function Keyboard(target, defaults) {
this._target = target || null;
this._keyDownList = {}; // List of depressed keys
// (even if they are happy)
this._pendingKey = null; // Key waiting for keypress
set_defaults(this, defaults, {
'target': null,
});
set_defaults(this, defaults, {});
// keep these here so we can refer to them later
this._eventHandlers = {
@@ -338,7 +338,5 @@ Keyboard.prototype = {
};
make_properties(Keyboard, [
['target', 'wo', 'dom'], // DOM element that captures keyboard input
['onKeyEvent', 'rw', 'func'] // Handler for key press/release
]);
+2 -4
View File
@@ -17,7 +17,8 @@ var WHEEL_STEP = 10; // Delta threshold for a mouse wheel step
var WHEEL_STEP_TIMEOUT = 50; // ms
var WHEEL_LINE_HEIGHT = 19;
export default function Mouse(defaults) {
export default function Mouse(target, defaults) {
this._target = target || document;
this._doubleClickTimer = null;
this._lastTouchPos = null;
@@ -30,7 +31,6 @@ export default function Mouse(defaults) {
// Configuration attributes
set_defaults(this, defaults, {
'target': document,
'touchButton': 1
});
@@ -284,8 +284,6 @@ Mouse.prototype = {
};
make_properties(Mouse, [
['target', 'ro', 'dom'], // DOM element that captures mouse input
['onMouseButton', 'rw', 'func'], // Handler for mouse button click/release
['onMouseMove', 'rw', 'func'], // Handler for mouse movement
['touchButton', 'rw', 'int'] // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
+17 -17
View File
@@ -28,11 +28,12 @@ import { encodings, encodingName } from "./encodings.js";
/*jslint white: false, browser: true */
/*global window, Util, Display, Keyboard, Mouse, Websock, Websock_native, Base64, DES, KeyTable, Inflator, XtScancode */
export default function RFB(defaults) {
export default function RFB(target, defaults) {
"use strict";
if (!defaults) {
defaults = {};
}
this._target = target;
// Connection details
this._url = '';
@@ -128,12 +129,9 @@ export default function RFB(defaults) {
// set the default value on user-facing properties
set_defaults(this, defaults, {
'target': 'null', // VNC display rendering Canvas object
'local_cursor': false, // Request locally rendered cursor
'shared': true, // Request shared mode
'view_only': false, // Disable client mouse/keyboard
'disconnectTimeout': 3, // Time (s) to wait for disconnection
'repeaterID': '', // [UltraVNC] RepeaterID to connect to
'viewportDrag': false, // Move the viewport on mouse drags
// Callback functions
@@ -172,19 +170,19 @@ export default function RFB(defaults) {
// NB: nothing that needs explicit teardown should be done
// before this point, since this can throw an exception
try {
this._display = new Display({target: this._target,
onFlush: this._onFlush.bind(this)});
this._display = new Display(this._target,
{onFlush: this._onFlush.bind(this)});
} catch (exc) {
Log.Error("Display exception: " + exc);
throw exc;
}
this._display.clear();
this._keyboard = new Keyboard({target: this._target,
onKeyEvent: this._handleKeyEvent.bind(this)});
this._keyboard = new Keyboard(this._target,
{onKeyEvent: this._handleKeyEvent.bind(this)});
this._mouse = new Mouse({target: this._target,
onMouseButton: this._handleMouseButton.bind(this),
this._mouse = new Mouse(this._target,
{onMouseButton: this._handleMouseButton.bind(this),
onMouseMove: this._handleMouseMove.bind(this)});
this._sock = new Websock();
@@ -243,15 +241,20 @@ export default function RFB(defaults) {
RFB.prototype = {
// Public methods
connect: function (url, creds) {
this._url = url;
this._rfb_credentials = (creds !== undefined) ? creds : {};
connect: function (url, options) {
if (!url) {
this._fail(_("Must specify URL"));
return;
}
this._url = url;
options = options || {}
this._rfb_credentials = options.credentials || {};
this._shared = 'shared' in options ? !!options.shared : true;
this._repeaterID = options.repeaterID || '';
this._rfb_init_state = '';
this._updateConnectionState('connecting');
return true;
@@ -1444,15 +1447,12 @@ RFB.prototype = {
};
make_properties(RFB, [
['target', 'wo', 'dom'], // VNC display rendering Canvas object
['local_cursor', 'rw', 'bool'], // Request locally rendered cursor
['shared', 'rw', 'bool'], // Request shared mode
['view_only', 'rw', 'bool'], // Disable client mouse/keyboard
['touchButton', 'rw', 'int'], // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
['scale', 'rw', 'float'], // Display area scale factor
['viewport', 'rw', 'bool'], // Use viewport clipping
['disconnectTimeout', 'rw', 'int'], // Time (s) to wait for disconnection
['repeaterID', 'rw', 'str'], // [UltraVNC] RepeaterID to connect to
['viewportDrag', 'rw', 'bool'], // Move the viewport on mouse drags
['capabilities', 'ro', 'arr'], // Supported capabilities