Add RunScript and implement on all backends. Document and add a very simple unit test.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68275 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -149,6 +149,8 @@ public:
|
|||||||
virtual wxString GetSelectedSource();
|
virtual wxString GetSelectedSource();
|
||||||
virtual void ClearSelection();
|
virtual void ClearSelection();
|
||||||
|
|
||||||
|
virtual void RunScript(const wxString& javascript);
|
||||||
|
|
||||||
/** FIXME: hack to work around signals being received too early */
|
/** FIXME: hack to work around signals being received too early */
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
|
||||||
|
@@ -106,6 +106,7 @@ public:
|
|||||||
virtual wxString GetSelectedSource();
|
virtual wxString GetSelectedSource();
|
||||||
virtual void ClearSelection();
|
virtual void ClearSelection();
|
||||||
|
|
||||||
|
virtual void RunScript(const wxString& javascript);
|
||||||
|
|
||||||
// ---- IE-specific methods
|
// ---- IE-specific methods
|
||||||
|
|
||||||
|
@@ -110,10 +110,10 @@ public:
|
|||||||
virtual wxString GetSelectedText();
|
virtual wxString GetSelectedText();
|
||||||
virtual wxString GetSelectedSource() { return ""; }
|
virtual wxString GetSelectedSource() { return ""; }
|
||||||
virtual void ClearSelection() {}
|
virtual void ClearSelection() {}
|
||||||
|
|
||||||
|
void RunScript(const wxString& javascript);
|
||||||
|
|
||||||
// ---- methods not from the parent (common) interface
|
// ---- methods not from the parent (common) interface
|
||||||
wxString RunScript(const wxString& javascript);
|
|
||||||
|
|
||||||
bool CanGetPageSource();
|
bool CanGetPageSource();
|
||||||
|
|
||||||
void SetScrollPos(int pos);
|
void SetScrollPos(int pos);
|
||||||
|
@@ -292,9 +292,11 @@ public:
|
|||||||
virtual wxString GetSelectedSource() = 0;
|
virtual wxString GetSelectedSource() = 0;
|
||||||
virtual void ClearSelection() = 0;
|
virtual void ClearSelection() = 0;
|
||||||
|
|
||||||
|
virtual void RunScript(const wxString& javascript) = 0;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// void EnableJavascript(bool enabled); // maybe?
|
// void EnableJavascript(bool enabled); // maybe?
|
||||||
// wxString RunScript(const wxString& javascript); // maybe?
|
// // maybe?
|
||||||
|
|
||||||
// void SetScrollPos(int pos); // maybe?
|
// void SetScrollPos(int pos); // maybe?
|
||||||
// int GetScrollPos(); // maybe?
|
// int GetScrollPos(); // maybe?
|
||||||
|
@@ -262,6 +262,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
|
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Runs the given javascript code.
|
||||||
|
*/
|
||||||
|
virtual void RunScript(const wxString& javascript) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the editable property of the web control. Enabling allows the user
|
Set the editable property of the web control. Enabling allows the user
|
||||||
to edit the page even if the @c contenteditable attribute is not set.
|
to edit the page even if the @c contenteditable attribute is not set.
|
||||||
|
@@ -792,6 +792,12 @@ wxString wxWebViewWebKit::GetPageText()
|
|||||||
wxConvUTF8);
|
wxConvUTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxWebViewWebKit::RunScript(const wxString& javascript)
|
||||||
|
{
|
||||||
|
webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view),
|
||||||
|
javascript.mb_str(wxConvUTF8));
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
wxVisualAttributes
|
wxVisualAttributes
|
||||||
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||||
|
@@ -686,6 +686,22 @@ wxString wxWebViewIE::GetPageText()
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxWebViewIE::RunScript(const wxString& javascript)
|
||||||
|
{
|
||||||
|
IHTMLDocument2* document = GetDocument();
|
||||||
|
IHTMLWindow2* window;
|
||||||
|
wxString language = "javascript";
|
||||||
|
HRESULT hr = document->get_parentWindow(&window);
|
||||||
|
if(SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
VARIANT level;
|
||||||
|
VariantInit(&level);
|
||||||
|
V_VT(&level) = VT_EMPTY;
|
||||||
|
window->execScript(SysAllocString(javascript), SysAllocString(language), &level);
|
||||||
|
}
|
||||||
|
document->Release();
|
||||||
|
}
|
||||||
|
|
||||||
bool wxWebViewIE::CanExecCommand(wxString command)
|
bool wxWebViewIE::CanExecCommand(wxString command)
|
||||||
{
|
{
|
||||||
IHTMLDocument2* document = GetDocument();
|
IHTMLDocument2* document = GetDocument();
|
||||||
|
@@ -732,42 +732,13 @@ wxString wxWebViewWebKit::GetSelectedText()
|
|||||||
return wxStringWithNSString(selection);
|
return wxStringWithNSString(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxWebViewWebKit::RunScript(const wxString& javascript)
|
void wxWebViewWebKit::RunScript(const wxString& javascript)
|
||||||
{
|
{
|
||||||
if ( !m_webView )
|
if ( !m_webView )
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
|
|
||||||
id result = [[m_webView windowScriptObject] evaluateWebScript:
|
[[m_webView windowScriptObject] evaluateWebScript:
|
||||||
(NSString*)wxNSStringWithWxString( javascript )];
|
(NSString*)wxNSStringWithWxString( javascript )];
|
||||||
|
|
||||||
NSString* resultAsString;
|
|
||||||
NSString* className = NSStringFromClass([result class]);
|
|
||||||
|
|
||||||
if ([className isEqualToString:@"NSCFNumber"])
|
|
||||||
{
|
|
||||||
resultAsString = [NSString stringWithFormat:@"%@", result];
|
|
||||||
}
|
|
||||||
else if ([className isEqualToString:@"NSCFString"])
|
|
||||||
{
|
|
||||||
resultAsString = result;
|
|
||||||
}
|
|
||||||
else if ([className isEqualToString:@"NSCFBoolean"])
|
|
||||||
{
|
|
||||||
if ([result boolValue])
|
|
||||||
resultAsString = @"true";
|
|
||||||
else
|
|
||||||
resultAsString = @"false";
|
|
||||||
}
|
|
||||||
else if ([className isEqualToString:@"WebScriptObject"])
|
|
||||||
{
|
|
||||||
resultAsString = [result stringRepresentation];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return wxString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return wxStringWithNSString( resultAsString );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewWebKit::OnSize(wxSizeEvent &event)
|
void wxWebViewWebKit::OnSize(wxSizeEvent &event)
|
||||||
|
@@ -43,6 +43,7 @@ private:
|
|||||||
CPPUNIT_TEST( Editable );
|
CPPUNIT_TEST( Editable );
|
||||||
CPPUNIT_TEST( Selection );
|
CPPUNIT_TEST( Selection );
|
||||||
CPPUNIT_TEST( Zoom );
|
CPPUNIT_TEST( Zoom );
|
||||||
|
CPPUNIT_TEST( RunScript );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void Title();
|
void Title();
|
||||||
@@ -54,6 +55,7 @@ private:
|
|||||||
void Editable();
|
void Editable();
|
||||||
void Selection();
|
void Selection();
|
||||||
void Zoom();
|
void Zoom();
|
||||||
|
void RunScript();
|
||||||
void LoadUrl(int times = 1);
|
void LoadUrl(int times = 1);
|
||||||
|
|
||||||
wxWebView* m_browser;
|
wxWebView* m_browser;
|
||||||
@@ -236,4 +238,10 @@ void WebTestCase::Zoom()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebTestCase::RunScript()
|
||||||
|
{
|
||||||
|
m_browser->RunScript("document.write(\"Hello World!\");");
|
||||||
|
CPPUNIT_ASSERT_EQUAL("Hello World!", m_browser->GetPageText());
|
||||||
|
}
|
||||||
|
|
||||||
#endif //wxUSE_WEB
|
#endif //wxUSE_WEB
|
||||||
|
Reference in New Issue
Block a user