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

那天有空自己测试下,看看
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值