wxWebKit API changes in preparation for DRT implementation.
authorkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Jan 2008 19:34:48 +0000 (19:34 +0000)
committerkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Jan 2008 19:34:48 +0000 (19:34 +0000)
Reviewed by Darin Adler.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@29453 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/wx/ChangeLog
WebKit/wx/WebFrame.cpp
WebKit/wx/WebFrame.h
WebKit/wx/WebKitSupport/ChromeClientWx.cpp
WebKit/wx/WebKitSupport/ChromeClientWx.h
WebKit/wx/WebKitSupport/FrameLoaderClientWx.cpp
WebKit/wx/WebView.cpp
WebKit/wx/WebView.h

index 66a15050d1c949564cd4e6093bc2cfe7fd63d76b..fa8468c20ffcfd5a6fd296e5d6ce439ba215a64c 100644 (file)
@@ -1,3 +1,40 @@
+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
index 83af1ac70791791873c62cb595cb21388184aeb5..cd46af684a50943c2c5eb794c89b3efd18e5cba3 100644 (file)
@@ -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());
         }
     }
index 6077a7fa76b78712b59f7cac815465b016645b99..046a650cea88ae17c00987a66d6510cfcd731ac4 100644 (file)
@@ -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);
index e858a1ec48afd7621026e198eb5e350f88d0483b..cf036dea47f184c3caddff88f53df8b7f5236e6d 100644 (file)
 
 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()
index 6447d070d25dfed17cfdb56f40d844570a496bdd..183cc5da6108979eb9639598b00e567f5368c227 100644 (file)
@@ -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;
 };
 
 }
index 1ab80fd4906ff8f9a201a63433bbfc829efb3c11..60881975dd6ed168ac3ec7b68449141023b4931d 100644 (file)
@@ -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);
     }
index 8c3174fe577233135bc413d120c43db039715c72..1d143f61eb7b43a3f19a7dbbedef95d9e9edefb3 100644 (file)
@@ -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"
 #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;
index ab4346ce79d7f46f9de549e3a3964dc515da8b3c..e04fea16e6fe1e4b2148acbc00550809a109f5e8 100644 (file)
@@ -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<wxObject*>(NULL)),
                             
 #define EVT_WEBVIEW_BEFORE_LOAD(func) \
@@ -294,11 +329,11 @@ END_DECLARE_EVENT_TYPES()
                             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) \
@@ -308,5 +343,13 @@ END_DECLARE_EVENT_TYPES()
                             (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