Scrolling a WebKit2.Webkit window in GTK+3

▼魔方 西西 提交于 2019-12-22 08:24:07

问题


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.


回答1:


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...




回答2:


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.



来源:https://stackoverflow.com/questions/21781868/scrolling-a-webkit2-webkit-window-in-gtk3

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