aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc/e-web-view.c
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/misc/e-web-view.c')
-rw-r--r--widgets/misc/e-web-view.c89
1 files changed, 70 insertions, 19 deletions
diff --git a/widgets/misc/e-web-view.c b/widgets/misc/e-web-view.c
index e4d7be7e09..bb7f64e8bf 100644
--- a/widgets/misc/e-web-view.c
+++ b/widgets/misc/e-web-view.c
@@ -2847,15 +2847,66 @@ e_web_view_update_actions (EWebView *web_view,
g_signal_emit (web_view, signals[UPDATE_ACTIONS], 0, event);
}
-gchar *
-e_web_view_get_selection_html (EWebView *web_view)
+static gchar *
+web_view_get_frame_selection_html (WebKitDOMElement *iframe)
{
WebKitDOMDocument *document;
WebKitDOMDOMWindow *window;
WebKitDOMDOMSelection *selection;
- WebKitDOMRange *range;
- WebKitDOMDocumentFragment *fragment;
- WebKitDOMHTMLElement *element;
+ WebKitDOMNodeList *frames;
+ gulong ii, length;
+
+ document = webkit_dom_html_iframe_element_get_content_document (
+ WEBKIT_DOM_HTML_IFRAME_ELEMENT (iframe));
+ window = webkit_dom_document_get_default_view (document);
+ selection = webkit_dom_dom_window_get_selection (window);
+ if (selection && (webkit_dom_dom_selection_get_range_count (selection) > 0)) {
+ WebKitDOMRange *range;
+ WebKitDOMElement *element;
+ WebKitDOMDocumentFragment *fragment;
+
+ range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+ if (range) {
+ fragment = webkit_dom_range_clone_contents (
+ range, NULL);
+
+ 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 (
+ WEBKIT_DOM_HTML_ELEMENT (element));
+ }
+ }
+
+ frames = webkit_dom_document_get_elements_by_tag_name (
+ document, "IFRAME");
+ length = webkit_dom_node_list_get_length (frames);
+ for (ii = 0; ii < length; ii++) {
+ WebKitDOMNode *node;
+ gchar *text;
+
+ node = webkit_dom_node_list_item (frames, ii);
+
+ text = web_view_get_frame_selection_html (
+ WEBKIT_DOM_ELEMENT (node));
+
+ if (text) {
+ return text;
+ }
+ }
+
+ return NULL;
+}
+
+gchar *
+e_web_view_get_selection_html (EWebView *web_view)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMNodeList *frames;
+ gulong ii, length;
g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);
@@ -2863,24 +2914,24 @@ e_web_view_get_selection_html (EWebView *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;
+ frames = webkit_dom_document_get_elements_by_tag_name (document, "IFRAME");
+ length = webkit_dom_node_list_get_length (frames);
- range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
- if (!range)
- return NULL;
+ for (ii = 0; ii < length; ii++) {
+ gchar *text;
+ WebKitDOMNode *node;
- fragment = webkit_dom_range_clone_contents (range, NULL);
- if (!fragment)
- return NULL;
+ node = webkit_dom_node_list_item (frames, ii);
- 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);
+ text = web_view_get_frame_selection_html (
+ WEBKIT_DOM_ELEMENT (node));
- return webkit_dom_html_element_get_inner_html (element);
+ if (text) {
+ return text;
+ }
+ }
+
+ return NULL;
}
void