back in august or so when i was first working on the glib DOM bindings, a number of people who expressed an interest asked for advice on how to use the glib / gdom bindings in c. as my primary focus was on the python bindings, using the auto-generator (codegen.py) to automatically write that code, i gave some notes but left it to the people who contacted me to write the code, as i didn't have a reason to do it, myself. now i've had a good reason to do the work, here is some code (attached and also link here) that shows how to begin manipulating and interacting with the DOM model: http://lkcl.net/webkit/gdom_bindings_gtklauncher_demo.patch
notes: 1) first thing you should notice is that add_event_listener isn't declared in an accessible header file; it's a badly-named that does the job it's required to do. it _is_ declared in WebKit/gtk/webkit/EventListenerNode.h but is wrapped in an extern "C" { ... } which makes the c compiler veery unhappy. so - ignore that, and use it anyway, bearing in mind that the name of the function _has_ to change. 2) there is a _single_ entrypoint linking the GTK-based Webkit GTK port to the Gobject-based Webkit Glib-DOM bindings code: webkit_web_frame_get_dom_document(). THAT'S ALL. once you've got that pointer to a GdomDocument, you can do _anything_ to or with the DOM model- without ever having to refer to the GTK code, _ever_ again. for those people who are involved in the Qt and the wxWidgets and other webkit ports, looking jealously at these shiny new glib/DOM bindings, i'm really talking to you, as yes you _can_ get glib/DOM bindings WITHOUT having to #include <gtk.h>. really. 3) the "load-finished" signal is hooked into purely so that the DOM model can be manipulated _after_ the web page has loaded. 4) load_finished_cb() is where the majority of the demo work takes place: a DIV tag is appended to the end of the document, with a Text Node added to that DIV tag. also note that the DIV's "id" attribute is set to "helloworld". lastly, an "onclick" is added to the DIV, by connecting to the shiny new "browser-event" signal. 5) when the DIV tag is clicked, dispatch_event_cb is called with the node that the event came from (in this case, the DIV tag) and the event itself. you can expect to be able to obtain, through the gobject properties, to obtain all the lovely things like the type (in this case it's a mouseevent) and then you will be able to get the x coords, y coords etc. etc. in the example code shown, what's being done is quite straightforward: all the hrefs of all anchor elements are printed out, whenever the DIV is clicked. 6) the get_dom_document() function is there purely for convenience, it's the equivalent of javascript global "document." and it references the static global web_view to get the frame and from that the frame's document. simple, really. to use this code, you'll need the following: https://bugs.webkit.org/attachment.cgi?id=25618 martin soto kindly rewrote the glib / gdom patch, and i've confirmed that the rewrite he's done doesn't make pywebkitgtk and pyjamas-desktop fall over, so there's at least _some_ confidence there that the code still does the job it's designed to do :) l.
f
Description: Binary data
_______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev