[webkit-gtk] hovering-over-link signal and HitTestResult in WebKit2 API

Simon Schampijer simon at schampijer.de
Fri Jan 27 12:43:09 PST 2012

On 01/27/2012 02:56 PM, Carlos Garcia Campos wrote:
> Looking at liferea code I've noticed that they use
> WebKitWebView::hovering-over-link signal (ephy uses it too). This signal
> comes from ChromeClient::mouseDidMoveOverElement() and I was wondering
> whether it would be useful to expose it as a general signal in the API,
> instead of just for links. ChromeClient::mouseDidMoveOverElement
> receives a HitTestResult, in WebKit1 we are checking whether it's a link
> or not and then emitting WebKitWebView::hovering-over-link in case it's
> a link. In WebKit2 mouseDidMoveOverElement is a callback of the UI
> Client, that also receives a HitTestResult, so what do you think about
> exposing WebKitWebView::hovering-over-element?
> That also made me think about how to expose HitTestResult in the API. In
> WebKit1 it's only used by webkit_web_view_get_hit_test_result() (it
> sounds like a getter, but it actually performs a hit test and returns
> the result). In WK2 there's no API to make a hit test from the UI
> process, and I'm not sure it's actually needed. However, I think a
> HitTestResult object can be useful in the API, probably with a different
> name WebKitWebElement or something like that. This could be passed as an
> argument to the WebKitWebView::hovering-over-element signal, and it
> could be used for the context menu API.
> We could use a similar approach than WK1 HitTestResult object, it has
> flags to get information about the hoevered thing (whether it's a link,
> or image, or text selected, whether the area is editable, etc.) and the
> uri or the image, link or media. It also has the inner node, we can add
> later once we have DOM bindings in WK2.
> What do you think?

Hi Carlos,

that is interesting.

I am working on the port of the Sugar browser from xpcom to webkit and 
was wondering about something similar. My intended behavior is the 
following: when you 'right-click' on an element (e.g. link or image) in 
the page I want to associate a custom menu (e.g. copy/save) with it. 
When the mouse leaves the element the menu is hidden (the menu is as 
well hidden when the mouse leaves the menu but that logic is inside the 
menu itself), will look something like this [1].

xpcom has something like an event listener [2], so you could either 
listen on all of the dom (an element has been clicked for example) but 
you could also associate it with a specific element. For example I did 
code the 'right-click'-menu for an element with that - when you right 
click on an element (e.g. link) a menu (with save/copy etc) was 
displayed and then on the 'mouse-out' event on the element we did 
popdown the menu.

With webkitgtk, I used now the 'button-press'-signal on the webview and 
then used the WebKit.HitTestResult [3] to determine what type of element 
I am dealing with. Like you describing above actually. To me it would be 
interesting to know as well when we have the 'mouse-out' event for a 
specific element so I can popdown the menu. In Chrome/Epiphany/Firefox 
you have to hit esc to popdown the menu or click outside of it, in Sugar 
we have as well the 'hover-out' way of popping down a menu.


[1] http://wiki.sugarlabs.org/images/d/df/Browse_0.86_palettes_improved.png

More information about the webkit-gtk mailing list