[webkit-dev] Add custom event into Webkit

Ross Lillie ross.lillie at motorola.com
Thu Apr 9 09:11:33 PDT 2009

Hi Darin,

Thanks for the reply.  Yes, this is starting to make sense, please excuse,
but my Javascript/DOM knowledge is pretty rusty - but it's coming back.

I'd figured out that I can create arbitrarily named events via the DOMEvent
class (in my external code), however, as you mentioned, the problem is that
I need to attach special data.

In a nutshell, I want to expose an external device model (C or C++) to
Javascript.  No problem, as there are numerous places to grab a reference to
the JSContext allowing me to expose my external code internally as a
Javascript object.

The next piece of the puzzle, however, is dispatching events generated by my
external code into the Javascript/DOM environment.  These events ideally
require special data to be attached.  From my admittedly limited
understanding of WebKit internals, it would appear that I can't do this
without bypassing the public interfaces.

Finally, if I want my custom event targets to be an attribute on a DOM node,
I would think that I would also need to create a custom attribute node that
implements the EventTarget interface, and register this node in some manner
within WebKit's core - but I haven't dug into this far enough yet.  While
this isn't strictly necessary, it provide nice syntactic sugar when
developing an interface that works with your external device model.

Obviously, I'd like to avoid bypassing public webkit interfaces.  I just
don't know if I can cleanly do what I need to with the current APIs for my
embedded application.

I hope I'm not complete out in the weeds in my current understanding.  Your
comments have been helpful.  Hopefully, this explanation makes more sense.

Thanks loads for the feedback.


On 4/9/09 10:45 AM, "Darin Adler" <darin at apple.com> wrote:

> On Apr 9, 2009, at 2:40 AM, Tony Louaze wrote:
>> I want to add a custom event into Webkit without modify and compile
>> Webkit.
> It all depends what you mean by a custom event. If you want to send an
> event with a special name but no special data attached, you can do
> this easily with standard DOM API.
> In JavaScript it would be something like this:
>      var event = document.createEvent("Events");
>      event.initEvent("specialName", false, false);
>      target.dispatchEvent(event);
>> On which object should I make the "addEventListener" : a custom JS
>> object or an existing DOM object (which one ?) ?
> You can send an event to any event target object, which can be any DOM
> node or other type of object, and the listener would need to be
> attached to that object, the one you send the event to. Your question
> isn¹t specific enough.
>> For now, I'm just interracting with JS context by using the
>> Webkit.dll API.
> WebKit DOM bindings for JavaScript and for Objective-C on Mac OS X are
> mostly complete; the ones done with COM on Windows are enough for
> Safari but are incomplete, and are likely missing some things you¹d
> need to deal with custom events.
>      -- Darin
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

More information about the webkit-dev mailing list