Find In Page

One WebKit feature I’ve exposed in Odysseus that I find very useful is “find in page”. That is pressing ctrl-f brings up a secondary toolbar in the topright corner of your webpage, for WebKit to highlight and scroll to whatever text you find.

(I think full-width find toolbars look like a waste of space unless it also has find&replace)

Today I think I’ll describe how WebKitGTK implements this, and see how long that takes me.

My code exposes a UI for the WebKit.FindController associated with the WebKit.WebView, which in turn mostly just wraps the wrapped WebPage’s .findString() method. This method call sent into the sandbox where it’s immediately forwarded to a FindController.

The FindController in turn wraps WebCore’s WebPage’s .findString() method, and sends it’s results back out of the sandbox to be routed to that WebKitGTK class to be exposed as GObject Signals.

The in-sandbox FindController also handles rendering an page overlay highlighting all the matches the WebCore Page has found, and the WebCore page in turn sends the method off to the Editors for all it’s Frames.

The Editor then calls it’s own .rangeOfString() method to finalize the range being searched, before calling TextIterator’s findPlainText function.

From there it simply flattens the DOM tree into a plain text string, so it can use normal String methods.