Android webkit 事件传递流程详解
前言:基于android webview 上定制自己使用的可移植浏览器apk,遇到好多按键处理的问题。所以索性研究了一下keyevent 事件的传递流程。
frameworks 层
keyevent 事件开始是从/frameworks/base/core/java/android/webkit目录下WebViewClassic.java
中的onKeyDown() 函数开始的
// 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))
这个的作用是判断event是不是系统按键,或者调用webview应用处理event。系统按键直接返回,
如果webview应用处理了也直接返回。
其它key事件调用 sendKeyEvent(event),在sendKeyEvent() 又调用sendBatchableInputMessage()
在这个函数中又调用mWebViewCore.sendMessage(message)
将event封装成Message传递给WebViewCore.java中的EventHub 类
在sendMessage()函数又通过它发送到Handler在transferMessages() 中handleMessage()处理keydown事件
case KEY_DOWN:
key((KeyEvent) msg.obj, msg.arg1, true);
break;
webkit 对接层
key中调用nativeKey() 将事件传入webkit中Source/WebKit/android/jni WebViewCore.cpp中的
{ "nativeKey", "(IIIIZZZZ)Z",
(void*) Key },
WebViewCore::key(const PlatformKeyboardEvent& event)
eventHandler->keyEvent(event);
WebCore层
此时调用进入Source/WebCore/page 中的EventHandler.cpp
它会区分为keyup keydown keypress 事件发送到Node中处理
bool Node::dispatchEvent(PassRefPtr<Event> event)
{
return EventDispatcher::dispatchEvent(this, EventDispatchMediator(event)); }
通过中转最终调用到EventDispatcher.cpp中
bool EventDispatcher::dispatchEvent(PassRefPtr<Event> event)
m_node->handleLocalEvents(event.get());
在Node.cpp 中调用
fireEventListeners(event);
class Node : public EventTarget Node继承了EventTarget
EventTarget.cpp中实现注册监听
bool EventTarget::fireEventListeners(Event* event)
registeredListener.listener->handleEvent(scriptExecutionContext(), event);
发送到注册监听的javascript中。
如果在js中注册了一个keypress事件处理而我们要兼容支持它我们可以只动WebViewClassic.java或者在app层代码实现转换并传入js中即可。
在WebViewClassic.java中实现了passVirtualKeyEvent(int KeyCode)。
第一时间获得博客更新提醒,以及更多技术信息分享,欢迎关注个人微信公众平台:程序员互动联盟(coder_online),扫一扫下方二维码或搜索微信号coder_online即可关注,我们可以在线交流。

Android webkit 事件传递流程详解的更多相关文章
- Android Touch事件传递机制详解 下
尊重原创:http://blog.csdn.net/yuanzeyao/article/details/38025165 资源下载:http://download.csdn.net/detail/yu ...
- Android 的事件传递机制,详解
Android 的事件传递机制,详解 前两天和一个朋友聊天的时候.然后说到事件传递机制.然后让我说的时候,忽然发现说的不是非常清楚,事实上Android 的事件传递机制也是知道一些,可是感觉自己知道的 ...
- Android webkit 事件传递流程通道分析
前言:基于android webview 上定制自己使用的可移植浏览器apk,遇到好多按键处理的问题.所以索性研究了一下keyevent 事件的传递流程. frameworks 层 keyevent ...
- Android Touch事件传递机制详解
Android开发的朋友经常处理各种触摸事件,然而在触摸事件的传递过程中主要用到三个方法:dispatchTouchEvent().onInterceptTouchEvent()和onTouchEve ...
- Android Touch事件传递机制详解 上
最近总是遇到关于Android Touch事件的问题,如:滑动冲突的问题,以前也花时间学习过Android Touch事件的传递机制,可以每次用起来的时候总是忘记了,索性自己总结一下写篇文章避免以后忘 ...
- Android事件传递机制详解及最新源码分析——ViewGroup篇
版权声明:本文出自汪磊的博客,转载请务必注明出处. 在上一篇<Android事件传递机制详解及最新源码分析--View篇>中,详细讲解了View事件的传递机制,没掌握或者掌握不扎实的小伙伴 ...
- Android事件传递机制详解及最新源码分析——View篇
摘要: 版权声明:本文出自汪磊的博客,转载请务必注明出处. 对于安卓事件传递机制相信绝大部分开发者都听说过或者了解过,也是面试中最常问的问题之一.但是真正能从源码角度理解具体事件传递流程的相信并不多, ...
- Android开发——事件分发机制详解
0. 前言 转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52566965 深入学习事件分发机制,是为了解决在Android开发中 ...
- Android按键事件传递流程(二)
5 应用层如何从Framework层接收按键事件 由3.2和4.5.4节可知,当InputDispatcher通过服务端管道向socket文件描述符发送消息后,epoll机制监听到了I/O事件, ...
随机推荐
- Codeforces Round #140 (Div. 1) D. The table 构造
D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...
- Codeforces Gym 100015F Fighting for Triangles 状压DP
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...
- Codeforces Round #136 (Div. 1)C. Little Elephant and Shifts multiset
C. Little Elephant and Shifts Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/pro ...
- Codeforces Beta Round #4 (Div. 2 Only) C. Registration system hash
C. Registration system Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- 自定义WM_NOTIFY消息
自定义WM_NOTIFY消息 习惯了用自定义用户消息进行各种状态的通知,特别是子窗口与父窗口之间的交互.但ON_MESSAGE没有控件ID的限制,如果有多个子窗口发送同一个消息给父窗口时,父窗口就不知 ...
- C语言阶乘和求闰年
#include<stdio.h> void main(){ int i,a,s=1; scanf("%d",&a); for(i=1;i<=a;i++) ...
- cocos2d-x make: *** [clean-box2d_static-armeabi] Error 1
/cygdrive/d/android-ndk-r8e/build/core/build-binary.mk:52: recipe for target `clean-cocos_curl_stati ...
- WSS3.0 SDK中的不同列表类型的对应值
Value Description 100 Generic list 101 Document library 102 Survey 103 Links list 104 Announcements ...
- VS环境下搭建自己NuGet服务器
一.NuGet服务端的搭建 环境:.NET 4.5 + VS2015 + NuGet.Server 2.10.1 1.建一个空的Web项目,取名叫NuGetServer 2.通过NuGet安装NuGe ...
- highcharts笔记 highcharts学习 highcharts用法
标示线:plotLines : 绘制线: