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: & nbsp , &NB Sp , &NB Sp  &NBSP
& nbsp Key ((KeyEvent) Msg.obj, MSG.ARG1, true);
break;
WebKit docking 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);
WebCore docking Layer
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.
the first time to get blog update reminders, as well as more technical information sharing, welcome to pay attention to personal public platform: programmer interaction Alliance (Coder_online), sweep the QR code below or search number coder_online can be followed, we can communicate online.
Android WebKit Event delivery Process channel analysis