* 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
This commit is contained in:
stippi 2010-04-30 15:40:36 +00:00 committed by Alexandre Deckner
parent 65cc5e49ee
commit a4c1f6783d
2 changed files with 67 additions and 42 deletions

View File

@ -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<PageUserData*>(
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<PageUserData*>(
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<BWebView*>(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<PageUserData*>(
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<PageUserData*>(
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<BWebView*>(fTabManager->ViewForTab(index)));
}

View File

@ -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);