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

Mario Sanchez Prada mario at webkit.org
Mon Oct 22 03:08:41 PDT 2012


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



More information about the webkit-gtk mailing list