From a4c1f6783dbe0ebd25a5699c648a26794574c9e0 Mon Sep 17 00:00:00 2001 From: stippi Date: Fri, 30 Apr 2010 15:40:36 +0000 Subject: [PATCH] * After a recent commit, _TabChanged() was accessing "webView" when it really meant CurrentWebView(). This also fixed the focus restoration, since it remembered the current focus for the wrong web view when the user data was already stored. * Refactored _TabChanged() so that this code is now executed in the now virtual SetCurrentWebView(), which makes the features also work for new tabs. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@466 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserWindow.cpp | 107 +++++++++++++++---------- src/apps/webpositive/BrowserWindow.h | 2 + 2 files changed, 67 insertions(+), 42 deletions(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index c5f9ce96e4..d1ee857392 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -750,9 +750,9 @@ BrowserWindow::QuitRequested() // Iterate over all tabs to delete all BWebViews. // Do this here, so WebKit tear down happens earlier. + SetCurrentWebView(NULL); while (fTabManager->CountTabs() > 0) _ShutdownTab(0); - SetCurrentWebView(NULL); BMessage message(WINDOW_CLOSED); message.AddRect("window frame", Frame()); @@ -769,6 +769,69 @@ BrowserWindow::MenusBeginning() } +static bool +viewIsChild(const BView* parent, const BView* view) +{ + if (parent == view) + return true; + + int32 count = parent->CountChildren(); + for (int32 i = 0; i < count; i++) { + BView* child = parent->ChildAt(i); + if (viewIsChild(child, view)) + return true; + } + return false; +} + + +void +BrowserWindow::SetCurrentWebView(BWebView* webView) +{ + if (webView == CurrentWebView()) + return; + + if (CurrentWebView() != NULL) { + // Remember the currently focused view before switching tabs, + // so that we can revert the focus when switching back to this tab + // later. + PageUserData* userData = static_cast( + CurrentWebView()->GetUserData()); + if (userData) + userData->SetFocusedView(CurrentFocus()); + else + CurrentWebView()->SetUserData(new PageUserData(CurrentFocus())); + } + + BWebWindow::SetCurrentWebView(webView); + + if (webView != NULL) { + _UpdateTitle(webView->MainFrameTitle()); + + // Restore the previous focus or focus the web view. + PageUserData* userData = static_cast( + webView->GetUserData()); + BView* focusedView = NULL; + if (userData != NULL) { + focusedView = userData->FocusedView(); + fURLInputGroup->SetPageIcon(userData->PageIcon()); + } + + if (focusedView != NULL + && viewIsChild(GetLayout()->View(), focusedView)) { + focusedView->MakeFocus(true); + } else + webView->MakeFocus(true); + + fURLInputGroup->SetText(webView->MainFrameURL()); + // Trigger update of the interface to the new page, by requesting + // to resend all notifications. + webView->WebPage()->ResendNotifications(); + } else + _UpdateTitle(""); +} + + void BrowserWindow::CreateNewTab(const BString& _url, bool select, BWebView* webView) { @@ -1150,47 +1213,7 @@ BrowserWindow::_ShutdownTab(int32 index) void BrowserWindow::_TabChanged(int32 index) { - BWebView* webView = dynamic_cast(fTabManager->ViewForTab(index)); - if (webView == CurrentWebView()) - return; - - if (CurrentWebView() != NULL) { - // Remember the currently focused view before switching tabs, - // so that we can revert the focus when switching back to this tab - // later. - PageUserData* userData = static_cast( - webView->GetUserData()); - if (userData) - userData->SetFocusedView(CurrentFocus()); - else - CurrentWebView()->SetUserData(new PageUserData(CurrentFocus())); - } - - SetCurrentWebView(webView); - - if (webView != NULL) { - _UpdateTitle(webView->MainFrameTitle()); - - // Restore the previous focus or focus the web view. - PageUserData* userData = static_cast( - webView->GetUserData()); - BView* focusedView = NULL; - if (userData != NULL) { - focusedView = userData->FocusedView(); - fURLInputGroup->SetPageIcon(userData->PageIcon()); - } - - if (focusedView != NULL) - focusedView->MakeFocus(true); - else - webView->MakeFocus(true); - - fURLInputGroup->SetText(webView->MainFrameURL()); - // Trigger update of the interface to the new page, by requesting - // to resend all notifications. - webView->WebPage()->ResendNotifications(); - } else - _UpdateTitle(""); + SetCurrentWebView(dynamic_cast(fTabManager->ViewForTab(index))); } diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index 9f3937257b..0e2769db49 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -89,6 +89,8 @@ public: virtual bool QuitRequested(); virtual void MenusBeginning(); + virtual void SetCurrentWebView(BWebView* view); + void CreateNewTab(const BString& url, bool select, BWebView* webView = 0);