[webkit-dev] webkit glib DOM bindings demo code
Luke Kenneth Casson Leighton
lkcl at lkcl.net
Mon Dec 8 06:03:46 PST 2008
here's a second example:
static void walk_table_node(GdomNode *node)
{
GdomNode *child;
g_object_get(node, "first_child", &child, NULL);
while (child)
{
gchar *name;
g_object_get(child, "node_name", &name, NULL);
printf("table child node %s\n", name);
if (strcmp(name, "tr") == 0)
{
walk_tr_node(child); /* etc. etc. */
}
g_object_get(child, "next_sibling", &child, NULL);
}
}
void walk_all_tables (void)
{
GdomDocument *doc = get_dom_document();
GdomNodeList *els;
gulong tags_length;
gulong i;
els = gdom_document_get_elements_by_tag_name(doc, "table");
g_object_get(els, "length", &tags_length, NULL);
printf("table count: %d\n", tags_length);
for (i = 0; i < tags_length; i++)
{
walk_table_node(gdom_node_list_item(els, i));
}
}
as can be seen:
* els = document.getElementsByTagName("table") is replaced by
gdom_document_get_elements_by_tag_name(doc, "table");
* els.length is replaced by g_object_get(els, &length, NULL); where
length MUST be an unsigned long (not an unsigned int - i made that
mistake already :) it's VITAL to check the idl file - NodeList.idl in
this case)
* els.item(i) is replaced by gdom_node_list_item(els, i);
* node.firstChild, node.nodeName, node.nextSibling all again use
g_object_get() to obtain those properties.
this is all in c.
it's the same sort of thing in python with pywebkitgtk - except
_slightly_ less messy. in pyjamas-desktop, once i get round to it, the
messy names will go away, and revert back to
moreSensibleNamingSchemes.
i'm recommending to change the naming schemes back to more sensible
ones than_this_stupid_looking_one, on the basis that the convention
has already been decided by netscape, and is now a specification.
mozilla doesn't do this (in xul interface bindings), so why it's being
done here is ... it just makes things _bizarre_.
thoughts, anyone?
l.
More information about the webkit-dev
mailing list