]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/webview_webkit.cpp
Update selection unit test to test GetSelectedHTML.
[wxWidgets.git] / src / gtk / webview_webkit.cpp
index dd9a375a755e96f8bddc9b3f12a357675cbf244f..8359ecd301a0ec384c9b80130294c6802d7b1c33 100644 (file)
@@ -26,7 +26,7 @@ extern "C"
 {
 
 static void
-wxgtk_webkitctrl_load_status_callback(GtkWidget* widget, GParamSpec* arg1,
+wxgtk_webkitctrl_load_status_callback(GtkWidget* widget, GParamSpec*,
                                       wxWebViewWebKit *webKitCtrl)
 {
     if (!webKitCtrl->m_ready) return;
@@ -61,7 +61,7 @@ wxgtk_webkitctrl_load_status_callback(GtkWidget* widget, GParamSpec* arg1,
 }
 
 static WebKitNavigationResponse
-wxgtk_webkitctrl_navigation_requ_callback(WebKitWebView        *web_view,
+wxgtk_webkitctrl_navigation_requ_callback(WebKitWebView*,
                                           WebKitWebFrame       *frame,
                                           WebKitNetworkRequest *request,
                                           wxWebViewWebKit      *webKitCtrl)
@@ -92,8 +92,8 @@ wxgtk_webkitctrl_navigation_requ_callback(WebKitWebView        *web_view,
 }
 
 static gboolean
-wxgtk_webkitctrl_error (WebKitWebView  *web_view,
-                        WebKitWebFrame *web_frame,
+wxgtk_webkitctrl_error (WebKitWebView*,
+                        WebKitWebFrame*,
                         gchar          *uri,
                         gpointer        web_error,
                         wxWebViewWebKit* webKitWindow)
@@ -235,10 +235,10 @@ wxgtk_webkitctrl_error (WebKitWebView  *web_view,
 }
 
 static gboolean
-wxgtk_webkitctrl_new_window(WebKitWebView *webView,
+wxgtk_webkitctrl_new_window(WebKitWebView*,
                             WebKitWebFrame *frame,
                             WebKitNetworkRequest *request,
-                            WebKitWebNavigationAction *navigation_action,
+                            WebKitWebNavigationAction*,
                             WebKitWebPolicyDecision *policy_decision,
                     wxWebViewWebKit *webKitCtrl)
 {
@@ -727,6 +727,46 @@ void wxWebViewWebKit::SelectAll()
     webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view));
 }
 
+wxString wxWebViewWebKit::GetSelectedText()
+{
+    WebKitDOMDocument* doc; 
+    WebKitDOMDOMWindow* win;
+    WebKitDOMDOMSelection* sel;
+    WebKitDOMRange* range;
+
+    doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
+    win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
+    sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win));
+    range = webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel), 
+                                                  0, NULL);
+    return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range)), 
+                    wxConvUTF8);
+}
+
+wxString wxWebViewWebKit::GetSelectedHTML()
+{
+    WebKitDOMDocument* doc; 
+    WebKitDOMDOMWindow* win;
+    WebKitDOMDOMSelection* sel;
+    WebKitDOMRange* range;
+    WebKitDOMElement* div;
+    WebKitDOMDocumentFragment* clone;
+    WebKitDOMHTMLElement* html;
+
+    doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
+    win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
+    sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win));
+    range = webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel), 
+                                                  0, NULL);
+    div = webkit_dom_document_create_element(WEBKIT_DOM_DOCUMENT(doc), "div", NULL);
+
+    clone = webkit_dom_range_clone_contents(WEBKIT_DOM_RANGE(range), NULL);
+    webkit_dom_node_append_child(&div->parent_instance, &clone->parent_instance, NULL);
+    html = (WebKitDOMHTMLElement*)div;
+
+    return wxString(webkit_dom_html_element_get_inner_html(WEBKIT_DOM_HTML_ELEMENT(html)), 
+                    wxConvUTF8);
+}
 
 // static
 wxVisualAttributes