Reviewed by Kevin Ollivier.
authorkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 May 2008 05:06:50 +0000 (05:06 +0000)
committerkevino@webkit.org <kevino@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 May 2008 05:06:50 +0000 (05:06 +0000)
Fix scrolling issues by implementing transitionToCommittedNewPage() so the scroll positions are reset when a new page is loaded, and also maintained so that back and next restore the scroll positions as well. This also simplifies the logic for initializing and managing wxWebView.

https://bugs.webkit.org/show_bug.cgi?id=18992

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

WebKit/wx/ChangeLog
WebKit/wx/WebKitSupport/FrameLoaderClientWx.cpp
WebKit/wx/WebKitSupport/FrameLoaderClientWx.h
WebKit/wx/WebView.cpp
WebKit/wx/WebViewPrivate.h

index 6787990..c3fd9dc 100644 (file)
@@ -1,3 +1,42 @@
+2008-05-11  Robin Dunn  <robin@alldunn.com>
+
+        Reviewed by Kevin Ollivier.
+        
+        Fix scrolling issues by implementing transitionToCommittedNewPage() so the scroll
+        positions are reset when a new page is loaded, and also maintained so that back
+        and next restore the scroll positions as well. This also simplifies the logic
+        for initializing and managing wxWebView.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=18992
+
+        * WebKitSupport/FrameLoaderClientWx.cpp:
+        (WebCore::FrameLoaderClientWx::setWebView):
+        (WebCore::FrameLoaderClientWx::dispatchDidHandleOnloadEvents):
+        (WebCore::FrameLoaderClientWx::dispatchDidStartProvisionalLoad):
+        (WebCore::FrameLoaderClientWx::dispatchDidReceiveTitle):
+        (WebCore::FrameLoaderClientWx::dispatchDidCommitLoad):
+        (WebCore::FrameLoaderClientWx::dispatchDidFinishDocumentLoad):
+        (WebCore::FrameLoaderClientWx::postProgressFinishedNotification):
+        (WebCore::FrameLoaderClientWx::dispatchDecidePolicyForNavigationAction):
+        (WebCore::FrameLoaderClientWx::createFrame):
+        (WebCore::FrameLoaderClientWx::transitionToCommittedForNewPage):
+        * WebKitSupport/FrameLoaderClientWx.h:
+        * WebView.cpp:
+        (wxWebView::wxWebView):
+        (wxWebView::~wxWebView):
+        (wxWebView::GetPageSource):
+        (wxWebView::GetInnerText):
+        (wxWebView::GetExternalRepresentation):
+        (wxWebView::OnPaint):
+        (wxWebView::OnSize):
+        (wxWebView::OnMouseEvents):
+        (wxWebView::CanCopy):
+        (wxWebView::CanCut):
+        (wxWebView::CanPaste):
+        (wxWebView::OnKeyEvents):
+        * WebViewPrivate.h:
+        (WebViewPrivate::WebViewPrivate):
+
 2008-05-04  Robin Dunn  <robin@alldunn.com>
 
         Reviewed by Kevin Ollivier.
index dec56cc..55c878f 100644 (file)
 #include "FrameView.h"
 #include "FrameTree.h"
 #include "HTMLFormElement.h"
+#include "HTMLFrameOwnerElement.h"
 #include "NotImplemented.h"
 #include "Page.h"
 #include "PlatformString.h"
 #include "ProgressTracker.h"
+#include "RenderPart.h"
 #include "ResourceError.h"
 #include "ResourceResponse.h"
 
@@ -83,6 +85,11 @@ void FrameLoaderClientWx::setFrame(Frame *frame)
     m_frame = frame;
 }
 
+void FrameLoaderClientWx::setWebView(wxWebView *webview)
+{
+    m_webView = webview;
+}
+
 void FrameLoaderClientWx::detachFrameLoader()
 {
     m_frame = 0;
@@ -249,12 +256,11 @@ void FrameLoaderClientWx::loadedFromCachedPage()
 
 void FrameLoaderClientWx::dispatchDidHandleOnloadEvents()
 {
-    wxWindow* target = m_frame->view()->nativeWindow();
-    if (target) {
-        wxWebViewLoadEvent wkEvent(target);
+    if (m_webView) {
+        wxWebViewLoadEvent wkEvent(m_webView);
         wkEvent.SetState(wxWEBVIEW_LOAD_ONLOAD_HANDLED);
         wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
-        target->GetEventHandler()->ProcessEvent(wkEvent);
+        m_webView->GetEventHandler()->ProcessEvent(wkEvent);
     }
 }
 
@@ -293,43 +299,39 @@ void FrameLoaderClientWx::dispatchWillClose()
 
 void FrameLoaderClientWx::dispatchDidStartProvisionalLoad()
 {
-    wxWindow* target = m_frame->view()->nativeWindow();
-    if (target) {
-        wxWebViewLoadEvent wkEvent(target);
+    if (m_webView) {
+        wxWebViewLoadEvent wkEvent(m_webView);
         wkEvent.SetState(wxWEBVIEW_LOAD_NEGOTIATING);
         wkEvent.SetURL(m_frame->loader()->provisionalDocumentLoader()->request().url().string());
-        target->GetEventHandler()->ProcessEvent(wkEvent);
+        m_webView->GetEventHandler()->ProcessEvent(wkEvent);
     }
 }
 
 
 void FrameLoaderClientWx::dispatchDidReceiveTitle(const String& title)
 {
-    wxWebView* target = static_cast<wxWebView*>(m_frame->view()->nativeWindow());
-    if (target)
-        target->SetPageTitle(title);
+    if (m_webView)
+        m_webView->SetPageTitle(title);
 }
 
 
 void FrameLoaderClientWx::dispatchDidCommitLoad()
 {
-    wxWindow* target = m_frame->view()->nativeWindow();
-    if (target) {
-        wxWebViewLoadEvent wkEvent(target);
+    if (m_webView) {
+        wxWebViewLoadEvent wkEvent(m_webView);
         wkEvent.SetState(wxWEBVIEW_LOAD_TRANSFERRING);
         wkEvent.SetURL(m_frame->loader()->documentLoader()->request().url().string());
-        target->GetEventHandler()->ProcessEvent(wkEvent);
+        m_webView->GetEventHandler()->ProcessEvent(wkEvent);
     }
 }
 
 void FrameLoaderClientWx::dispatchDidFinishDocumentLoad()
 {
-    wxWindow* target = m_frame->view()->nativeWindow();
-    if (target) {
-        wxWebViewLoadEvent wkEvent(target);
+    if (m_webView) {
+        wxWebViewLoadEvent wkEvent(m_webView);
         wkEvent.SetState(wxWEBVIEW_LOAD_DOC_COMPLETED);
         wkEvent.SetURL(m_frame->loader()->url().string());
-        target->GetEventHandler()->ProcessEvent(wkEvent);
+        m_webView->GetEventHandler()->ProcessEvent(wkEvent);
     }
 }
 
@@ -390,12 +392,11 @@ void FrameLoaderClientWx::postProgressEstimateChangedNotification()
 
 void FrameLoaderClientWx::postProgressFinishedNotification()
 {
-    wxWindow* target = m_frame->view()->nativeWindow();
-    if (target) {
-        wxWebViewLoadEvent wkEvent(target);
+    if (m_webView) {
+        wxWebViewLoadEvent wkEvent(m_webView);
         wkEvent.SetState(wxWEBVIEW_LOAD_DL_COMPLETED);
         wkEvent.SetURL(m_frame->loader()->url().string());
-        target->GetEventHandler()->ProcessEvent(wkEvent);
+        m_webView->GetEventHandler()->ProcessEvent(wkEvent);
     }
 }
 
@@ -719,13 +720,12 @@ void FrameLoaderClientWx::dispatchDecidePolicyForNavigationAction(FramePolicyFun
     if (!m_frame)
         return;
         
-    wxWindow* target = m_frame->view()->nativeWindow();
-    if (target) {
-        wxWebViewBeforeLoadEvent wkEvent(target);
+    if (m_webView) {
+        wxWebViewBeforeLoadEvent wkEvent(m_webView);
         wkEvent.SetNavigationType(wxNavTypeFromWebNavType(action.type()));
         wkEvent.SetURL(request.url().string());
         
-        target->GetEventHandler()->ProcessEvent(wkEvent);
+        m_webView->GetEventHandler()->ProcessEvent(wkEvent);
         if (wkEvent.IsCancelled())
             (m_frame->loader()->*function)(PolicyIgnore);
         else
@@ -762,7 +762,7 @@ PassRefPtr<Frame> FrameLoaderClientWx::createFrame(const KURL& url, const String
 */
 
 /*
-    wxWindow* parent = m_frame->view()->nativeWindow();
+    wxWindow* parent = m_webView;
 
     WebViewFrameData* data = new WebViewFrameData();
     data->name = name;
@@ -857,7 +857,33 @@ void FrameLoaderClientWx::transitionToCommittedFromCachedPage(CachedPage*)
 
 void FrameLoaderClientWx::transitionToCommittedForNewPage()
 { 
-    notImplemented();
+    ASSERT(m_frame);
+    ASSERT(m_webView);
+    
+    Page* page = m_frame->page();
+    ASSERT(page);
+
+    bool isMainFrame = m_frame == page->mainFrame();
+
+    m_frame->setView(0);
+
+    FrameView* frameView;
+    if (isMainFrame) {
+        frameView = new FrameView(m_frame, IntRect(m_webView->GetRect()).size());
+    } else
+        frameView = new FrameView(m_frame);
+
+    ASSERT(frameView);
+    m_frame->setView(frameView);
+    frameView->deref(); // FrameViews are created with a ref count of 1. Release this ref since we've assigned it to frame.
+
+    frameView->setNativeWindow(m_webView);
+
+    if (m_frame->ownerRenderer())
+        m_frame->ownerRenderer()->setWidget(frameView);
+
+    if (HTMLFrameOwnerElement* owner = m_frame->ownerElement())
+        m_frame->view()->setScrollbarsMode(owner->scrollingMode());
 }
 
 }
index 341115c..4609323 100644 (file)
@@ -34,6 +34,7 @@
 #include "RefCounted.h"
 #include "ResourceResponse.h"
 
+class wxWebView;
 
 namespace WebCore {
 
@@ -52,6 +53,7 @@ namespace WebCore {
         FrameLoaderClientWx();
         ~FrameLoaderClientWx();
         void setFrame(Frame *frame);
+        void setWebView(wxWebView *webview);
         virtual void detachFrameLoader();
 
         virtual void ref();
@@ -209,6 +211,7 @@ namespace WebCore {
 
     private:
         Frame *m_frame;
+        wxWebView *m_webView;
         ResourceResponse m_response;
         bool m_firstData;
     };
index e7a11cd..5dccbfb 100644 (file)
@@ -221,14 +221,11 @@ wxWebView::wxWebView(wxWindow* parent, int id, const wxPoint& position,
     
     m_impl->frame = new WebCore::Frame(m_impl->page, parentFrame, loaderClient);
     m_impl->frame->deref();
-    m_impl->frameView = new WebCore::FrameView(m_impl->frame.get());
-    m_impl->frameView->deref();
+
+    loaderClient->setFrame(m_impl->frame.get());
+    loaderClient->setWebView(this);
     
-    m_impl->frame->setView(m_impl->frameView.get());
     m_impl->frame->init();
-    
-    m_impl->frameView->setNativeWindow(this);
-    loaderClient->setFrame(m_impl->frame.get());
         
     // Default settings - we should have wxWebViewSettings class for this
     // eventually
@@ -252,10 +249,7 @@ wxWebView::~wxWebView()
     m_impl->frame->loader()->detachFromParent();
     
     delete m_impl->page;
-    m_impl->page = 0;
-    // Since frameView has the last reference to Frame, once it is
-    // destroyed the destructor for Frame will happen as well.
-    m_impl->frameView = 0;    
+    m_impl->page = 0;   
 }
 
 void wxWebView::Stop()
@@ -273,8 +267,8 @@ void wxWebView::Reload()
 wxString wxWebView::GetPageSource()
 {
     if (m_impl->frame) {
-        if (m_impl->frameView && m_impl->frameView->layoutPending())
-            m_impl->frameView->layout();
+        if (m_impl->frame->view() && m_impl->frame->view()->layoutPending())
+            m_impl->frame->view()->layout();
     
         WebCore::Document* doc = m_impl->frame->document();
         
@@ -298,8 +292,8 @@ void wxWebView::SetPageSource(const wxString& source, const wxString& baseUrl)
 
 wxString wxWebView::GetInnerText()
 {
-    if (m_impl->frameView && m_impl->frameView->layoutPending())
-        m_impl->frameView->layout();
+    if (m_impl->frame->view() && m_impl->frame->view()->layoutPending())
+        m_impl->frame->view()->layout();
         
     WebCore::Element *documentElement = m_impl->frame->document()->documentElement();
     return documentElement->innerText();
@@ -315,8 +309,8 @@ wxString wxWebView::GetAsMarkup()
 
 wxString wxWebView::GetExternalRepresentation()
 {
-    if (m_impl->frameView && m_impl->frameView->layoutPending())
-        m_impl->frameView->layout();
+    if (m_impl->frame->view() && m_impl->frame->view()->layoutPending())
+        m_impl->frame->view()->layout();
 
     return externalRepresentation(m_impl->frame->contentRenderer());
 }
@@ -432,7 +426,7 @@ void wxWebView::MakeEditable(bool enable)
 
 void wxWebView::OnPaint(wxPaintEvent& event)
 {
-    if (m_beingDestroyed || !m_impl->frameView || !m_impl->frame)
+    if (m_beingDestroyed || !m_impl->frame->view() || !m_impl->frame)
         return;
     
     wxAutoBufferedPaintDC dc(this);
@@ -445,7 +439,7 @@ void wxWebView::OnPaint(wxPaintEvent& event)
         if (dc.IsOk()) {
             wxRect paintRect = GetUpdateRegion().GetBox();
 
-            WebCore::IntSize offset = m_impl->frameView->scrollOffset();
+            WebCore::IntSize offset = m_impl->frame->view()->scrollOffset();
 #if USE(WXGC)
             gcdc.SetDeviceOrigin(-offset.width(), -offset.height());
 #endif
@@ -458,8 +452,8 @@ void wxWebView::OnPaint(wxPaintEvent& event)
             WebCore::GraphicsContext* gc = new WebCore::GraphicsContext((wxWindowDC*)&dc);
 #endif
             if (gc && m_impl->frame->contentRenderer()) {
-                if (m_impl->frameView->needsLayout())
-                    m_impl->frameView->layout();
+                if (m_impl->frame->view()->needsLayout())
+                    m_impl->frame->view()->layout();
 
                 m_impl->frame->paint(gc, paintRect);
             }
@@ -469,9 +463,9 @@ void wxWebView::OnPaint(wxPaintEvent& event)
 
 void wxWebView::OnSize(wxSizeEvent& event)
 { 
-    if (m_isInitialized && m_impl->frame && m_impl->frameView) {
+    if (m_isInitialized && m_impl->frame && m_impl->frame->view()) {
         m_impl->frame->sendResizeEvent();
-        m_impl->frameView->layout();
+        m_impl->frame->view()->layout();
     }
     
     event.Skip();
@@ -482,7 +476,7 @@ void wxWebView::OnMouseEvents(wxMouseEvent& event)
 {
     event.Skip();
     
-    if (!m_impl->frame  && m_impl->frameView)
+    if (!m_impl->frame  && m_impl->frame->view())
         return; 
         
     wxPoint globalPoint = ClientToScreen(event.GetPosition());
@@ -510,7 +504,7 @@ void wxWebView::OnMouseEvents(wxMouseEvent& event)
 
 bool wxWebView::CanCopy()
 {
-    if (m_impl->frame && m_impl->frameView)
+    if (m_impl->frame && m_impl->frame->view())
         return (m_impl->frame->editor()->canCopy() || m_impl->frame->editor()->canDHTMLCopy());
 
     return false;
@@ -524,7 +518,7 @@ void wxWebView::Copy()
 
 bool wxWebView::CanCut()
 {
-    if (m_impl->frame && m_impl->frameView)
+    if (m_impl->frame && m_impl->frame->view())
         return (m_impl->frame->editor()->canCut() || m_impl->frame->editor()->canDHTMLCut());
 
     return false;
@@ -538,7 +532,7 @@ void wxWebView::Cut()
 
 bool wxWebView::CanPaste()
 {
-    if (m_impl->frame && m_impl->frameView)
+    if (m_impl->frame && m_impl->frame->view())
         return (m_impl->frame->editor()->canPaste() || m_impl->frame->editor()->canDHTMLPaste());
 
     return false;
@@ -553,7 +547,7 @@ void wxWebView::Paste()
 
 void wxWebView::OnKeyEvents(wxKeyEvent& event)
 {
-    if (m_impl->frame && m_impl->frameView) {
+    if (m_impl->frame && m_impl->frame->view()) {
         // WebCore doesn't handle these events itself, so we need to do
         // it and not send the event down or else CTRL+C will erase the text
         // and replace it with c.
index 1e8ffcf..2eef499 100644 (file)
@@ -41,12 +41,10 @@ class WebViewPrivate
 public:
     WebViewPrivate() :
         frame(0),
-        frameView(0),
         page(0)
     {}
     
     WTF::RefPtr<WebCore::Frame> frame;
-    WTF::RefPtr<WebCore::FrameView> frameView;
     WebCore::Page* page;
 };