PDA

View Full Version : MS Edge support - Contextual menu opening while scrolling



priand
14 Apr 2017, 5:37 AM
On MS Edge, the contextual menu opens when a long mouse click is detected (even with the left button).
This typically occurs while scrolling, which is a problem.
As a workaround, we have overridden protected void onTouch(Event event) {} on the widget (empty implementation).
Is there a better way to handle this case?
Could this be fixed in next version?

priand
18 Apr 2017, 12:27 PM
Overriding onTouch(Event event) {} has some side-effects, so I implemented a cleaner workaround as below (class extending Grid)):
private boolean fixContextMenuGestureRecognizer=false;

@Override
public void setContextMenu(Menu menu) {
fixContextMenuGestureRecognizer=true;
try {
super.setContextMenu(menu);
} finally {
fixContextMenuGestureRecognizer=false;
}
}
@Override
public void addGestureRecognizer(GestureRecognizer gestureRecognizer) {
if (fixContextMenuGestureRecognizer){
gestureRecognizer = new LongPressOrTapGestureRecognizer() {
@Override
protected void onLongPress(TouchData touchData) {
super.onLongPress(touchData);


// we do not want to show context menu on right click
// we could also test isMSEdge, not sure what is best here
if (GXT.isDesktop()){
onClick((Event) touchData.getLastNativeEvent());
} else {
onRightClick((Event) touchData.getLastNativeEvent());
}
}


@Override
public boolean handleEnd(NativeEvent endEvent) {
// onRightClick does preventDefault and stopPropagation
cancel();
return super.handleEnd(endEvent);
}
};
}

super.addGestureRecognizer(gestureRecognizer);
}