import elemental.js.dom.JsElement; //导入依赖的package包/类
private void setupShowAdditionalInfo(final CMHintResultsOverlay data,
final AdditionalInfoCallback additionalInfoCallback) {
if (additionalInfoCallback != null) {
final CodeMirrorOverlay codeMirror = editorWidget.getCodeMirror();
final Element bodyElement = Elements.getBody();
codeMirror.on(data, EventTypes.COMPLETION_SELECT, new EventHandlers.EventHandlerMixedParameters() {
@Override
public void onEvent(final JsArrayMixed param) {
// param 0 -> completion object (string or object)
final CMCompletionObjectOverlay completionObject = param.getObject(0);
// param 1 -> DOM node in the menu
final JsElement itemElement = param.getObject(1);
final ClientRect itemRect = itemElement.getBoundingClientRect();
Element popup = itemElement;
while (popup.getParentElement() != null && ! popup.getParentElement().equals(bodyElement)) {
popup = popup.getParentElement();
}
final ClientRect popupRect = popup.getBoundingClientRect();
final float pixelX = Math.max(itemRect.getRight(), popupRect.getRight());
final float pixelY = itemRect.getTop();
final Element info = getAdditionalInfo(completionObject);
// there can be only one
// remove any other body child with the additional info marker
removeStaleInfoPopups(ADDITIONAL_INFO_MARKER);
// Don't show anything if there is no additional info
if (info == null) {
return;
}
final Element infoDisplayElement = additionalInfoCallback.onAdditionalInfoNeeded(pixelX, pixelY, info);
// set the additional info marker on the popup element
infoDisplayElement.getClassList().add(ADDITIONAL_INFO_MARKER);
}
});
// close the additional info along with the completion popup
codeMirror.on(data, EventTypes.COMPLETION_CLOSE, new EventHandlers.EventHandlerNoParameters() {
@Override
public void onEvent() {
delayedRemoveStaleInfoPopups(ADDITIONAL_INFO_MARKER);
}
});
}
}