-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathMouse.js
54 lines (47 loc) · 1.41 KB
/
Mouse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
var addFinalProp = require('../utils').addFinalProp;
var Coordinates = require('./Coordinates');
var Long = require('../imports').Long;
module.exports = Mouse;
function Mouse(instance) {
addFinalProp(this, '_instance', instance);
}
Mouse.prototype.click = function(where) {
assertCoordinates(where);
this._instance.clickSync(where);
};
Mouse.prototype.contextClick = function(where) {
assertCoordinates(where);
this._instance.contextClickSync(where);
};
Mouse.prototype.doubleClick = function(where) {
assertCoordinates(where);
this._instance.doubleClickSync(where);
};
Mouse.prototype.mouseDown = function(where) {
assertCoordinates(where);
this._instance.mouseDownSync(where);
};
Mouse.prototype.mouseMove = function(where, xOffset, yOffset) {
assertCoordinates(where);
if (typeof xOffset === 'number' && typeof yOffset === 'number') {
this._instance.mouseMoveSync(where);
} else {
this._instance.mouseMoveSync(where, new Long(xOffset), new Long(yOffset));
}
};
Mouse.prototype.mouseUp = function(where) {
assertCoordinates(where);
this._instance.mouseUpSync(where);
};
function asssertCoordinates(where) {
if (!(where instanceof Coordinates)) {
throw new Error('where must be an instanceof Coordinates');
}
}
function assertCoordinates(coords){
if(coords instanceof Coordinates){
return;
}
throw new Error('the first argument wasn\'t an instance of Coordinates');
}