From 94ec73c74c9362a535e1e1a456c10bd97c18a82b Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Sat, 6 Aug 2011 13:32:40 +0000 Subject: [PATCH] Implement GetSelectedSource for the OSX WebKit backend. 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 | 2 +- src/osx/webview_webkit.mm | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index a455f18222..4af95519a5 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -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); diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index e1ebe148f5..2285278f6a 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -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]