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
This commit is contained in:
Steve Lamerton
2011-07-15 09:36:08 +00:00
parent 0609769d3b
commit 41933aa5a0
8 changed files with 39 additions and 0 deletions

View File

@@ -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;

View File

@@ -104,6 +104,7 @@ public:
virtual void DeleteSelection();
virtual wxString GetSelectedText();
virtual wxString GetSelectedSource();
virtual void ClearSelection();
// ---- IE-specific methods

View File

@@ -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);

View File

@@ -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?

View File

@@ -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

View File

@@ -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;

View File

@@ -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();

View File

@@ -207,6 +207,9 @@ void WebTestCase::Selection()
//We lower case the result as ie returns tags in uppercase
CPPUNIT_ASSERT_EQUAL("some <strong>strong</strong> text",
m_browser->GetSelectedSource().Lower());
m_browser->ClearSelection();
CPPUNIT_ASSERT(!m_browser->HasSelection());
}
void WebTestCase::Zoom()