android 4.0.1 webkit 添加自定义事件接口发送自定义Event

webkit增加自定义事件接口onirkeypress,onsystemevent,使页面可以注册实现这两个接口,需要在webkit中做如下改动:

1.DomWindow.idl添加:

 attribute EventListener onirkeypress;

 attribute EventListener onsystemevent;


2.HTMLAttributenames.in添加:
  onirkeypress
  onsystemevent

3.EventNames.h添加:
  macro(irkeypress) 
  macro(systemevent) 


4.Document.idl添加:

 attribute [DontEnum] EventListener onirkeypress;
 attribute [DontEnum] EventListener onsystemevent;


5.Document.h添加:

DEFINE_ATTRIBUTE_EVENT_LISTENER(irkeypress);
DEFINE_ATTRIBUTE_EVENT_LISTENER(systemevent);

6.DomWindow.h添加:
DEFINE_ATTRIBUTE_EVENT_LISTENER(irkeypress);
DEFINE_ATTRIBUTE_EVENT_LISTENER(systemevent);


7.自定义Event 实现(可参照UIEvent):

TestEvent.h
TestEvent.cpp
TestEvent.idl

8.dom/Event.h添加

virtual bool isTestEvent() const;

9.JSEventCustom.cpp添加
 if (event->isTestEvent())
       wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CCDTEvent, event);

在webkit 内部(比如js 扩展中需要发送自定义Event到页面)可以发送TestEvent 给页面的onirkeypress或onsystemevent.


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);
}



你可能感兴趣的:(android 4.0.1 webkit 添加自定义事件接口发送自定义Event)