Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let dispatchEvent work. issues#17638 #949

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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