[webkit-gtk] Moving the caret with "enable-caret-browsing" set

Nicholas Bishop nicholasbishop at gmail.com
Sat Nov 3 17:06:56 PDT 2012


As suggested, I am trying out the Atk API to move the caret. I didn't
see any public webkit_web_view_get_accessible() function, but
gtk_widget_get_accessible() seems to do the trick.

I'm trying to figure out how to use the API for this by printing out
the AtkObject tree of a webkit view. What I cannot see is any property
that indicates where in the tree the caret currently is. Calling
atk_text_get_caret_offset() on an AtkText object in the tree gives
mysterious values -- objects that are nowhere near the caret have
greater-than-zero values. There doesn't seem to be a signal value like
-1 to indicate the caret isn't there.

I also tried getting the AtkStateSet for text objects, but it only
ever contains ATK_STATE_ENABLED, ATK_STATE_SENSITIVE,
ATK_STATE_SHOWING, and ATK_STATE_VISIBLE. I was hoping the one with
the caret would have ATK_STATE_FOCUSED, but seems not.

Finally, I tried atk_text_get_n_selections() to see if the caret
counted as zero-length selection, but seems not.

Any further hints?

Thanks,
-Nicholas

> Date: Mon, 22 Oct 2012 12:08:41 +0200
> From: Mario Sanchez Prada <mario at webkit.org>
> To: webkit-gtk at lists.webkit.org
> Subject: Re: [webkit-gtk] Moving the caret with
>         "enable-caret-browsing" set
> Message-ID: <1350900521.10623.21.camel at zoiberg>
> Content-Type: text/plain; charset="UTF-8"
>
> On Sat, 2012-10-20 at 16:16 -0400, Nicholas Bishop wrote:
>> With the "enable-caret-browsing" option set on a WebkitWebView, is it
>> possible to programatically move the caret with respect to lines of
>> text as they are appear on screen? For example, move to end of visual
>> line rather than move to end of DOM node.
>>
>> This behavior is accessible through keyboard navigation (e.g. the End
>> key goes to end of visual line), but couldn't find anything in the API
>> for this.
>
> You need to use the accessibility APIs for this, that is, the ATK
> interfaces that are implemented by the accessibility objects in
> WebKitGTK+, for which you first need to get the AtkObject wrapping the
> web element you're interested in. Calling
> webkit_web_view_get_accessible() gives you the AtkObject for the
> WebView, and then you can go down in the a11y hierarchy by means of
> AtkObject's methods.
>
> Regarding to how to manipulate the caret, in your case you should use
> the functions from the AtkText interface that allows you to get and set
> the caret for a given element in the accessibility hierarchy
> implementing that interface (e.g. a paragraph, a link, a label, a text
> entry...):
>
>   atk_text_get_caret_offset()
>   atk_text_set_caret_offset()
>
> If you want to know more detailed information, such as where the next
> word starts, or where the current line ends, you need to use one of the
> following functions first, specifying the right value for the
> AtkTextBoundary parameter:
>
>   atk_text_get_text_before_offset()
>   atk_text_get_text_at_offset
>   atk_text_get_text_after_offset()
>
> Not sure if there's a better way to do that, though.
>
> Hope this helps,
> Mario
>
>
>
> ------------------------------
>
> _______________________________________________
> webkit-gtk mailing list
> webkit-gtk at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-gtk
>
>
> End of webkit-gtk Digest, Vol 40, Issue 12
> ******************************************


More information about the webkit-gtk mailing list