Refactoring to support multiple WebViews per WebViewWindow. There is now the

notion of a current WebView. In the notification messages, carry the information
which WebView it is for.


git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@147 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi
2010-02-19 17:23:45 +00:00
parent a62545c155
commit a89e2a4b6c
3 changed files with 128 additions and 57 deletions
+10 -11
View File
@@ -130,15 +130,14 @@ void LauncherApp::MessageReceived(BMessage* message)
BString url; BString url;
if (message->FindString("url", &url) != B_OK) if (message->FindString("url", &url) != B_OK)
break; break;
bool newWindow; bool openNewWindow = false;
if (message->FindBool("new window", &newWindow) != B_OK) message->FindBool("new window", &openNewWindow);
newWindow = false; LauncherWindow* webWindow = NULL;
WebViewWindow* webWindow = NULL;
for (int i = 0; BWindow* window = WindowAt(i); i++) { for (int i = 0; BWindow* window = WindowAt(i); i++) {
webWindow = dynamic_cast<WebViewWindow*>(window); webWindow = dynamic_cast<LauncherWindow*>(window);
if (!webWindow) if (!webWindow)
continue; continue;
if (!newWindow) { if (!openNewWindow) {
// stop at the first window // stop at the first window
break; break;
} }
@@ -146,12 +145,12 @@ void LauncherApp::MessageReceived(BMessage* message)
if (webWindow) { if (webWindow) {
// There should always be at least one window open. If not, maybe we are about // There should always be at least one window open. If not, maybe we are about
// to quit anyway... // to quit anyway...
if (newWindow) { if (openNewWindow) {
// open a new window with an offset to the last window // open a new window with an offset to the last window
webWindow->newWindowRequested(url); newWindow(url);
} else { } else {
// load the URL in the first window // load the URL in the first window
webWindow->webView()->loadRequest(url.String()); webWindow->currentWebView()->loadRequest(url.String());
} }
} }
break; break;
@@ -218,7 +217,7 @@ void LauncherApp::RefsReceived(BMessage* message)
bool LauncherApp::QuitRequested() bool LauncherApp::QuitRequested()
{ {
for (int i = 0; BWindow* window = WindowAt(i); i++) { for (int i = 0; BWindow* window = WindowAt(i); i++) {
WebViewWindow* webWindow = dynamic_cast<WebViewWindow*>(window); LauncherWindow* webWindow = dynamic_cast<LauncherWindow*>(window);
if (!webWindow) if (!webWindow)
continue; continue;
if (!webWindow->Lock()) if (!webWindow->Lock())
@@ -268,7 +267,7 @@ void LauncherApp::newWindow(const BString& url)
BMessenger(m_downloadWindow)); BMessenger(m_downloadWindow));
window->Show(); window->Show();
if (url.Length()) if (url.Length())
window->webView()->loadRequest(url.String()); window->currentWebView()->loadRequest(url.String());
} }
// #pragma mark - // #pragma mark -
+102 -36
View File
@@ -88,6 +88,7 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS) B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS)
{ {
setCurrentWebView(new WebView("web_view"));
if (toolbarPolicy == HaveToolbar) { if (toolbarPolicy == HaveToolbar) {
// Menu // Menu
m_menuBar = new BMenuBar("Main menu"); m_menuBar = new BMenuBar("Main menu");
@@ -174,7 +175,7 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
.SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing) .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing)
) )
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.Add(webView()) .Add(currentWebView())
.Add(findGroup) .Add(findGroup)
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing)
@@ -196,11 +197,11 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
m_loadingProgressBar = 0; m_loadingProgressBar = 0;
AddChild(BGroupLayoutBuilder(B_VERTICAL, 7) AddChild(BGroupLayoutBuilder(B_VERTICAL, 7)
.Add(webView()) .Add(currentWebView())
); );
} }
webView()->webPage()->setDownloadListener(downloadListener); currentWebView()->webPage()->setDownloadListener(downloadListener);
m_findGroup->SetVisible(false); m_findGroup->SetVisible(false);
@@ -209,7 +210,7 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
AddShortcut('F', B_COMMAND_KEY, new BMessage(TEXT_SHOW_FIND_GROUP)); AddShortcut('F', B_COMMAND_KEY, new BMessage(TEXT_SHOW_FIND_GROUP));
AddShortcut('F', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(TEXT_HIDE_FIND_GROUP)); AddShortcut('F', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(TEXT_HIDE_FIND_GROUP));
navigationCapabilitiesChanged(false, false, false); navigationCapabilitiesChanged(false, false, false, currentWebView());
be_app->PostMessage(WINDOW_OPENED); be_app->PostMessage(WINDOW_OPENED);
} }
@@ -222,20 +223,20 @@ void LauncherWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case RELOAD: case RELOAD:
webView()->loadRequest(m_url->Text()); currentWebView()->loadRequest(m_url->Text());
break; break;
case GOTO_URL: { case GOTO_URL: {
BString url = m_url->Text(); BString url = m_url->Text();
message->FindString("url", &url); message->FindString("url", &url);
if (m_loadedURL != url) if (m_loadedURL != url)
webView()->loadRequest(url.String()); currentWebView()->loadRequest(url.String());
break; break;
} }
case GO_BACK: case GO_BACK:
webView()->goBack(); currentWebView()->goBack();
break; break;
case GO_FORWARD: case GO_FORWARD:
webView()->goForward(); currentWebView()->goForward();
break; break;
case CLEAR_HISTORY: { case CLEAR_HISTORY: {
@@ -271,26 +272,26 @@ void LauncherWindow::MessageReceived(BMessage* message)
BPath path; BPath path;
if (!entry.Exists() || entry.GetPath(&path) != B_OK) if (!entry.Exists() || entry.GetPath(&path) != B_OK)
break; break;
webView()->loadRequest(path.Path()); currentWebView()->loadRequest(path.Path());
break; break;
} }
case TEXT_SIZE_INCREASE: case TEXT_SIZE_INCREASE:
webView()->increaseTextSize(); currentWebView()->increaseTextSize();
break; break;
case TEXT_SIZE_DECREASE: case TEXT_SIZE_DECREASE:
webView()->decreaseTextSize(); currentWebView()->decreaseTextSize();
break; break;
case TEXT_SIZE_RESET: case TEXT_SIZE_RESET:
webView()->resetTextSize(); currentWebView()->resetTextSize();
break; break;
case TEXT_FIND_NEXT: case TEXT_FIND_NEXT:
webView()->findString(m_findTextControl->Text(), true, currentWebView()->findString(m_findTextControl->Text(), true,
m_findCaseSensitiveCheckBox->Value()); m_findCaseSensitiveCheckBox->Value());
break; break;
case TEXT_FIND_PREVIOUS: case TEXT_FIND_PREVIOUS:
webView()->findString(m_findTextControl->Text(), false, currentWebView()->findString(m_findTextControl->Text(), false,
m_findCaseSensitiveCheckBox->Value()); m_findCaseSensitiveCheckBox->Value());
break; break;
case TEXT_SHOW_FIND_GROUP: case TEXT_SHOW_FIND_GROUP:
@@ -309,20 +310,26 @@ void LauncherWindow::MessageReceived(BMessage* message)
break; break;
default: default:
WebViewWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
} }
} }
bool LauncherWindow::QuitRequested() bool LauncherWindow::QuitRequested()
{ {
if (WebViewWindow::QuitRequested()) { // TODO: Check for modified form data and ask user for confirmation, etc.
BMessage message(WINDOW_CLOSED);
message.AddRect("window frame", Frame()); // Do this here, so WebKit tear down happens earlier.
be_app->PostMessage(&message); // TODO: Iterator over all WebViews, if there are more then one...
return true; WebView* view = currentWebView();
} view->RemoveSelf();
return false; delete view;
setCurrentWebView(0);
BMessage message(WINDOW_CLOSED);
message.AddRect("window frame", Frame());
be_app->PostMessage(&message);
return true;
} }
void LauncherWindow::MenusBeginning() void LauncherWindow::MenusBeginning()
@@ -341,7 +348,9 @@ void LauncherWindow::MenusBeginning()
BMessage* message = new BMessage(GOTO_URL); BMessage* message = new BMessage(GOTO_URL);
message->AddString("url", historyItem.url().String()); message->AddString("url", historyItem.url().String());
// TODO: More sophisticated menu structure... sorted by days/weeks... // TODO: More sophisticated menu structure... sorted by days/weeks...
menuItem = new BMenuItem(historyItem.url().String(), message); BString truncatedUrl(historyItem.url());
be_plain_font->TruncateString(&truncatedUrl, B_TRUNCATE_END, 480);
menuItem = new BMenuItem(truncatedUrl, message);
m_goMenu->AddItem(menuItem); m_goMenu->AddItem(menuItem);
} }
@@ -356,8 +365,9 @@ void LauncherWindow::MenusBeginning()
// #pragma mark - Notification API // #pragma mark - Notification API
void LauncherWindow::navigationRequested(const BString& url) void LauncherWindow::navigationRequested(const BString& url, WebView* view)
{ {
// TODO: Move elsewhere, doesn't belong here.
m_loadedURL = url; m_loadedURL = url;
if (m_url) if (m_url)
m_url->SetText(url.String()); m_url->SetText(url.String());
@@ -374,22 +384,25 @@ void LauncherWindow::newWindowRequested(const BString& url)
be_app->PostMessage(&message); be_app->PostMessage(&message);
} }
void LauncherWindow::loadNegociating(const BString& url) void LauncherWindow::loadNegociating(const BString& url, WebView* view)
{ {
BString status("Requesting: "); BString status("Requesting: ");
status << url; status << url;
statusChanged(status); statusChanged(status, view);
} }
void LauncherWindow::loadTransfering(const BString& url) void LauncherWindow::loadTransfering(const BString& url, WebView* view)
{ {
BString status("Loading: "); BString status("Loading: ");
status << url; status << url;
statusChanged(status); statusChanged(status, view);
} }
void LauncherWindow::loadProgress(float progress) void LauncherWindow::loadProgress(float progress, WebView* view)
{ {
if (view != currentWebView())
return;
if (m_loadingProgressBar) { if (m_loadingProgressBar) {
if (progress < 100 && m_loadingProgressBar->IsHidden()) if (progress < 100 && m_loadingProgressBar->IsHidden())
m_loadingProgressBar->Show(); m_loadingProgressBar->Show();
@@ -397,29 +410,76 @@ void LauncherWindow::loadProgress(float progress)
} }
} }
void LauncherWindow::loadFailed(const BString& url) void LauncherWindow::loadFailed(const BString& url, WebView* view)
{ {
if (view != currentWebView())
return;
BString status(url); BString status(url);
status << " failed."; status << " failed.";
statusChanged(status); statusChanged(status, view);
if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden()) if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden())
m_loadingProgressBar->Hide(); m_loadingProgressBar->Hide();
} }
void LauncherWindow::loadFinished(const BString& url) void LauncherWindow::loadFinished(const BString& url, WebView* view)
{ {
if (view != currentWebView())
return;
m_loadedURL = url; m_loadedURL = url;
BString status(url); BString status(url);
status << " finished."; status << " finished.";
statusChanged(status); statusChanged(status, view);
if (m_url) if (m_url)
m_url->SetText(url.String()); m_url->SetText(url.String());
if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden()) if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden())
m_loadingProgressBar->Hide(); m_loadingProgressBar->Hide();
} }
void LauncherWindow::titleChanged(const BString& title) void LauncherWindow::resizeRequested(float width, float height, WebView* view)
{ {
if (view != currentWebView())
return;
// TODO: Ignore request when there is more than one WebView embedded!
ResizeTo(width, height);
}
void LauncherWindow::setToolBarsVisible(bool flag, WebView* view)
{
// TODO
// TODO: Ignore request when there is more than one WebView embedded!
}
void LauncherWindow::setStatusBarVisible(bool flag, WebView* view)
{
// TODO
// TODO: Ignore request when there is more than one WebView embedded!
}
void LauncherWindow::setMenuBarVisible(bool flag, WebView* view)
{
// TODO
// TODO: Ignore request when there is more than one WebView embedded!
}
void LauncherWindow::setResizable(bool flag, WebView* view)
{
// TODO: Ignore request when there is more than one WebView embedded!
if (flag)
SetFlags(Flags() & ~B_NOT_RESIZABLE);
else
SetFlags(Flags() | B_NOT_RESIZABLE);
}
void LauncherWindow::titleChanged(const BString& title, WebView* view)
{
if (view != currentWebView())
return;
BString windowTitle = title; BString windowTitle = title;
if (windowTitle.Length() > 0) if (windowTitle.Length() > 0)
windowTitle << " - "; windowTitle << " - ";
@@ -427,15 +487,21 @@ void LauncherWindow::titleChanged(const BString& title)
SetTitle(windowTitle.String()); SetTitle(windowTitle.String());
} }
void LauncherWindow::statusChanged(const BString& statusText) void LauncherWindow::statusChanged(const BString& statusText, WebView* view)
{ {
if (view != currentWebView())
return;
if (m_statusText) if (m_statusText)
m_statusText->SetText(statusText.String()); m_statusText->SetText(statusText.String());
} }
void LauncherWindow::navigationCapabilitiesChanged(bool canGoBackward, void LauncherWindow::navigationCapabilitiesChanged(bool canGoBackward,
bool canGoForward, bool canStop) bool canGoForward, bool canStop, WebView* view)
{ {
if (view != currentWebView())
return;
if (m_BackButton) if (m_BackButton)
m_BackButton->SetEnabled(canGoBackward); m_BackButton->SetEnabled(canGoBackward);
if (m_ForwardButton) if (m_ForwardButton)
+16 -10
View File
@@ -64,18 +64,24 @@ public:
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MenusBeginning(); virtual void MenusBeginning();
// WebViewWindow notification API implementations private:
virtual void navigationRequested(const BString& url); // WebPage notification API implementations
virtual void navigationRequested(const BString& url, WebView* view);
virtual void newWindowRequested(const BString& url); virtual void newWindowRequested(const BString& url);
virtual void loadNegociating(const BString& url); virtual void loadNegociating(const BString& url, WebView* view);
virtual void loadTransfering(const BString& url); virtual void loadTransfering(const BString& url, WebView* view);
virtual void loadProgress(float progress); virtual void loadProgress(float progress, WebView* view);
virtual void loadFailed(const BString& url); virtual void loadFailed(const BString& url, WebView* view);
virtual void loadFinished(const BString& url); virtual void loadFinished(const BString& url, WebView* view);
virtual void titleChanged(const BString& title); virtual void titleChanged(const BString& title, WebView* view);
virtual void statusChanged(const BString& status); virtual void resizeRequested(float width, float height, WebView* view);
virtual void setToolBarsVisible(bool flag, WebView* view);
virtual void setStatusBarVisible(bool flag, WebView* view);
virtual void setMenuBarVisible(bool flag, WebView* view);
virtual void setResizable(bool flag, WebView* view);
virtual void statusChanged(const BString& status, WebView* view);
virtual void navigationCapabilitiesChanged(bool canGoBackward, virtual void navigationCapabilitiesChanged(bool canGoBackward,
bool canGoForward, bool canStop); bool canGoForward, bool canStop, WebView* view);
virtual void updateGlobalHistory(const BString& url); virtual void updateGlobalHistory(const BString& url);
virtual void authenticationChallenge(BMessage* challenge); virtual void authenticationChallenge(BMessage* challenge);