Browsing in Tk: Enticing Firefox into Tk and Tkhtml3

The next two afternoon talks (Steve Landers and then Dan Kennedy, both very talented programmers from down under) both deal with the marriage of web browsing and Tcl/Tk. I'll report on both of them together.

Entice: Embedding Firefox in Tk

Steve Landers: "I was going to write a language called S but that was already taken. Now L is too."

"Tcl meets Ajax. 100% buzzword compliant."

Embedding browsers in Tk

Possible approaches

  1. Browser library wrapped as a Tcl extension (TkGecko). Pro's: complete, controllable from Tcl. Cons: can't be self-contained. Huge footprint. Difficult to build Gecko.
  2. Tk-based browser (TkHTML). Pro's: 80/20 approach, can be self-contained, easy to control from Tcl. Con's: some situations need the last 20% (that percentage decreasing over time as work on TkHTML3 progresses).
  3. Re-parent browser window into Tk container. Pro's fully featured browser. Cons: not so easy to control from Tcl. Applications aren't self contained.

Entice is built on top of [frame -container], and GPS's TkXext (search for X11 window ID by window title, get a handle, re-parent the window by ID).

Firefox talks back to the entice library on a server socket listening from Tcl. Various security features. Tell firefox to connect back to localhost on Entice's port, and get a custom chrome (.xul). Entice substitutes the listening port into the .xul and sends to Firefox.

Controlling Firefox via XMLHttpRequest. Javascript object running in the browser that waits asyncronously for a connection. Basically a GET operation that is asyncronous. It is at the heart of AJAX.

Thanks to GPS for making it possible (TkXext) and Mike Doyle for sponsoring it.


Tkhtml3

The problem with existing HTML widgets is simple: "Most documents found on the WWW are rendered incorrectly." Lightweight web browsers generally have the same problems (often because CSS is not supported well—if at all).

Although not always possible, Tkhtml3 tries to focus on CSS. Delegates most HTML functionality to the application. More of a CSS renderer than an HTML renderer.

Anticipated uses

HTML can be specified incrementally. .css (zero to many) must be fully prepared.

The document tree: constructed by parsing step, creates a tree. Not DOM compatible (but provides simillar levels of functionality). For the time being only read access to the tree is provided.

Document tree can be queried: for root node, for all nodes that match a specific selector, for whats under a given mouse coordinate.

Tkhtml does not implement hyperlinks(!). Applications are expected to:

This approach makes for maximum flexibility.

Element handlers: parse handlers, script handlers, and node handlers.

To support images the application implements the -imagecmd callback. The callback is given a URI and is expected to return a Tk image.

Tkhtml3 uses images as backgrounds, list markers, and as replaced content.

Replacement objects. Any node in the tree can be mapped to display in another widget in place of a node's content.

Applications can specify regions of text to be tagged.

Hv3: A web browser built using Tkhtml3

Leverages existing Tcl/Tk extensions. [img] allows it to support more image types than any other web browser(!). The tls package for SSL, etc.

Project status

Available at tkhtml.tcl.tk. The shared library on Linux is ~220kb.


—Michael A. Cleverly

Comment:

  1. John Cocke wrote (at Thu, 13 Aug 2009, 20:41):

Being able to embed something like XUL into Tcl/Tk would be great! It's hard to tell from this web page whether this is possible. (If it is, please provide some details.)

Thanks!!

Permanent URL for this post: http://blog.cleverly.com/permalinks/252.html