An explanation of the Android WebKit 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:                     & nbsp                          ,         &NB Sp                          ,         &NB Sp                   
                  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",                                                ,         &NB Sp                          ,         &NB Sp                       
        (void*) Key},

Webviewcore::key (const platformkeyboardevent& event)

Eventhandler->keyevent (event);

WebCore Layer

This calls into the EventHandler.cpp in Source/webcore/page

It distinguishes the KeyUp KeyDown KeyPress event from being sent to node to handle the

 bool Node::d ispatchevent (passrefptr<event> Event)
  {               &NBSP;
      Return Eventdispatcher::d ispatchevent (This, Eventdispatchmediator (event));                          ,         &NB Sp              } 

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 the individual public platform: Programmer Interaction Alliance (Coder_online), sweep the QR code below or search number < Span style= "Background-color: #ffff00;" >coder_online is a concern, we can communicate online.

                                                                 

An explanation of the Android WebKit event delivery process

Related Article

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.