--- /dev/null
+/**
+ * @license MIT
+ */
+
+import { CharMeasure } from './CharMeasure';
+
+export function getCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure): [number, number] {
+ // ignore browsers without pageX for now
+ if (event.pageX == null) {
+ return null;
+ }
+
+ let x = event.pageX;
+ let y = event.pageY;
+ let el = rowContainer;
+
+ // should probably check offsetParent
+ // but this is more portable
+ while (el && el !== self.document.documentElement) {
+ x -= el.offsetLeft;
+ y -= el.offsetTop;
+ el = 'offsetParent' in el ? <HTMLElement>el.offsetParent : <HTMLElement>el.parentElement;
+ }
+
+ // convert to cols/rows
+ x = Math.ceil(x / charMeasure.width);
+ y = Math.ceil(y / charMeasure.height);
+
+ return [x, y];
+}
+
+export function getRawByteCoords(event: MouseEvent, rowContainer: HTMLElement, charMeasure: CharMeasure, colCount: number, rowCount: number): { x: number, y: number } {
+ const coords = getCoords(event, rowContainer, charMeasure);
+ let x = coords[0];
+ let y = coords[1];
+
+ // be sure to avoid sending bad positions to the program
+ if (x < 0) x = 0;
+ if (x > colCount) x = colCount;
+ if (y < 0) y = 0;
+ if (y > rowCount) y = rowCount;
+
+ // xterm sends raw bytes and
+ // starts at 32 (SP) for each.
+ x += 32;
+ y += 32;
+
+ return { x, y };
+}
import * as Browser from './utils/Browser';
import * as Keyboard from './utils/Keyboard';
import { CHARSETS } from './Charsets';
+import { getRawByteCoords } from './utils/Mouse';
/**
* Terminal Emulation References:
button = getButton(ev);
// get mouse coordinates
- pos = getCoords(ev);
+ pos = getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
if (!pos) return;
sendEvent(button, pos);
var button = pressed
, pos;
- pos = getCoords(ev);
+ pos = getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
if (!pos) return;
// buttons marked as motions
return button;
}
- // mouse coordinates measured in cols/rows
- function getCoords(ev) {
- var x, y, w, h, el;
-
- // ignore browsers without pageX for now
- if (ev.pageX == null) return;
-
- x = ev.pageX;
- y = ev.pageY;
- el = self.element;
-
- // should probably check offsetParent
- // but this is more portable
- while (el && el !== self.document.documentElement) {
- x -= el.offsetLeft;
- y -= el.offsetTop;
- el = 'offsetParent' in el
- ? el.offsetParent
- : el.parentNode;
- }
-
- // convert to cols/rows
- x = Math.ceil(x / self.charMeasure.width);
- y = Math.ceil(y / self.charMeasure.height);
-
- // be sure to avoid sending
- // bad positions to the program
- if (x < 0) x = 0;
- if (x > self.cols) x = self.cols;
- if (y < 0) y = 0;
- if (y > self.rows) y = self.rows;
-
- // xterm sends raw bytes and
- // starts at 32 (SP) for each.
- x += 32;
- y += 32;
-
- return {
- x: x,
- y: y,
- type: 'wheel'
- };
- }
-
on(el, 'mousedown', function(ev) {
if (!self.mouseEvents) return;