From 83014c1c00c00bf072693bb7cbeac407c69316f2 Mon Sep 17 00:00:00 2001 From: "kevino@webkit.org" Date: Sun, 13 Jan 2008 19:34:48 +0000 Subject: [PATCH] wxWebKit API changes in preparation for DRT implementation. Reviewed by Darin Adler. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@29453 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebKit/wx/ChangeLog | 37 +++++++++ WebKit/wx/WebFrame.cpp | 12 +-- WebKit/wx/WebFrame.h | 2 +- WebKit/wx/WebKitSupport/ChromeClientWx.cpp | 19 ++++- WebKit/wx/WebKitSupport/ChromeClientWx.h | 4 + .../wx/WebKitSupport/FrameLoaderClientWx.cpp | 24 +++--- WebKit/wx/WebView.cpp | 52 +++++++++++-- WebKit/wx/WebView.h | 77 +++++++++++++++---- 8 files changed, 185 insertions(+), 42 deletions(-) diff --git a/WebKit/wx/ChangeLog b/WebKit/wx/ChangeLog index 66a15050d1c9..fa8468c20ffc 100644 --- a/WebKit/wx/ChangeLog +++ b/WebKit/wx/ChangeLog @@ -1,3 +1,40 @@ +2008-01-12 Kevin Ollivier + + 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 wx build fix. Add WebCore/icu/include dir for OS X boxes with diff --git a/WebKit/wx/WebFrame.cpp b/WebKit/wx/WebFrame.cpp index 83af1ac70791..cd46af684a50 100644 --- a/WebKit/wx/WebFrame.cpp +++ b/WebKit/wx/WebFrame.cpp @@ -71,7 +71,7 @@ BEGIN_EVENT_TABLE(wxWebFrame, wxFrame) 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) @@ -208,21 +208,21 @@ void wxWebFrame::OnLoadFile(wxCommandEvent& WXUNUSED(event)) } } -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()); } } diff --git a/WebKit/wx/WebFrame.h b/WebKit/wx/WebFrame.h index 6077a7fa76b7..046a650cea88 100644 --- a/WebKit/wx/WebFrame.h +++ b/WebKit/wx/WebFrame.h @@ -60,7 +60,7 @@ protected: 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); diff --git a/WebKit/wx/WebKitSupport/ChromeClientWx.cpp b/WebKit/wx/WebKitSupport/ChromeClientWx.cpp index e858a1ec48af..cf036dea47f1 100644 --- a/WebKit/wx/WebKitSupport/ChromeClientWx.cpp +++ b/WebKit/wx/WebKitSupport/ChromeClientWx.cpp @@ -46,6 +46,11 @@ namespace WebCore { +ChromeClientWx::ChromeClientWx(wxWebView* webView) +{ + m_webView = webView; +} + ChromeClientWx::~ChromeClientWx() { } @@ -192,11 +197,17 @@ void ChromeClientWx::setResizable(bool) 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() diff --git a/WebKit/wx/WebKitSupport/ChromeClientWx.h b/WebKit/wx/WebKitSupport/ChromeClientWx.h index 6447d070d25d..183cc5da6108 100644 --- a/WebKit/wx/WebKitSupport/ChromeClientWx.h +++ b/WebKit/wx/WebKitSupport/ChromeClientWx.h @@ -37,6 +37,7 @@ namespace WebCore { class ChromeClientWx : public ChromeClient { public: + ChromeClientWx(wxWebView*); virtual ~ChromeClientWx(); virtual void chromeDestroyed(); @@ -105,6 +106,9 @@ public: 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; }; } diff --git a/WebKit/wx/WebKitSupport/FrameLoaderClientWx.cpp b/WebKit/wx/WebKitSupport/FrameLoaderClientWx.cpp index 1ab80fd4906f..60881975dd6e 100644 --- a/WebKit/wx/WebKitSupport/FrameLoaderClientWx.cpp +++ b/WebKit/wx/WebKitSupport/FrameLoaderClientWx.cpp @@ -248,7 +248,13 @@ void FrameLoaderClientWx::loadedFromCachedPage() 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); + } } @@ -288,8 +294,8 @@ void FrameLoaderClientWx::dispatchDidStartProvisionalLoad() { 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); } @@ -308,8 +314,8 @@ void FrameLoaderClientWx::dispatchDidCommitLoad() { 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); } @@ -319,8 +325,8 @@ void FrameLoaderClientWx::dispatchDidFinishDocumentLoad() { 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); } @@ -391,8 +397,8 @@ void FrameLoaderClientWx::postProgressFinishedNotification() { 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); } diff --git a/WebKit/wx/WebView.cpp b/WebKit/wx/WebView.cpp index 8c3174fe5772..1d143f61eb7b 100644 --- a/WebKit/wx/WebView.cpp +++ b/WebKit/wx/WebView.cpp @@ -26,6 +26,7 @@ #include "config.h" #include "DeprecatedString.h" #include "Document.h" +#include "Element.h" #include "Editor.h" #include "EventHandler.h" #include "Frame.h" @@ -34,12 +35,14 @@ #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" @@ -82,13 +85,13 @@ int rint(double val) // 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()); } @@ -127,6 +130,17 @@ wxWebViewRightClickEvent::wxWebViewRightClickEvent(wxWindow* win) 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 //--------------------------------------------------------- @@ -183,7 +197,7 @@ wxWebView::wxWebView(wxWindow* parent, int id, const wxPoint& position, } 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); } @@ -243,6 +257,9 @@ void wxWebView::Reload() 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) { @@ -263,6 +280,31 @@ void wxWebView::SetPageSource(const wxString& source, const wxString& baseUrl) } } +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; diff --git a/WebKit/wx/WebView.h b/WebKit/wx/WebView.h index ab4346ce79d7..e04fea16e6fe 100644 --- a/WebKit/wx/WebView.h +++ b/WebKit/wx/WebView.h @@ -92,6 +92,10 @@ public: 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; @@ -134,12 +138,16 @@ private: // ---------------------------------------------------------------------------- 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 { @@ -205,10 +213,10 @@ private: 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: @@ -217,8 +225,8 @@ 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; @@ -263,26 +271,53 @@ private: 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(NULL)), #define EVT_WEBVIEW_BEFORE_LOAD(func) \ @@ -294,11 +329,11 @@ END_DECLARE_EVENT_TYPES() static_cast(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(NULL)), #define EVT_WEBVIEW_RIGHT_CLICK(func) \ @@ -308,5 +343,13 @@ END_DECLARE_EVENT_TYPES() (wxObjectEventFunction) \ (wxWebViewRightClickEventFunction) & func, \ static_cast(NULL)), + +#define EVT_WEBVIEW_CONSOLE_MESSAGE(func) \ + DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_CONSOLE_MESSAGE, \ + wxID_ANY, \ + wxID_ANY, \ + (wxObjectEventFunction) \ + (wxWebViewConsoleMessageEventFunction) & func, \ + static_cast(NULL)), #endif // ifndef WXWEBVIEW_H -- 2.36.0