+2008-01-12 Kevin Ollivier <kevino@theolliviers.com>
+
+ Reviewed by Darin Adler.
+
+ wxWebKit API changes in preparation for DRT implementation.
+ Specifically:
+
+ - Add CONSOLE_MESSAGE callback so clients can choose how to handle
+ console messages.
+ - Add more load events, and rename wxWebViewStateChangedEvent to
+ wxWebViewLoadEvent to reflect that all 'states' are load states.
+ - Add wxWebView impls. for GetInnerText(), GetAsMarkup() and
+ GetExternalRepresentation()
+
+ * WebFrame.cpp:
+ (wxWebFrame::OnLoadEvent):
+ * WebFrame.h:
+ * WebKitSupport/ChromeClientWx.cpp:
+ (WebCore::ChromeClientWx::ChromeClientWx):
+ (WebCore::ChromeClientWx::addMessageToConsole):
+ * WebKitSupport/ChromeClientWx.h:
+ * WebKitSupport/FrameLoaderClientWx.cpp:
+ (WebCore::FrameLoaderClientWx::dispatchDidHandleOnloadEvents):
+ (WebCore::FrameLoaderClientWx::dispatchDidStartProvisionalLoad):
+ (WebCore::FrameLoaderClientWx::dispatchDidCommitLoad):
+ (WebCore::FrameLoaderClientWx::dispatchDidFinishDocumentLoad):
+ (WebCore::FrameLoaderClientWx::postProgressFinishedNotification):
+ * WebView.cpp:
+ (wxWebViewLoadEvent::wxWebViewLoadEvent):
+ (wxWebViewConsoleMessageEvent::wxWebViewConsoleMessageEvent):
+ (wxWebView::wxWebView):
+ (wxWebView::GetPageSource):
+ (wxWebView::GetInnerText):
+ (wxWebView::GetAsMarkup):
+ (wxWebView::GetExternalRepresentation):
+ * WebView.h:
+
2008-01-12 Kevin Ollivier <kevino@theolliviers.com>
wx build fix. Add WebCore/icu/include dir for OS X boxes with
EVT_MENU(ID_LOADFILE, wxWebFrame::OnLoadFile)
EVT_TEXT_ENTER(ID_TEXTCTRL, wxWebFrame::OnAddressBarEnter)
EVT_TEXT_ENTER(ID_SEARCHCTRL, wxWebFrame::OnSearchCtrlEnter)
- EVT_WEBVIEW_STATE_CHANGED(wxWebFrame::OnStateChangedEvent)
+ EVT_WEBVIEW_LOAD(wxWebFrame::OnLoadEvent)
EVT_WEBVIEW_BEFORE_LOAD(wxWebFrame::OnBeforeLoad)
EVT_MENU(ID_BACK, wxWebFrame::OnBack)
EVT_MENU(ID_FORWARD, wxWebFrame::OnForward)
}
}
-void wxWebFrame::OnStateChangedEvent(wxWebViewStateChangedEvent& event)
+void wxWebFrame::OnLoadEvent(wxWebViewLoadEvent& event)
{
if (GetStatusBar() != NULL){
- if (event.GetState() == wxWEBVIEW_STATE_NEGOTIATING) {
+ if (event.GetState() == wxWEBVIEW_LOAD_NEGOTIATING) {
GetStatusBar()->SetStatusText(_("Contacting ") + event.GetURL());
}
- else if (event.GetState() == wxWEBVIEW_STATE_TRANSFERRING) {
+ else if (event.GetState() == wxWEBVIEW_LOAD_TRANSFERRING) {
GetStatusBar()->SetStatusText(_("Loading ") + event.GetURL());
}
- else if (event.GetState() == wxWEBVIEW_STATE_STOP) {
+ else if (event.GetState() == wxWEBVIEW_LOAD_ONLOAD_HANDLED) {
GetStatusBar()->SetStatusText(_("Load complete."));
addressBar->SetValue(event.GetURL());
SetTitle(webview->GetPageTitle());
}
- else if (event.GetState() == wxWEBVIEW_STATE_FAILED) {
+ else if (event.GetState() == wxWEBVIEW_LOAD_FAILED) {
GetStatusBar()->SetStatusText(_("Failed to load ") + event.GetURL());
}
}
void OnLoadFile(wxCommandEvent& event);
void OnAddressBarEnter(wxCommandEvent& event);
void OnSearchCtrlEnter(wxCommandEvent& event);
- void OnStateChangedEvent(wxWebViewStateChangedEvent& event);
+ void OnLoadEvent(wxWebViewLoadEvent& event);
void OnBeforeLoad(wxWebViewBeforeLoadEvent& event);
void OnBack(wxCommandEvent& event);
void OnForward(wxCommandEvent& event);
namespace WebCore {
+ChromeClientWx::ChromeClientWx(wxWebView* webView)
+{
+ m_webView = webView;
+}
+
ChromeClientWx::~ChromeClientWx()
{
}
notImplemented();
}
-void ChromeClientWx::addMessageToConsole(const String&,
- unsigned int,
- const String&)
+void ChromeClientWx::addMessageToConsole(const String& message,
+ unsigned int lineNumber,
+ const String& sourceID)
{
- notImplemented();
+ if (m_webView) {
+ wxWebViewConsoleMessageEvent wkEvent(m_webView);
+ wkEvent.SetMessage(message);
+ wkEvent.SetLineNumber(lineNumber);
+ wkEvent.SetSourceID(sourceID);
+ m_webView->GetEventHandler()->ProcessEvent(wkEvent);
+ }
}
bool ChromeClientWx::canRunBeforeUnloadConfirmPanel()
class ChromeClientWx : public ChromeClient {
public:
+ ChromeClientWx(wxWebView*);
virtual ~ChromeClientWx();
virtual void chromeDestroyed();
virtual unsigned long long requestQuotaIncreaseForNewDatabase(Frame*, SecurityOrigin*, const String&, unsigned long long);
virtual unsigned long long requestQuotaIncreaseForDatabaseOperation(Frame*, SecurityOrigin*, const String&, unsigned long long);
+
+private:
+ wxWebView* m_webView;
};
}
void FrameLoaderClientWx::dispatchDidHandleOnloadEvents()
{
- notImplemented();
+ wxWindow* target = m_frame->view()->nativeWindow();
+ if (target) {
+ wxWebViewLoadEvent wkEvent(target);
+ wkEvent.SetState(wxWEBVIEW_LOAD_ONLOAD_HANDLED);
+ wkEvent.SetURL(m_frame->loader()->provisionalDocumentLoader()->request().url().string());
+ target->GetEventHandler()->ProcessEvent(wkEvent);
+ }
}
{
wxWindow* target = m_frame->view()->nativeWindow();
if (target) {
- wxWebViewStateChangedEvent wkEvent(target);
- wkEvent.SetState(wxWEBVIEW_STATE_NEGOTIATING);
+ wxWebViewLoadEvent wkEvent(target);
+ wkEvent.SetState(wxWEBVIEW_LOAD_NEGOTIATING);
wkEvent.SetURL(m_frame->loader()->provisionalDocumentLoader()->request().url().string());
target->GetEventHandler()->ProcessEvent(wkEvent);
}
{
wxWindow* target = m_frame->view()->nativeWindow();
if (target) {
- wxWebViewStateChangedEvent wkEvent(target);
- wkEvent.SetState(wxWEBVIEW_STATE_TRANSFERRING);
+ wxWebViewLoadEvent wkEvent(target);
+ wkEvent.SetState(wxWEBVIEW_LOAD_TRANSFERRING);
wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
target->GetEventHandler()->ProcessEvent(wkEvent);
}
{
wxWindow* target = m_frame->view()->nativeWindow();
if (target) {
- wxWebViewStateChangedEvent wkEvent(target);
- wkEvent.SetState(wxWEBVIEW_STATE_STOP);
+ wxWebViewLoadEvent wkEvent(target);
+ wkEvent.SetState(wxWEBVIEW_LOAD_DOC_COMPLETED);
wkEvent.SetURL(m_frame->loader()->url().string());
target->GetEventHandler()->ProcessEvent(wkEvent);
}
{
wxWindow* target = m_frame->view()->nativeWindow();
if (target) {
- wxWebViewStateChangedEvent wkEvent(target);
- wkEvent.SetState(wxWEBVIEW_STATE_STOP);
+ wxWebViewLoadEvent wkEvent(target);
+ wkEvent.SetState(wxWEBVIEW_LOAD_DL_COMPLETED);
wkEvent.SetURL(m_frame->loader()->url().string());
target->GetEventHandler()->ProcessEvent(wkEvent);
}
#include "config.h"
#include "DeprecatedString.h"
#include "Document.h"
+#include "Element.h"
#include "Editor.h"
#include "EventHandler.h"
#include "Frame.h"
#include "GraphicsContext.h"
#include "HTMLFrameOwnerElement.h"
#include "Logging.h"
+#include "markup.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformMouseEvent.h"
#include "PlatformString.h"
#include "PlatformWheelEvent.h"
#include "RenderObject.h"
+#include "RenderTreeAsText.h"
#include "Settings.h"
#include "ChromeClientWx.h"
// wxWebView Events
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxWebViewStateChangedEvent, wxCommandEvent)
+IMPLEMENT_DYNAMIC_CLASS(wxWebViewLoadEvent, wxCommandEvent)
-DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_STATE_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_LOAD)
-wxWebViewStateChangedEvent::wxWebViewStateChangedEvent(wxWindow* win)
+wxWebViewLoadEvent::wxWebViewLoadEvent(wxWindow* win)
{
- SetEventType( wxEVT_WEBVIEW_STATE_CHANGED);
+ SetEventType( wxEVT_WEBVIEW_LOAD);
SetEventObject( win );
SetId(win->GetId());
}
SetId(win->GetId());
}
+IMPLEMENT_DYNAMIC_CLASS(wxWebViewConsoleMessageEvent, wxCommandEvent)
+
+DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_CONSOLE_MESSAGE)
+
+wxWebViewConsoleMessageEvent::wxWebViewConsoleMessageEvent(wxWindow* win)
+{
+ SetEventType(wxEVT_WEBVIEW_CONSOLE_MESSAGE);
+ SetEventObject(win);
+ SetId(win->GetId());
+}
+
//---------------------------------------------------------
// DOM Element info data type
//---------------------------------------------------------
}
else {
WebCore::EditorClientWx* editorClient = new WebCore::EditorClientWx();
- m_impl->page = new WebCore::Page(new WebCore::ChromeClientWx(), new WebCore::ContextMenuClientWx(), editorClient, new WebCore::DragClientWx(), new WebCore::InspectorClientWx());
+ m_impl->page = new WebCore::Page(new WebCore::ChromeClientWx(this), new WebCore::ContextMenuClientWx(), editorClient, new WebCore::DragClientWx(), new WebCore::InspectorClientWx());
editorClient->setPage(m_impl->page);
}
wxString wxWebView::GetPageSource()
{
if (m_impl->frame) {
+ if (m_impl->frameView && m_impl->frameView->layoutPending())
+ m_impl->frameView->layout();
+
WebCore::Document* doc = m_impl->frame->document();
if (doc) {
}
}
+wxString wxWebView::GetInnerText()
+{
+ if (m_impl->frameView && m_impl->frameView->layoutPending())
+ m_impl->frameView->layout();
+
+ WebCore::Element *documentElement = m_impl->frame->document()->documentElement();
+ return documentElement->innerText();
+}
+
+wxString wxWebView::GetAsMarkup()
+{
+ if (!m_impl->frame || !m_impl->frame->document())
+ return wxEmptyString;
+
+ return createMarkup(m_impl->frame->document());
+}
+
+wxString wxWebView::GetExternalRepresentation()
+{
+ if (m_impl->frameView && m_impl->frameView->layoutPending())
+ m_impl->frameView->layout();
+
+ return externalRepresentation(m_impl->frame->renderer());
+}
+
wxString wxWebView::RunScript(const wxString& javascript)
{
wxString returnValue = wxEmptyString;
wxString GetPageSource();
void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString);
+ wxString GetInnerText();
+ wxString GetAsMarkup();
+ wxString GetExternalRepresentation();
+
wxString RunScript(const wxString& javascript);
bool CanIncreaseTextSize() const;
// ----------------------------------------------------------------------------
enum {
- wxWEBVIEW_STATE_START = 1,
- wxWEBVIEW_STATE_NEGOTIATING = 2,
- wxWEBVIEW_STATE_REDIRECTING = 4,
- wxWEBVIEW_STATE_TRANSFERRING = 8,
- wxWEBVIEW_STATE_STOP = 16,
- wxWEBVIEW_STATE_FAILED = 32
+ wxWEBVIEW_LOAD_STARTED = 1,
+ wxWEBVIEW_LOAD_NEGOTIATING = 2,
+ wxWEBVIEW_LOAD_REDIRECTING = 4,
+ wxWEBVIEW_LOAD_TRANSFERRING = 8,
+ wxWEBVIEW_LOAD_STOPPED = 16,
+ wxWEBVIEW_LOAD_FAILED = 32,
+ wxWEBVIEW_LOAD_DL_COMPLETED = 64,
+ wxWEBVIEW_LOAD_DOC_COMPLETED = 128,
+ wxWEBVIEW_LOAD_ONLOAD_HANDLED = 256,
+ wxWEBVIEW_LOAD_WINDOW_OBJECT_CLEARED = 512
};
enum {
int m_navType;
};
-class WXDLLIMPEXP_WEBKIT wxWebViewStateChangedEvent : public wxCommandEvent
+class WXDLLIMPEXP_WEBKIT wxWebViewLoadEvent : public wxCommandEvent
{
#ifndef SWIG
- DECLARE_DYNAMIC_CLASS( wxWebViewStateChangedEvent )
+ DECLARE_DYNAMIC_CLASS( wxWebViewLoadEvent )
#endif
public:
wxString GetURL() const { return m_url; }
void SetURL(const wxString& url) { m_url = url; }
- wxWebViewStateChangedEvent( wxWindow* win = (wxWindow*) NULL );
- wxEvent *Clone(void) const { return new wxWebViewStateChangedEvent(*this); }
+ wxWebViewLoadEvent( wxWindow* win = (wxWindow*) NULL );
+ wxEvent *Clone(void) const { return new wxWebViewLoadEvent(*this); }
private:
int m_state;
wxPoint m_position;
};
-typedef void (wxEvtHandler::*wxWebViewStateChangedEventFunction)(wxWebViewStateChangedEvent&);
+class WXDLLIMPEXP_WEBKIT wxWebViewConsoleMessageEvent : public wxCommandEvent
+{
+#ifndef SWIG
+ DECLARE_DYNAMIC_CLASS( wxWebViewConsoleMessageEvent )
+#endif
+
+public:
+ wxString GetMessage() const { return m_message; }
+ void SetMessage(const wxString& message) { m_message = message; }
+
+ unsigned int GetLineNumber() const { return m_lineNumber; }
+ void SetLineNumber(unsigned int lineNumber) { m_lineNumber = lineNumber; }
+
+ wxString GetSourceID() const { return m_sourceID; }
+ void SetSourceID(const wxString& sourceID) { m_sourceID = sourceID; }
+
+ wxWebViewConsoleMessageEvent( wxWindow* win = (wxWindow*) NULL );
+ wxEvent *Clone(void) const { return new wxWebViewConsoleMessageEvent(*this); }
+
+private:
+ unsigned int m_lineNumber;
+ wxString m_message;
+ wxString m_sourceID;
+};
+
+typedef void (wxEvtHandler::*wxWebViewLoadEventFunction)(wxWebViewLoadEvent&);
typedef void (wxEvtHandler::*wxWebViewBeforeLoadEventFunction)(wxWebViewBeforeLoadEvent&);
typedef void (wxEvtHandler::*wxWebViewNewWindowEventFunction)(wxWebViewNewWindowEvent&);
typedef void (wxEvtHandler::*wxWebViewRightClickEventFunction)(wxWebViewRightClickEvent&);
+typedef void (wxEvtHandler::*wxWebViewConsoleMessageEventFunction)(wxWebViewConsoleMessageEvent&);
#ifndef SWIG
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_BEFORE_LOAD, wxID_ANY)
- DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_STATE_CHANGED, wxID_ANY)
+ DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_LOAD, wxID_ANY)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_NEW_WINDOW, wxID_ANY)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_RIGHT_CLICK, wxID_ANY)
+ DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_CONSOLE_MESSAGE, wxID_ANY)
END_DECLARE_EVENT_TYPES()
#endif
-#define EVT_WEBVIEW_STATE_CHANGED(func) \
- DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_STATE_CHANGED, \
+#define EVT_WEBVIEW_LOAD(func) \
+ DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_LOAD, \
wxID_ANY, \
wxID_ANY, \
(wxObjectEventFunction) \
- (wxWebViewStateChangedEventFunction) & func, \
+ (wxWebViewLoadEventFunction) & func, \
static_cast<wxObject*>(NULL)),
#define EVT_WEBVIEW_BEFORE_LOAD(func) \
static_cast<wxObject*>(NULL)),
#define EVT_WEBVIEW_NEW_WINDOW(func) \
- DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_BEFORE_LOAD, \
+ DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_NEW_WINDOW, \
wxID_ANY, \
wxID_ANY, \
(wxObjectEventFunction) \
- (wxWebViewBeforeLoadEventFunction) & func, \
+ (wxWebViewNewWindowEventFunction) & func, \
static_cast<wxObject*>(NULL)),
#define EVT_WEBVIEW_RIGHT_CLICK(func) \
(wxObjectEventFunction) \
(wxWebViewRightClickEventFunction) & func, \
static_cast<wxObject*>(NULL)),
+
+#define EVT_WEBVIEW_CONSOLE_MESSAGE(func) \
+ DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_CONSOLE_MESSAGE, \
+ wxID_ANY, \
+ wxID_ANY, \
+ (wxObjectEventFunction) \
+ (wxWebViewConsoleMessageEventFunction) & func, \
+ static_cast<wxObject*>(NULL)),
#endif // ifndef WXWEBVIEW_H