我已经用 preventDefault 停止了一个事件。现在我想重新抛出它。我尝试了fireEvent,但没有奏效。有没有办法做到这一点?
更新 我创建了一个新的事件实例并使用了 elem.dispatchEvent(clickEvent); 而不是触发事件
Event.addNativePreviewHandler(new Event.NativePreviewHandler()
{
public void onPreviewNativeEvent(NativePreviewEvent event)
{
if (event.getTypeInt() == Event.ONMOUSEDOWN)
{
Element elem = JSHelper.elementFromPoint(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
EventListener listener = Event.getEventListener(elem);
if((listener instanceof ListBox))
{
event.getNativeEvent().preventDefault();
//// ((ListBox) listener).fireEvent(event);
int y = event.getNativeEvent().getClientY();
int x = event.getNativeEvent().getClientX();
int screenX = event.getNativeEvent().getScreenX();
int screenY = event.getNativeEvent().getScreenY();
NativeEvent clickEvent = Document.get().createMouseEvent(
"click",true, false,0, screenX, screenY, x, y, false, false,
false, false, NativeEvent.BUTTON_LEFT, elem);
elem.dispatchEvent(clickEvent);
}
}
}
});