Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/core/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type FirefoxMouseEvent = {
layerY: number
}

type DispatchedEvent = {
dispatchedOffsetX: number
dispatchedOffsetY: number
}

/**
* Get the `zrX` and `zrY`, which are relative to the top-left of
Expand All @@ -45,19 +49,22 @@ type FirefoxMouseEvent = {
*/
export function clientToLocal(
el: HTMLElement,
e: ZRRawEvent | FirefoxMouseEvent | Touch,
e: ZRRawEvent | FirefoxMouseEvent | Touch | DispatchedEvent,
out: {zrX?: number, zrY?: number},
calculate?: boolean
) {
out = out || {};

if ((e as DispatchedEvent).dispatchedOffsetX) {
out.zrX = (e as DispatchedEvent).dispatchedOffsetX;
out.zrY = (e as DispatchedEvent).dispatchedOffsetY;
}
// According to the W3C Working Draft, offsetX and offsetY should be relative
// to the padding edge of the target element. The only browser using this convention
// is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
// not support the properties.
// (see http://www.jacklmoore.com/notes/mouse-position/)
// In zr painter.dom, padding edge equals to border edge.
if (calculate) {
else if (calculate) {
calculateZrXY(el, e as ZRRawEvent, out);
}
// Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
Expand Down