[evolution/webkit: 105/146] Implement e_web_view_get_selection_html() and port a forgotten GtkHTML call to it



commit ac097b4e75b11355af3db9a65e7a741b51bdc2d3
Author: Dan VrÃtil <dvratil redhat com>
Date:   Fri Jan 6 14:26:10 2012 +0100

    Implement e_web_view_get_selection_html() and port a forgotten GtkHTML call to it
    
    WebKit does not have any native way of getting selected text or it's HTML
    so we need to provide our own implementation via the DOM API.
    
    There was a forgotten call to gtk_html_get_selection_html() in
    e-mail-reader-utils.c which was causing crash, ported to the new EWebView call now.

 mail/e-mail-reader-utils.c |    3 ++-
 widgets/misc/e-web-view.c  |   36 ++++++++++++++++++++++++++++++++++++
 widgets/misc/e-web-view.h  |    2 ++
 3 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index bf1b8f8..01048f6 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -861,7 +861,8 @@ e_mail_reader_reply_to_message (EMailReader *reader,
 	if (!e_web_view_is_selection_active (web_view))
 		goto whole_message;
 
-	selection = gtk_html_get_selection_html (GTK_HTML (web_view), &length);
+        selection = e_web_view_get_selection_html (web_view);
+        length = strlen (selection);
 	if (selection == NULL || *selection == '\0')
 		goto whole_message;
 
diff --git a/widgets/misc/e-web-view.c b/widgets/misc/e-web-view.c
index b7af87f..617b06e 100644
--- a/widgets/misc/e-web-view.c
+++ b/widgets/misc/e-web-view.c
@@ -2608,3 +2608,39 @@ e_web_view_update_actions (EWebView *web_view)
 
 	g_signal_emit (web_view, signals[UPDATE_ACTIONS], 0);
 }
+
+gchar*
+e_web_view_get_selection_html (EWebView *web_view)
+{
+        WebKitDOMDocument *document;
+        WebKitDOMDOMWindow *window;
+        WebKitDOMDOMSelection *selection;
+        WebKitDOMRange *range;
+        WebKitDOMDocumentFragment *fragment;
+        WebKitDOMHTMLElement *element;
+
+        g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);
+
+        if (!webkit_web_view_has_selection (WEBKIT_WEB_VIEW (web_view)))
+                return NULL;
+
+        document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (web_view));
+        window = webkit_dom_document_get_default_view (document);
+        selection = webkit_dom_dom_window_get_selection (window);
+        if (!selection)
+                return NULL;
+
+        range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+        if (!range)
+                return NULL;
+
+        fragment = webkit_dom_range_clone_contents (range, NULL);
+        if (!fragment)
+                return NULL;
+
+        element = WEBKIT_DOM_HTML_ELEMENT (webkit_dom_document_create_element (document, "div", NULL));
+        webkit_dom_node_append_child (WEBKIT_DOM_NODE (element),
+                WEBKIT_DOM_NODE (fragment), NULL);
+
+        return webkit_dom_html_element_get_inner_html (element);
+}
diff --git a/widgets/misc/e-web-view.h b/widgets/misc/e-web-view.h
index 9beed9f..9e31ab9 100644
--- a/widgets/misc/e-web-view.h
+++ b/widgets/misc/e-web-view.h
@@ -214,6 +214,8 @@ void		e_web_view_status_message	(EWebView *web_view,
 void		e_web_view_stop_loading		(EWebView *web_view);
 void		e_web_view_update_actions	(EWebView *web_view);
 
+gchar*          e_web_view_get_selection_html   (EWebView *web_view);
+
 G_END_DECLS
 
 #endif /* E_WEB_VIEW_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]