Scrolling a WebKit2.Webkit window in GTK+3

落爺英雄遲暮 提交于 2019-12-05 16:14:13

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!