Introduction: Based on the Android WebView to customize their own use of portable browser apk, encountered a lot of key handling problems. So I simply studied the transmission flow of the KeyEvent event.
Frameworks Layer
The KeyEvent event starts from the/frameworks/base/core/java/android/webkit directory Webviewclassic.java
Starts with the onkeydown () function in the
Bubble up the key event if
1. It is a system key; Or
2. The host application wants to handle it;
if ((Event.issystem () | | | mcallbackproxy.uioverridekeyevent (EVENT))
The function of this is to determine if the event is a system key or call the WebView application to handle the event. The System button returns directly,
If the WebView app is processed, it also returns directly.
Other key events call Sendkeyevent (event), and Sendbatchableinputmessage () is called in Sendkeyevent ()
In this function, you call Mwebviewcore.sendmessage (message).
Encapsulates an event as a message passed to the Eventhub class in Webviewcore.java
The SendMessage () function is also sent through it to Handler in Transfermessages () Handlemessage () handles the KeyDown event
Case Key_down:
Key ((KeyEvent) Msg.obj, MSG.ARG1, true);
Break
WebKit Layer
Key calls Nativekey () to pass the event into the WebKit in Source/webkit/android/jni WebViewCore.cpp
{"Nativekey", "(iiiizzzz) Z",
(void*) Key},
Webviewcore::key (const platformkeyboardevent& event)
Eventhandler->keyevent (event);
This calls into the EventHandler.cpp in Source/webcore/page
It distinguishes the KeyUp KeyDown KeyPress event from being sent to node processing
BOOL Node::d ispatchevent (passrefptr<event> Event)
{
Return Eventdispatcher::d ispatchevent (This, Eventdispatchmediator (event)); }
Final call to EventDispatcher.cpp by relay
BOOL Eventdispatcher::d ispatchevent (passrefptr<event> Event)
M_node->handlelocalevents (Event.get ());
Called in Node.cpp
Fireeventlisteners (event);
Class Node:public Eventtarget Node inherits the Eventtarget
Registering for monitoring in EventTarget.cpp
BOOL Eventtarget::fireeventlisteners (event* Event)
Registeredlistener.listener->handleevent (Scriptexecutioncontext (), event);
Sent to the JavaScript that registered the listener.
If we register a KeyPress event processing in JS and we want to support it, we can only move the Webviewclassic.java or the application layer code to convert and pass in JS.
passvirtualkeyevent (int keycode) is implemented in Webviewclassic.java.
If you have questions and needs, please leave a message, I will answer the questions for you.
Sweep the QR code or search number below the programmer's Interactive Alliance (coder_online), we can exchange on-line
Android WebKit keyevent Event Delivery process