From: Steve Lamerton Date: Wed, 13 Jul 2011 17:25:05 +0000 (+0000) Subject: Add GetPageText to MSW IE and to GTK WebKit. Add stub for OSX and document. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/241b769f9670cd372c45db51f5f71ba83f93bad5 Add GetPageText to MSW IE and to GTK WebKit. Add stub for OSX and document. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68250 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index d1c717e3a9..15b919374c 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -110,6 +110,7 @@ public: virtual wxString GetCurrentURL(); virtual wxString GetCurrentTitle(); virtual wxString GetPageSource(); + virtual wxString GetPageText(); //We do not want to hide the other overloads using wxWebView::SetPage; virtual void SetPage(const wxString& html, const wxString& baseUrl); diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index 9e0132187e..416b54047c 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -63,6 +63,7 @@ public: virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); virtual wxString GetPageSource(); + virtual wxString GetPageText(); virtual bool IsBusy(); virtual wxString GetCurrentURL(); diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index dcab0e31a0..cbf0af2851 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -56,6 +56,7 @@ public: virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); virtual void Stop(); virtual wxString GetPageSource(); + virtual wxString GetPageText() { return ""; } virtual void SetPageTitle(const wxString& title) { m_pageTitle = title; } virtual wxString GetPageTitle(){ return m_pageTitle; } diff --git a/include/wx/webview.h b/include/wx/webview.h index 1d448e9e9c..5d846a1d9a 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -222,6 +222,7 @@ public: * shown */ virtual wxString GetPageSource() = 0; + virtual wxString GetPageText() = 0; /** * Get the zoom factor of the page diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 3f521c6e69..85e9a235eb 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -226,6 +226,11 @@ public: */ virtual wxString GetPageSource() = 0; + /** + Get the text of the current page. + */ + virtual wxString GetPageText() = 0; + /** Returns whether the web control is currently busy (e.g. loading a page). */ diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index f81872e412..4305f30675 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -768,6 +768,17 @@ wxString wxWebViewWebKit::GetSelectedSource() wxConvUTF8); } +wxString wxWebViewWebKit::GetPageText() +{ + WebKitDOMDocument* doc; + WebKitDOMHTMLElement* body; + + doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view)); + body = webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc)); + return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body)), + wxConvUTF8); +} + // static wxVisualAttributes wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 9cbb0b74ca..83accbe58b 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -643,6 +643,21 @@ wxString wxWebViewIE::GetSelectedSource() return selected; } +wxString wxWebViewIE::GetPageText() +{ + IHTMLDocument2* document = GetDocument(); + BSTR out; + IHTMLElement* body; + HRESULT hr = document->get_body(&body); + if(SUCCEEDED(hr)) + { + body->get_innerText(&out); + body->Release(); + } + document->Release(); + return wxString(out); +} + bool wxWebViewIE::CanExecCommand(wxString command) { IHTMLDocument2* document = GetDocument();