diff options
author | Claudio Saavedra <csaavedra@igalia.com> | 2015-06-04 15:53:00 +0300 |
---|---|---|
committer | Claudio Saavedra <csaavedra@igalia.com> | 2015-06-09 15:02:16 +0300 |
commit | b516557124a4372e47418cfc51692c2d75e89aec (patch) | |
tree | 917f2f94c51adfacb6cbb4118ae1e37498a37c2b | |
parent | b92a519ab577c1eb22f6f24dfc5c57da43746048 (diff) | |
download | epiphany-b516557124a4372e47418cfc51692c2d75e89aec.tar.gz |
ephy-web-dom-utils: add ephy_web_dom_utils_get_selection_as_string()
The DOMSelection::toString() API is only bound to JavaScript. This method
does not work with selection inside input elements.
https://bugzilla.gnome.org/show_bug.cgi?id=663545
-rw-r--r-- | lib/ephy-web-dom-utils.c | 22 | ||||
-rw-r--r-- | lib/ephy-web-dom-utils.h | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/ephy-web-dom-utils.c b/lib/ephy-web-dom-utils.c index 75c586cf5..2a75da887 100644 --- a/lib/ephy-web-dom-utils.c +++ b/lib/ephy-web-dom-utils.c @@ -492,3 +492,25 @@ ephy_web_dom_utils_get_absolute_bottom_for_element (WebKitDOMElement *element, *y += offset_height; } + +/** + * ephy_web_dom_utils_get_selection_as_string: + * @selection: the #WebKitDOMDOMSelection. + * + * Gets the contents of the selection as a string. + * + * Returns: a newly allocated string with the selection or %NULL. + **/ +char * +ephy_web_dom_utils_get_selection_as_string (WebKitDOMDOMSelection *selection) +{ + char *string; + WebKitDOMRange *range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL); + if (!range) + return NULL; + + string = webkit_dom_range_to_string (range, NULL); + g_object_unref (range); + + return string; +} diff --git a/lib/ephy-web-dom-utils.h b/lib/ephy-web-dom-utils.h index caa822813..c2cc9a59c 100644 --- a/lib/ephy-web-dom-utils.h +++ b/lib/ephy-web-dom-utils.h @@ -25,6 +25,8 @@ #define EPHY_WEB_DOM_UTILS_H #include <webkitdom/webkitdom.h> +#define WEBKIT_DOM_USE_UNSTABLE_API +#include <webkitdom/WebKitDOMDOMSelection.h> G_BEGIN_DECLS @@ -48,6 +50,8 @@ void ephy_web_dom_utils_get_absolute_bottom_for_element (WebKitDOMElement *eleme void ephy_web_dom_utils_get_absolute_position_for_element(WebKitDOMElement *element, long *x, long *y); + +char *ephy_web_dom_utils_get_selection_as_string (WebKitDOMDOMSelection *selection); G_END_DECLS #endif |