[webkit-dev] pywebkitgtk - adding DOM javascript executing and evaluation; next step, addEventListener etc.

Luke Kenneth Casson Leighton lkcl at lkcl.net
Wed Aug 20 08:07:48 PDT 2008


as part of the experiment to get pyjamas ported to webkit, the first step - 
pending proper (direct) DOM manipulation, with direct functions such as
document.createElement(), document.getElementById(), addChild and... well.. .
everything, really - the first step is to add javascript execution and

thanks to kalikiana's help, pointing me in the direction of gjs.[ch], that
has taken only about three hours to complete.

the next stage is slightly more hair-raising, and, rather than put in
some god-awful hack based on cut/paste of e.g. console.error(), calling
it pyjamas.awfulnotificationhackfunctionforgenericinsanepurposes() and
liberally sprinkling the javascript to be executed with calls to this
function - at every single event that is required to be notified back
into python code - i'd rather give the "proper way to do it" a chance.

i notice for example in WebKit/gtk/webkit/webkitwebview.cpp that there
are already perfectly good callbacks such as webViewClass->console_message
and widgetClass->key_press_event - i think that's perfect (maybe)
especially the key_press_event ones.

however - i need eeevverryyything.  "addEventListener()" seems like the
logical function to hook into :)  no - not "hook into" as in via
javascript - "hook into" as in "add a gtk signal called
'javascript-event-listener' which someone in a gtk app can connect()
to.  and likewise for QT.  and likewise for wxWidgets.


* is _every_ javascript event covered by those callbacks, e.g.

here's a hint of the list:

    element.onclick    = (bits & 0x00001) ? $wnd.__dispatchEvent : null;
    element.ondblclick  = (bits & 0x00002) ? $wnd.__dispatchEvent : null;
    element.onmousedown   = (bits & 0x00004) ? $wnd.__dispatchEvent : null;
    element.onmouseup    = (bits & 0x00008) ? $wnd.__dispatchEvent : null;
    element.onmouseover   = (bits & 0x00010) ? $wnd.__dispatchEvent : null;
    element.onmouseout  = (bits & 0x00020) ? $wnd.__dispatchEvent : null;
    element.onmousemove   = (bits & 0x00040) ? $wnd.__dispatchEvent : null;
    element.onkeydown    = (bits & 0x00080) ? $wnd.__dispatchEvent : null;
    element.onkeypress  = (bits & 0x00100) ? $wnd.__dispatchEvent : null;
    element.onkeyup    = (bits & 0x00200) ? $wnd.__dispatchEvent : null;
    element.onchange      = (bits & 0x00400) ? $wnd.__dispatchEvent : null;
    element.onfocus    = (bits & 0x00800) ? $wnd.__dispatchEvent : null;
    element.onblur      = (bits & 0x01000) ? $wnd.__dispatchEvent : null;
    element.onlosecapture = (bits & 0x02000) ? $wnd.__dispatchEvent : null;
    element.onscroll      = (bits & 0x04000) ? $wnd.__dispatchEvent : null;
    element.onload      = (bits & 0x08000) ? $wnd.__dispatchEvent : null;
    element.onerror    = (bits & 0x10000) ? $wnd.__dispatchEvent : null;

* can i access and change cancelBubble, call event.stopPropagation()
  and event.preventDefault()  from the gtk event functions or am i
  really going to have to bite the bullet and add a python wrapper around
  the Event class (when i find it), and add my own addEventListener
  (when i find the right places) with its corresponding qt/gtk etc.

this is slightly mind-bending even by my standards.

some sort of pointers along the right lines, e.g. "yes, go for it, by
all means add an insane c-based callback into every addEventListener
you can find", or "no, you fooool, that's been done already, *slap*
use this", or "no, fooool, that's already been planned and designed"
would be greatly appreciated.

ideas, anyone?


More information about the webkit-dev mailing list