问题
I'm trying to capture dragover and drop events. Right now I'm capturing those events adding a dom handler to my RootLayoutPanel:
dragOverHandler = RootLayoutPanel.get().addBitlessDomHandler(this, DragOverEvent.getType());
dropHandler = RootLayoutPanel.get().addBitlessDomHandler(this, DropEvent.getType());
The problem is this code does not capture the events when showing a popup and the drag/drop is over the popup itself or the glass around it.
I have also tried using a native preview handler, but it seems it is not called on dragover nor drop events:
Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
GWT.log(event.getNativeEvent().getType());
}
});
Is there a straight way to capture all dragover and drop events in my app?
Thanks
回答1:
Try using RootPanel.get() instead of RootLayoutPanel.get().
FYI, RootLayoutPanel.get() adds the RootLayoutPanel singleton to the RootPanel.get(); RootPanel.get() wraps the document's <body> inside a RootPanel, so it should capture everything (provided the body fills the viewport, which the RootLayoutPanel ensures).
来源:https://stackoverflow.com/questions/12900945/gwt-capturing-drag-drop-events