-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathBrowserMouseEventArgs.ts
More file actions
37 lines (31 loc) · 1.38 KB
/
BrowserMouseEventArgs.ts
File metadata and controls
37 lines (31 loc) · 1.38 KB
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
import type { IContainer } from '@coderline/alphatab/platform/IContainer';
import type { IMouseEventArgs } from '@coderline/alphatab/platform/IMouseEventArgs';
import type { HtmlElementContainer } from '@coderline/alphatab/platform/javascript/HtmlElementContainer';
/**
* @target web
* @internal
*/
export class BrowserMouseEventArgs implements IMouseEventArgs {
public readonly mouseEvent: PointerEvent;
public get isLeftMouseButton(): boolean {
return this.mouseEvent.button === 0;
}
public getX(relativeTo: IContainer): number {
const relativeToElement: HTMLElement = (relativeTo as HtmlElementContainer).element;
const bounds: DOMRect = relativeToElement.getBoundingClientRect();
const left: number = bounds.left + relativeToElement.ownerDocument!.defaultView!.pageXOffset;
return this.mouseEvent.pageX - left;
}
public getY(relativeTo: IContainer): number {
const relativeToElement: HTMLElement = (relativeTo as HtmlElementContainer).element;
const bounds: DOMRect = relativeToElement.getBoundingClientRect();
const top: number = bounds.top + relativeToElement.ownerDocument!.defaultView!.pageYOffset;
return this.mouseEvent.pageY - top;
}
public preventDefault(): void {
this.mouseEvent.preventDefault();
}
public constructor(e: PointerEvent) {
this.mouseEvent = e;
}
}