]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement GetSelectedSource for the OSX WebKit backend.
authorSteve Lamerton <steve.lamerton@gmail.com>
Sat, 6 Aug 2011 13:32:40 +0000 (13:32 +0000)
committerSteve Lamerton <steve.lamerton@gmail.com>
Sat, 6 Aug 2011 13:32:40 +0000 (13:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/webview_webkit.h
src/osx/webview_webkit.mm

index a455f18222ae703d2ecacff96d6bf050a5651a8d..4af95519a589ce0aa05a954f95bd8993b94814f8 100644 (file)
@@ -108,7 +108,7 @@ public:
     virtual bool HasSelection();
     virtual void SelectAll();
     virtual wxString GetSelectedText();
-    virtual wxString GetSelectedSource() { return ""; }
+    virtual wxString GetSelectedSource();
     virtual void ClearSelection();
     
     void RunScript(const wxString& javascript);
index e1ebe148f5d8155190ea22d062a44eaa88d54d55..2285278f6a7d3d9fa52ec9de58100045c02c820f 100644 (file)
@@ -925,6 +925,17 @@ void wxWebViewWebKit::SelectAll()
     RunScript("window.getSelection().selectAllChildren(document.body);");
 }
 
+wxString wxWebViewWebKit::GetSelectedSource()
+{
+    wxString script = ("var range = window.getSelection().getRangeAt(0);"
+                       "var element = document.createElement('div');"
+                       "element.appendChild(range.cloneContents());"
+                       "return element.innerHTML;");
+    id result = [[m_webView windowScriptObject]
+                   evaluateWebScript:wxNSStringWithWxString(script)];
+    return wxStringWithNSString([result stringValue]);
+}
+
 wxString wxWebViewWebKit::GetPageText()
 {
     id result = [[m_webView windowScriptObject]