Android WebKit keyevent Event Delivery process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.