Skip to content

Commit

Permalink
Add CefFrame.selectAll (fixes chromiumembedded#428)
Browse files Browse the repository at this point in the history
Also implements common keyboard shortcuts on Mac.
  • Loading branch information
antoineveldhoven authored and magreenblatt committed Jan 9, 2024
1 parent beb9336 commit 812891b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
7 changes: 6 additions & 1 deletion java/org/cef/browser/CefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ public interface CefFrame {
* Execute paste in this frame.
*/
public void paste();
}

/**
* Execute selectAll in this frame.
*/
public void selectAll();
}
9 changes: 9 additions & 0 deletions java/org/cef/browser/CefFrame_N.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public void paste() {
}
}

public void selectAll() {
try {
N_SelectAll(getNativeRef(null));
} catch (UnsatisfiedLinkError ule) {
ule.printStackTrace();
}
}

private final native void N_Dispose(long self);
private final native long N_GetIdentifier(long self);
private final native String N_GetURL(long self);
Expand All @@ -162,4 +170,5 @@ public void paste() {
private final native void N_Cut(long self);
private final native void N_Copy(long self);
private final native void N_Paste(long self);
private final native void N_SelectAll(long self);
}
26 changes: 26 additions & 0 deletions java/tests/detailed/handler/KeyboardHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ public boolean onKeyEvent(CefBrowser browser, CefKeyEvent event) {
browser.executeJavaScript("alert('You pressed the space bar!');", "", 0);
}
return true;
} else if (event.type == CefKeyEvent.EventType.KEYEVENT_RAWKEYDOWN && event.is_system_key) {
// CMD+[key] is not working on a Mac.
// This switch statement delegates the common keyboard shortcuts to the browser
switch (event.unmodified_character) {
case 'a':
browser.getFocusedFrame().selectAll();
break;
case 'c':
browser.getFocusedFrame().copy();
break;
case 'v':
browser.getFocusedFrame().paste();
break;
case 'x':
browser.getFocusedFrame().cut();
break;
case 'z':
browser.getFocusedFrame().undo();
break;
case 'Z':
browser.getFocusedFrame().redo();
break;
default:
return false;
}
return true;
}
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions native/CefFrame_N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,14 @@ JNIEXPORT void JNICALL Java_org_cef_browser_CefFrame_1N_N_1Paste(JNIEnv* env,

frame->Paste();
}

JNIEXPORT void JNICALL
Java_org_cef_browser_CefFrame_1N_N_1SelectAll(JNIEnv* env,
jobject obj,
jlong self) {
CefRefPtr<CefFrame> frame = GetSelf(self);
if (!frame)
return;

frame->SelectAll();
}
9 changes: 9 additions & 0 deletions native/CefFrame_N.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 812891b

Please sign in to comment.