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 ¹, but now I'm detecting touches I seem unable to use them.WebView
widget
¹ 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.
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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With