SelectAll missing in CefFrame
magreenblatt opened this issue · 5 comments
Original report by Antoine Veldhoven (Bitbucket: Antoine Veldhoven).
SelectAll function is missing in the CefFrame implementation, whilst all other are available; cut / copy / paste etc.
Original comment by 远星河 (Bitbucket: 远星河).
Javascript can solve the problem temporarily.
@Override
public boolean onKeyEvent(CefBrowser browser, CefKeyEvent event) {
if (event.type == CefKeyEvent.EventType.KEYEVENT_RAWKEYDOWN) {
if (event.modifiers == KeyEvent.CTRL_DOWN_MASK) {
final CefFrame frame = browser.getFocusedFrame();
switch (event.windows_key_code) {
case KeyEvent.VK_A:
frame.executeJavaScript("!(function(node){var win=window;var doc=win.document,sel,range;if(node.tagName==='INPUT'){node.select()}else if(win.getSelection&&doc.createRange){sel=win.getSelection();range=doc.createRange();range.selectNodeContents(node);sel.removeAllRanges();sel.addRange(range)}else if(doc.body.createTextRange){range=doc.body.createTextRange();range.moveToElementText(node);range.select()}})(document.activeElement)", browser.getURL(), 0);
break;
case KeyEvent.VK_C:
frame.copy();
break;
case KeyEvent.VK_V:
frame.paste();
break;
case KeyEvent.VK_X:
frame.cut();
break;
case KeyEvent.VK_Z:
frame.undo();
break;
case KeyEvent.VK_R:
browser.reload();
break;
}
} else if (event.modifiers == 130 && event.windows_key_code == KeyEvent.VK_Z) {
browser.getFocusedFrame().redo();
}
}
return super.onKeyEvent(browser, event);
}
Original comment by Antoine Veldhoven (Bitbucket: Antoine Veldhoven).
In Windows this is working already I believe, on Mac these events aren’t delegated; that’s why I proposed the change with a PR.
The JS will definitely work for Mac check for event.is_system_key instead of CTRL_DOWN_MASK
Original comment by Antoine Veldhoven (Bitbucket: Antoine Veldhoven).
https://bitbucket.org/chromiumembedded/java-cef/pull-requests/98
Original comment by 远星河 (Bitbucket: 远星河).
Ctrl+Alt+A or Ctrl+Shift+A
should not select all. so i check event.modifiers == KeyEvent.CTRL_DOWN_MASK
.