webkit增加自定义事件接口onirkeypress,onsystemevent,使页面可以注册实现这两个接口,需要在webkit中做如下改动:
1.DomWindow.idl添加:
attribute EventListener onirkeypress;
attribute EventListener onsystemevent;
4.Document.idl添加:
attribute [DontEnum] EventListener onirkeypress;
5.Document.h添加:
DEFINE_ATTRIBUTE_EVENT_LISTENER(irkeypress);
7.自定义Event 实现(可参照UIEvent):
TestEvent.h
TestEvent.cpp
TestEvent.idl
8.dom/Event.h添加
virtual bool isTestEvent() const;
9.JSEventCustom.cpp添加
10. 在webkit中的js 扩展函数中发送TestEvent的示例代码如下:
ExceptionCode ec = 0;
RefPtr<TestEvent> event = TestEvent::create();
event->initEvent(eventNames().irkeypressEvent, true, false);
event->setCode(keycode);
event->setWhich(messageid);
m_document->dispatchEvent(event.release(), ec);
11. 接收事件的测试页面 testevent.html中注册onirkeypress:
document.onirkeypress = grabevent;
function grabevent(event) {
var type = event.type;
var which = event.which;
var code = event.keyCode;
alert("event type "+ type);
alert("event which "+ which);
alert("grabevent be called key code "+ code);
}