]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement GetSelectedHTML for the ie and gtk webkit backends and document.
authorSteve Lamerton <steve.lamerton@gmail.com>
Mon, 11 Jul 2011 18:26:07 +0000 (18:26 +0000)
committerSteve Lamerton <steve.lamerton@gmail.com>
Mon, 11 Jul 2011 18:26:07 +0000 (18:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/webview_webkit.h
include/wx/msw/webview_ie.h
include/wx/osx/webview_webkit.h
include/wx/webview.h
interface/wx/webview.h
src/gtk/webview_webkit.cpp
src/msw/webview_ie.cpp

index 205caa6282d3b3761606eee0f8e14d0374524bc3..a98d3a3fa3a6da6b4c896de7781d0dec3c633ca5 100644 (file)
@@ -145,6 +145,7 @@ public:
     virtual bool HasSelection();
     virtual void SelectAll();
     virtual wxString GetSelectedText();
+    virtual wxString GetSelectedHTML();
 
     /** FIXME: hack to work around signals being received too early */
     bool m_ready;
index 8255f5bc09d0469952aa046ae57db8e81847277a..0968683fb51d2f20b7aa9d9e13f5f5732d20fc0e 100644 (file)
@@ -102,6 +102,7 @@ public:
     virtual bool HasSelection();
     virtual void DeleteSelection();
     virtual wxString GetSelectedText();
+    virtual wxString GetSelectedHTML();
 
 
     // ---- IE-specific methods
index 0a3ec2d638f62a753ada1dea7bc47bd2274b3ade..db43f35a3ee3b0f6768945003a2bc45345476157 100644 (file)
@@ -107,6 +107,7 @@ public:
     virtual bool HasSelection() { return false };
     virtual void SelectAll() {};
     virtual wxString GetSelectedText();
+    virtual wxString GetSelectedHTML() { return ""; }
 
     // ---- methods not from the parent (common) interface
     wxString RunScript(const wxString& javascript);
index 06aa126ef3d3c87e59a0c69150ece5df2aa12b5b..5514cf10a1fa9b5ef640b99285bdff0ef6637db8 100644 (file)
@@ -288,6 +288,7 @@ public:
     virtual bool HasSelection() = 0;
     virtual void DeleteSelection() = 0;
     virtual wxString GetSelectedText() = 0;
+    virtual wxString GetSelectedHTML() = 0;
 
     // TODO:
     //     void EnableJavascript(bool enabled);             // maybe?
index 441dd6894a390cd0a1334688072be2f2a9434c2a..0fb9ca61485c83c43f828f33a2d13a2d115fbd98 100644 (file)
@@ -393,6 +393,11 @@ public:
     */
     virtual void DeleteSelection() = 0;
     
+    /**
+        Returns the currently selected HTML, if any.
+    */
+    virtual wxString GetSelectedHTML() = 0;
+    
     /**
         Returns the currently selected text, if any.
     */
index 347b19c5d976bae80d14f0342886a9405e1babfe..8359ecd301a0ec384c9b80130294c6802d7b1c33 100644 (file)
@@ -743,6 +743,31 @@ wxString wxWebViewWebKit::GetSelectedText()
                     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
 wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
index 2e4e7a2e758e1f5cbf5f6e07922c30d147ccc19f..b0ead6e81c1e37367576e974ddf672b239ef4301 100644 (file)
@@ -614,6 +614,35 @@ wxString wxWebViewIE::GetSelectedText()
     return selected;
 }
 
+wxString wxWebViewIE::GetSelectedHTML()
+{
+    IHTMLDocument2* document = GetDocument();
+    IHTMLSelectionObject* selection;
+    wxString selected;
+    HRESULT hr = document->get_selection(&selection);
+    if(SUCCEEDED(hr))
+    {
+        IDispatch* disrange;
+        hr = selection->createRange(&disrange);
+        if(SUCCEEDED(hr))
+        {
+            IHTMLTxtRange* range;
+            hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
+            if(SUCCEEDED(hr))
+            {
+                BSTR text;
+                range->get_htmlText(&text);
+                selected = wxString(text);
+                range->Release();
+            }
+            disrange->Release();
+        }
+        selection->Release();
+    }
+    document->Release();
+    return selected;
+}
+
 bool wxWebViewIE::CanExecCommand(wxString command)
 {
     IHTMLDocument2* document = GetDocument();