In hosted mode, the MouseUpHandler works correctly. However, in server mode the event will not occur if getSelectedHtml() is called. The console doesn’t report any errors and indicates that the mouseup event is delivered to the canvas. Commenting out getSelectedHtml will display the SC.say.
VLayout main = new VLayout();
main.setPadding(10);
main.setWidth100();
main.setHeight100();
main.setMembersMargin(10);
main.addMouseUpHandler(new MouseUpHandler() {
public void onMouseUp(MouseUpEvent e) {
String text = getSelectedHtml();
SC.say("test");
}
});
...
public static native String getSelectedHtml() /*-{
if ($wnd.getSelection) {
var selection = window.getSelection();
var range = selection.getRangeAt(0);
if (range != null) {
var div = document.createElement('div');
div.appendChild(range.cloneContents());
return div.toString();
} else
return "";
} else if ($doc.getSelection) {
var selection = $doc.getSelection();
var range = selection.getRangeAt(0);
if (range != null) {
var div = document.createElement('div');
div.appendChild(range.cloneContents());
return div.toString();
} else
return "";
} else if ($doc.selection) {
return $doc.selection.createRange().htmlText;
} else
return '';
}-*/;
