Add basic tabbed browsing support. Does not yet properly handle maintaining/switching the current URL or status bar text per-tab.
git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@152 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
parent
c14fa62638
commit
95b246f2a7
@ -35,6 +35,7 @@
|
|||||||
#include "AuthenticationPanel.h"
|
#include "AuthenticationPanel.h"
|
||||||
#include "BrowsingHistory.h"
|
#include "BrowsingHistory.h"
|
||||||
#include "WebPage.h"
|
#include "WebPage.h"
|
||||||
|
#include "WebTabView.h"
|
||||||
#include "WebView.h"
|
#include "WebView.h"
|
||||||
#include "WebViewConstants.h"
|
#include "WebViewConstants.h"
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
@ -88,16 +89,26 @@ 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"));
|
m_tabView = new WebTabView("tabview", BMessenger(this));
|
||||||
|
WebView *webView = new WebView("web_view");
|
||||||
|
m_tabView->AddTab(webView);
|
||||||
|
m_tabView->TabAt(0L)->SetLabel("New Tab");
|
||||||
|
setCurrentWebView(webView);
|
||||||
|
|
||||||
if (toolbarPolicy == HaveToolbar) {
|
if (toolbarPolicy == HaveToolbar) {
|
||||||
// Menu
|
// Menu
|
||||||
m_menuBar = new BMenuBar("Main menu");
|
m_menuBar = new BMenuBar("Main menu");
|
||||||
BMenu* menu = new BMenu("Window");
|
BMenu* menu = new BMenu("Window");
|
||||||
BMessage* newWindowMessage = new BMessage(NEW_WINDOW);
|
BMessage* newWindowMessage = new BMessage(NEW_WINDOW);
|
||||||
newWindowMessage->AddString("url", "");
|
newWindowMessage->AddString("url", "");
|
||||||
BMenuItem* newItem = new BMenuItem("New", newWindowMessage, 'N');
|
BMenu *newMenu = new BMenu("New");
|
||||||
menu->AddItem(newItem);
|
BMenuItem* newItem = new BMenuItem("Window", newWindowMessage, 'N');
|
||||||
|
newMenu->AddItem(newItem);
|
||||||
newItem->SetTarget(be_app);
|
newItem->SetTarget(be_app);
|
||||||
|
newItem = new BMenuItem("Tab", new BMessage(NEW_TAB), 'T');
|
||||||
|
newMenu->AddItem(newItem);
|
||||||
|
newItem->SetTarget(this);
|
||||||
|
menu->AddItem(newMenu);
|
||||||
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
|
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
menu->AddItem(new BMenuItem("Show Downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
|
menu->AddItem(new BMenuItem("Show Downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
|
||||||
@ -175,7 +186,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(currentWebView())
|
.Add(m_tabView)
|
||||||
.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)
|
||||||
@ -309,6 +320,24 @@ void LauncherWindow::MessageReceived(BMessage* message)
|
|||||||
be_app->PostMessage(message);
|
be_app->PostMessage(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case NEW_TAB:
|
||||||
|
{
|
||||||
|
m_tabView->AddTab(new WebView("web_view"));
|
||||||
|
m_tabView->TabAt(m_tabView->CountTabs() - 1)->SetLabel("New Tab");
|
||||||
|
m_tabView->DrawTabs();
|
||||||
|
m_tabView->Select(m_tabView->CountTabs() - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TAB_CHANGED:
|
||||||
|
{
|
||||||
|
int32 index = message->FindInt32("index");
|
||||||
|
setCurrentWebView(dynamic_cast<WebView *>(
|
||||||
|
m_tabView->ViewForTab(index)));
|
||||||
|
updateTitle(m_tabView->TabAt(index)->Label());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
WebViewWindow::MessageReceived(message);
|
WebViewWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@ -477,14 +506,18 @@ void LauncherWindow::setResizable(bool flag, WebView* view)
|
|||||||
|
|
||||||
void LauncherWindow::titleChanged(const BString& title, WebView* view)
|
void LauncherWindow::titleChanged(const BString& title, WebView* view)
|
||||||
{
|
{
|
||||||
|
for (int32 i = 0; i < m_tabView->CountTabs(); i++)
|
||||||
|
{
|
||||||
|
if (m_tabView->ViewForTab(i) == view) {
|
||||||
|
m_tabView->TabAt(i)->SetLabel(title);
|
||||||
|
m_tabView->DrawTabs();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (view != currentWebView())
|
if (view != currentWebView())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BString windowTitle = title;
|
updateTitle(title);
|
||||||
if (windowTitle.Length() > 0)
|
|
||||||
windowTitle << " - ";
|
|
||||||
windowTitle << "HaikuLauncher";
|
|
||||||
SetTitle(windowTitle.String());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherWindow::statusChanged(const BString& statusText, WebView* view)
|
void LauncherWindow::statusChanged(const BString& statusText, WebView* view)
|
||||||
@ -539,3 +572,12 @@ void LauncherWindow::authenticationChallenge(BMessage* message)
|
|||||||
reply.AddBool("rememberCredentials", rememberCredentials);
|
reply.AddBool("rememberCredentials", rememberCredentials);
|
||||||
message->SendReply(&reply);
|
message->SendReply(&reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LauncherWindow::updateTitle(const BString& title)
|
||||||
|
{
|
||||||
|
BString windowTitle = title;
|
||||||
|
if (windowTitle.Length() > 0)
|
||||||
|
windowTitle << " - ";
|
||||||
|
windowTitle << "HaikuLauncher";
|
||||||
|
SetTitle(windowTitle.String());
|
||||||
|
}
|
||||||
|
@ -39,6 +39,7 @@ class BLayoutItem;
|
|||||||
class BMenu;
|
class BMenu;
|
||||||
class BStatusBar;
|
class BStatusBar;
|
||||||
class BStringView;
|
class BStringView;
|
||||||
|
class BTabView;
|
||||||
class BTextControl;
|
class BTextControl;
|
||||||
class WebView;
|
class WebView;
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ enum ToolbarPolicy {
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
NEW_WINDOW = 'nwnd',
|
NEW_WINDOW = 'nwnd',
|
||||||
|
NEW_TAB = 'ntab',
|
||||||
WINDOW_OPENED = 'wndo',
|
WINDOW_OPENED = 'wndo',
|
||||||
WINDOW_CLOSED = 'wndc',
|
WINDOW_CLOSED = 'wndc',
|
||||||
SHOW_DOWNLOAD_WINDOW = 'sdwd'
|
SHOW_DOWNLOAD_WINDOW = 'sdwd'
|
||||||
@ -84,6 +86,7 @@ private:
|
|||||||
bool canGoForward, bool canStop, WebView* view);
|
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);
|
||||||
|
void updateTitle(const BString &title);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMenuBar* m_menuBar;
|
BMenuBar* m_menuBar;
|
||||||
@ -97,6 +100,7 @@ private:
|
|||||||
BLayoutItem* m_findGroup;
|
BLayoutItem* m_findGroup;
|
||||||
BTextControl* m_findTextControl;
|
BTextControl* m_findTextControl;
|
||||||
BCheckBox* m_findCaseSensitiveCheckBox;
|
BCheckBox* m_findCaseSensitiveCheckBox;
|
||||||
|
BTabView* m_tabView;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LauncherWindow_h
|
#endif // LauncherWindow_h
|
||||||
|
57
src/apps/webpositive/WebTabView.cpp
Normal file
57
src/apps/webpositive/WebTabView.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Rene Gollent <rene@gollent.com>
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||||
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "WebTabView.h"
|
||||||
|
|
||||||
|
WebTabView::WebTabView(const char *name, const BMessenger& target)
|
||||||
|
: BTabView(name)
|
||||||
|
, m_target(target)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
WebTabView::~WebTabView(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
WebTabView::Select(int32 tab)
|
||||||
|
{
|
||||||
|
BTabView::Select(tab);
|
||||||
|
BMessage message(TAB_CHANGED);
|
||||||
|
message.AddInt32("index", tab);
|
||||||
|
m_target.SendMessage(&message);
|
||||||
|
}
|
||||||
|
|
||||||
|
const BMessenger& WebTabView::Target(void) const
|
||||||
|
{
|
||||||
|
return m_target;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebTabView::SetTarget(const BMessenger& target)
|
||||||
|
{
|
||||||
|
m_target = target;
|
||||||
|
}
|
52
src/apps/webpositive/WebTabView.h
Normal file
52
src/apps/webpositive/WebTabView.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Rene Gollent <rene@gollent.com>
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||||
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WebTabView_h
|
||||||
|
#define WebTabView_h
|
||||||
|
|
||||||
|
#include <Messenger.h>
|
||||||
|
#include <TabView.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TAB_CHANGED = 'tcha'
|
||||||
|
};
|
||||||
|
|
||||||
|
class WebTabView : public BTabView {
|
||||||
|
public:
|
||||||
|
WebTabView(const char *name, const BMessenger& target);
|
||||||
|
virtual ~WebTabView(void);
|
||||||
|
virtual void Select(int32 tab);
|
||||||
|
|
||||||
|
const BMessenger& Target(void) const;
|
||||||
|
void SetTarget(const BMessenger& target);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BMessenger m_target;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define WebTabView_h
|
||||||
|
#endif // WebTabView_h
|
Loading…
Reference in New Issue
Block a user