virtual wxString GetSelectedSource();
virtual void ClearSelection();
+ virtual void RunScript(const wxString& javascript);
+
/** FIXME: hack to work around signals being received too early */
bool m_ready;
virtual wxString GetSelectedSource();
virtual void ClearSelection();
+ virtual void RunScript(const wxString& javascript);
// ---- IE-specific methods
virtual wxString GetSelectedText();
virtual wxString GetSelectedSource() { return ""; }
virtual void ClearSelection() {}
+
+ void RunScript(const wxString& javascript);
// ---- methods not from the parent (common) interface
- wxString RunScript(const wxString& javascript);
-
bool CanGetPageSource();
void SetScrollPos(int pos);
virtual wxString GetSelectedSource() = 0;
virtual void ClearSelection() = 0;
+ virtual void RunScript(const wxString& javascript) = 0;
+
// TODO:
// void EnableJavascript(bool enabled); // maybe?
- // wxString RunScript(const wxString& javascript); // maybe?
+ // // maybe?
// void SetScrollPos(int pos); // maybe?
// int GetScrollPos(); // maybe?
*/
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
to edit the page even if the @c contenteditable attribute is not set.
wxConvUTF8);
}
+void wxWebViewWebKit::RunScript(const wxString& javascript)
+{
+ webkit_web_view_execute_script(WEBKIT_WEB_VIEW(web_view),
+ javascript.mb_str(wxConvUTF8));
+}
+
// static
wxVisualAttributes
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
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)
{
IHTMLDocument2* document = GetDocument();
return wxStringWithNSString(selection);
}
-wxString wxWebViewWebKit::RunScript(const wxString& javascript)
+void wxWebViewWebKit::RunScript(const wxString& javascript)
{
if ( !m_webView )
return wxEmptyString;
- id result = [[m_webView windowScriptObject] evaluateWebScript:
+ [[m_webView windowScriptObject] evaluateWebScript:
(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)
CPPUNIT_TEST( Editable );
CPPUNIT_TEST( Selection );
CPPUNIT_TEST( Zoom );
+ CPPUNIT_TEST( RunScript );
CPPUNIT_TEST_SUITE_END();
void Title();
void Editable();
void Selection();
void Zoom();
+ void RunScript();
void LoadUrl(int times = 1);
wxWebView* m_browser;
}
}
+void WebTestCase::RunScript()
+{
+ m_browser->RunScript("document.write(\"Hello World!\");");
+ CPPUNIT_ASSERT_EQUAL("Hello World!", m_browser->GetPageText());
+}
+
#endif //wxUSE_WEB