Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling a WebKit2.Webkit window in GTK+3

How does one scroll a webkit2gtk widget?

In webkitgtk (aka. webkit1) you wrap your WebView in a ScrolledWindow, so can use its vadjustment property.

For wekit2gtk, this call on the WebView just returns None, and I see no other method to call.

As an explanation, I want to add touch support to webkit2. I have hacked my way into this by adding a transparent layer over the WebView widget¹, but now I'm detecting touches I seem unable to use them.

¹ A release that came out today has removed the need for the layer on-top. Nevertheless, I have touches and nothing I can do with them.

like image 834
Veedrac Avatar asked Feb 14 '14 14:02

Veedrac


2 Answers

The process separation in WebKit2 has some advantages, but it also makes many things more complex. I believe scrolling is one of those things: it happens in the web process because scrollbars are now handled by webkit, and not the Gtk widget. The same should hold for touch handling: it is partly done in the web process. Carlos Garcia Campos has written a blog post about using WebKitWebExtension to help in this. Note that the design has lots of implications on your code as well: Part of the code will be running in a totally different process.

The rest of the answer is not tested, please consider this more like an educated guess:

I believe the way to control scrolling is through the DOM API, more specifically DOMDOMWindow.scroll* functions. The complex part is getting a reference to the DOMDOMWindow -- You'll need to implement a WebExtension which will be running in the web process and will allow you to get notified when a WebPage is created. The WebPage.get_dom_document() call gives you a DOMDocument and DOMDocument.get_default_view() should then give you the DOMDOMWindow you need.

For the DOM API documentation, Mozilla is probably a better reference than the spartan WebKit-GTK-DOM documentation.

If I was doing what you are trying to do, my first stop would be the #webkitgtk+ IRC channel on Freenode to check if the above really is a sane way to do what you want...

like image 89
Jussi Kukkonen Avatar answered Sep 17 '22 22:09

Jussi Kukkonen


You could run some javascript to scroll the page. The C API has the function webkit_web_view_run_javascript() so you could feed it some javascript like

window.scrollTo(500,0);

and the page should scroll.

like image 21
iain Avatar answered Sep 17 '22 22:09

iain