From 41933aa5a0de47e845a833127a99f7ae9f3df2ea Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Fri, 15 Jul 2011 09:36:08 +0000 Subject: [PATCH] Add ClearSelection for msw ie and gtk webkit, with a stub for osx webkit. Document and add to unit tests. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68274 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/webview_webkit.h | 1 + include/wx/msw/webview_ie.h | 1 + include/wx/osx/webview_webkit.h | 1 + include/wx/webview.h | 1 + interface/wx/webview.h | 5 +++++ src/gtk/webview_webkit.cpp | 13 +++++++++++++ src/msw/webview_ie.cpp | 14 ++++++++++++++ tests/controls/webtest.cpp | 3 +++ 8 files changed, 39 insertions(+) diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index 15b919374c..e675d5d98a 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -147,6 +147,7 @@ public: virtual void SelectAll(); virtual wxString GetSelectedText(); virtual wxString GetSelectedSource(); + virtual void ClearSelection(); /** FIXME: hack to work around signals being received too early */ bool m_ready; diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index efc13b61ed..5d854abd9d 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -104,6 +104,7 @@ public: virtual void DeleteSelection(); virtual wxString GetSelectedText(); virtual wxString GetSelectedSource(); + virtual void ClearSelection(); // ---- IE-specific methods diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index cbf0af2851..a30f95cccb 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -109,6 +109,7 @@ public: virtual void SelectAll() {}; virtual wxString GetSelectedText(); virtual wxString GetSelectedSource() { return ""; } + virtual void ClearSelection() {} // ---- methods not from the parent (common) interface wxString RunScript(const wxString& javascript); diff --git a/include/wx/webview.h b/include/wx/webview.h index 5d846a1d9a..22d9a2cbbc 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -290,6 +290,7 @@ public: virtual void DeleteSelection() = 0; virtual wxString GetSelectedText() = 0; virtual wxString GetSelectedSource() = 0; + virtual void ClearSelection() = 0; // TODO: // void EnableJavascript(bool enabled); // maybe? diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 85e9a235eb..2ee3844688 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -391,6 +391,11 @@ public: @name Selection */ + /** + Clears the current selection. + */ + virtual void ClearSelection() = 0; + /** Deletes the current selection. Note that for @c wxWEB_VIEW_BACKEND_WEBKIT the selection must be editable, either through SetEditable or the diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index 4305f30675..11304653d6 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -768,6 +768,19 @@ wxString wxWebViewWebKit::GetSelectedSource() wxConvUTF8); } +void wxWebViewWebKit::ClearSelection() +{ + WebKitDOMDocument* doc; + WebKitDOMDOMWindow* win; + WebKitDOMDOMSelection* sel; + + 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)); + webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel)); + +} + wxString wxWebViewWebKit::GetPageText() { WebKitDOMDocument* doc; diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 343699581c..01d0061146 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -655,6 +655,20 @@ wxString wxWebViewIE::GetSelectedSource() return selected; } +void wxWebViewIE::ClearSelection() +{ + IHTMLDocument2* document = GetDocument(); + IHTMLSelectionObject* selection; + wxString selected; + HRESULT hr = document->get_selection(&selection); + if(SUCCEEDED(hr)) + { + selection->empty(); + selection->Release(); + } + document->Release(); +} + wxString wxWebViewIE::GetPageText() { IHTMLDocument2* document = GetDocument(); diff --git a/tests/controls/webtest.cpp b/tests/controls/webtest.cpp index 3e3b4cafda..8154a9032b 100644 --- a/tests/controls/webtest.cpp +++ b/tests/controls/webtest.cpp @@ -207,6 +207,9 @@ void WebTestCase::Selection() //We lower case the result as ie returns tags in uppercase CPPUNIT_ASSERT_EQUAL("some strong text", m_browser->GetSelectedSource().Lower()); + + m_browser->ClearSelection(); + CPPUNIT_ASSERT(!m_browser->HasSelection()); } void WebTestCase::Zoom() -- 2.45.2