diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index 5ebef34120..3dd0d7a25a 100644 --- a/src/apps/webpositive/BrowserApp.cpp +++ b/src/apps/webpositive/BrowserApp.cpp @@ -8,10 +8,10 @@ * 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. + * 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. + * 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 @@ -27,17 +27,16 @@ */ #include "config.h" -#include "LauncherApp.h" +#include "BrowserApp.h" +#include "BrowserWindow.h" #include "DownloadWindow.h" -#include "FrameView.h" -#include "GraphicsContext.h" -#include "LauncherWindow.h" #include "WebPage.h" #include "WebView.h" #include "WebViewConstants.h" #include #include +#include #include #include #include @@ -45,170 +44,187 @@ #include #include -extern const char* kApplicationSignature = "application/x-vnd.RJL-HaikuLauncher"; + +const char* kApplicationSignature = "application/x-vnd.Haiku-WebPositive"; +const char* kApplicationName = "WebPositive"; + + enum { - LOAD_AT_STARTING = 'lost' + LOAD_AT_STARTING = 'lost' }; -LauncherApp::LauncherApp() - : BApplication(kApplicationSignature) - , m_windowCount(0) - , m_lastWindowFrame(100, 100, 700, 750) - , m_launchRefsMessage(0) - , m_initialized(false) - , m_downloadWindow(0) +BrowserApp::BrowserApp() + : BApplication(kApplicationSignature) + , fWindowCount(0) + , fLastWindowFrame(100, 100, 700, 750) + , fLaunchRefsMessage(0) + , fInitialized(false) + , fDownloadWindow(0) { } -LauncherApp::~LauncherApp() + +BrowserApp::~BrowserApp() { - delete m_launchRefsMessage; + delete fLaunchRefsMessage; } -void LauncherApp::AboutRequested() + +void +BrowserApp::AboutRequested() { - BAlert* alert = new BAlert("About HaikuLauncher", - "For testing WebKit...\n\nby Ryan Leavengood", "Sweet!"); - alert->Go(); + BAlert* alert = new BAlert("About WebPositive", + "WebPositive\n\nby Ryan Leavengood, Andrea Anzani, " + "Maxime Simone, Michael Lotz, Rene Gollent and Stephan Aßmus", + "Sweet!"); + alert->Go(); } -void LauncherApp::ArgvReceived(int32 argc, char** argv) + +void +BrowserApp::ArgvReceived(int32 argc, char** argv) { for (int i = 1; i < argc; i++) { const char* url = argv[i]; BEntry entry(argv[i], true); BPath path; if (entry.Exists() && entry.GetPath(&path) == B_OK) - url = path.Path(); - BMessage message(LOAD_AT_STARTING); - message.AddString("url", url); - message.AddBool("new window", m_initialized || i > 1); - PostMessage(&message); + url = path.Path(); + BMessage message(LOAD_AT_STARTING); + message.AddString("url", url); + message.AddBool("new window", fInitialized || i > 1); + PostMessage(&message); } } -void LauncherApp::ReadyToRun() + +void +BrowserApp::ReadyToRun() { // Since we will essentially run the GUI... set_thread_priority(Thread(), B_DISPLAY_PRIORITY); - BWebPage::InitializeOnce(); - BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); + BWebPage::InitializeOnce(); + BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); BFile settingsFile; - BRect windowFrameFromSettings = m_lastWindowFrame; + BRect windowFrameFromSettings = fLastWindowFrame; BRect downloadWindowFrame(100, 100, 300, 250); bool showDownloads = false; - if (openSettingsFile(settingsFile, B_READ_ONLY)) { + if (_OpenSettingsFile(settingsFile, B_READ_ONLY)) { BMessage settingsArchive; settingsArchive.Unflatten(&settingsFile); settingsArchive.FindRect("window frame", &windowFrameFromSettings); settingsArchive.FindRect("downloads window frame", &downloadWindowFrame); settingsArchive.FindBool("show downloads", &showDownloads); } - m_lastWindowFrame = windowFrameFromSettings; + fLastWindowFrame = windowFrameFromSettings; - m_downloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads); + fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads); - m_initialized = true; + fInitialized = true; - if (m_launchRefsMessage) { - RefsReceived(m_launchRefsMessage); - delete m_launchRefsMessage; - m_launchRefsMessage = 0; + if (fLaunchRefsMessage) { + RefsReceived(fLaunchRefsMessage); + delete fLaunchRefsMessage; + fLaunchRefsMessage = 0; } else { - LauncherWindow* window = new LauncherWindow(m_lastWindowFrame, - BMessenger(m_downloadWindow)); - window->Show(); + BrowserWindow* window = new BrowserWindow(fLastWindowFrame, + BMessenger(fDownloadWindow)); + window->Show(); } } -void LauncherApp::MessageReceived(BMessage* message) + +void +BrowserApp::MessageReceived(BMessage* message) { - switch (message->what) { - case LOAD_AT_STARTING: { - BString url; - if (message->FindString("url", &url) != B_OK) - break; - bool openNewWindow = false; - message->FindBool("new window", &openNewWindow); - LauncherWindow* webWindow = NULL; - for (int i = 0; BWindow* window = WindowAt(i); i++) { - webWindow = dynamic_cast(window); - if (!webWindow) - continue; - if (!openNewWindow) { - // stop at the first window - break; - } - } - if (webWindow) { - // There should always be at least one window open. If not, maybe we are about - // to quit anyway... - if (openNewWindow) { - // open a new window with an offset to the last window - newWindow(url); - } else { - // load the URL in the first window - webWindow->CurrentWebView()->LoadURL(url.String()); - } - } - break; - } - case B_SILENT_RELAUNCH: - newWindow(""); - break; - case NEW_WINDOW: { + switch (message->what) { + case LOAD_AT_STARTING: { BString url; if (message->FindString("url", &url) != B_OK) break; - newWindow(url); - break; - } - case NEW_TAB: { - LauncherWindow* window; + bool openNewWindow = false; + message->FindBool("new window", &openNewWindow); + BrowserWindow* webWindow = NULL; + for (int i = 0; BWindow* window = WindowAt(i); i++) { + webWindow = dynamic_cast(window); + if (!webWindow) + continue; + if (!openNewWindow) { + // stop at the first window + break; + } + } + if (webWindow) { + // There should always be at least one window open. If not, maybe we are about + // to quit anyway... + if (openNewWindow) { + // open a new window with an offset to the last window + _CreateNewWindow(url); + } else { + // load the URL in the first window + webWindow->CurrentWebView()->LoadURL(url.String()); + } + } + break; + } + case B_SILENT_RELAUNCH: + _CreateNewWindow(""); + break; + case NEW_WINDOW: { + BString url; + if (message->FindString("url", &url) != B_OK) + break; + _CreateNewWindow(url); + break; + } + case NEW_TAB: { + BrowserWindow* window; if (message->FindPointer("window", reinterpret_cast(&window)) != B_OK) break; - BString url; + BString url; message->FindString("url", &url); - bool select = false; + bool select = false; message->FindBool("select", &select); - newTab(window, url, select); - break; - } - case WINDOW_OPENED: - m_windowCount++; - break; - case WINDOW_CLOSED: - m_windowCount--; - message->FindRect("window frame", &m_lastWindowFrame); - if (m_windowCount <= 0) - PostMessage(B_QUIT_REQUESTED); - break; + _CreateNewTab(window, url, select); + break; + } + case WINDOW_OPENED: + fWindowCount++; + break; + case WINDOW_CLOSED: + fWindowCount--; + message->FindRect("window frame", &fLastWindowFrame); + if (fWindowCount <= 0) + PostMessage(B_QUIT_REQUESTED); + break; - case SHOW_DOWNLOAD_WINDOW: { - BAutolock _(m_downloadWindow); - uint32 workspaces; - if (message->FindUInt32("workspaces", &workspaces) == B_OK) - m_downloadWindow->SetWorkspaces(workspaces); - if (m_downloadWindow->IsHidden()) - m_downloadWindow->Show(); - else - m_downloadWindow->Activate(); - } + case SHOW_DOWNLOAD_WINDOW: { + BAutolock _(fDownloadWindow); + uint32 workspaces; + if (message->FindUInt32("workspaces", &workspaces) == B_OK) + fDownloadWindow->SetWorkspaces(workspaces); + if (fDownloadWindow->IsHidden()) + fDownloadWindow->Show(); + else + fDownloadWindow->Activate(); + } - default: - BApplication::MessageReceived(message); - break; - } + default: + BApplication::MessageReceived(message); + break; + } } -void LauncherApp::RefsReceived(BMessage* message) + +void +BrowserApp::RefsReceived(BMessage* message) { - if (!m_initialized) { - delete m_launchRefsMessage; - m_launchRefsMessage = new BMessage(*message); + if (!fInitialized) { + delete fLaunchRefsMessage; + fLaunchRefsMessage = new BMessage(*message); return; } @@ -222,82 +238,97 @@ void LauncherApp::RefsReceived(BMessage* message) continue; BString url; url << path.Path(); - newWindow(url); + _CreateNewWindow(url); } } -bool LauncherApp::QuitRequested() + +bool +BrowserApp::QuitRequested() { - for (int i = 0; BWindow* window = WindowAt(i); i++) { - LauncherWindow* webWindow = dynamic_cast(window); - if (!webWindow) - continue; - if (!webWindow->Lock()) - continue; - if (webWindow->QuitRequested()) { - m_lastWindowFrame = webWindow->Frame(); - webWindow->Quit(); - i--; - } else { - webWindow->Unlock(); - return false; - } - } + for (int i = 0; BWindow* window = WindowAt(i); i++) { + BrowserWindow* webWindow = dynamic_cast(window); + if (!webWindow) + continue; + if (!webWindow->Lock()) + continue; + if (webWindow->QuitRequested()) { + fLastWindowFrame = webWindow->Frame(); + webWindow->Quit(); + i--; + } else { + webWindow->Unlock(); + return false; + } + } BFile settingsFile; - if (openSettingsFile(settingsFile, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)) { + if (_OpenSettingsFile(settingsFile, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)) { BMessage settingsArchive; - settingsArchive.AddRect("window frame", m_lastWindowFrame); - if (m_downloadWindow->Lock()) { - settingsArchive.AddRect("downloads window frame", m_downloadWindow->Frame()); - settingsArchive.AddBool("show downloads", !m_downloadWindow->IsHidden()); - m_downloadWindow->Unlock(); + settingsArchive.AddRect("window frame", fLastWindowFrame); + if (fDownloadWindow->Lock()) { + settingsArchive.AddRect("downloads window frame", fDownloadWindow->Frame()); + settingsArchive.AddBool("show downloads", !fDownloadWindow->IsHidden()); + fDownloadWindow->Unlock(); } settingsArchive.Flatten(&settingsFile); } - return true; + return true; } -bool LauncherApp::openSettingsFile(BFile& file, uint32 mode) + +bool +BrowserApp::_OpenSettingsFile(BFile& file, uint32 mode) { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK - || path.Append("HaikuLauncher") != B_OK) { + || path.Append(kApplicationName) != B_OK + || create_directory(path.Path(), 0777) != B_OK + || path.Append("Application") != B_OK) { return false; } + return file.SetTo(path.Path(), mode) == B_OK; } -void LauncherApp::newWindow(const BString& url) -{ - m_lastWindowFrame.OffsetBy(20, 20); - if (!BScreen().Frame().Contains(m_lastWindowFrame)) - m_lastWindowFrame.OffsetTo(50, 50); - LauncherWindow* window = new LauncherWindow(m_lastWindowFrame, - BMessenger(m_downloadWindow)); +void +BrowserApp::_CreateNewWindow(const BString& url) +{ + fLastWindowFrame.OffsetBy(20, 20); + if (!BScreen().Frame().Contains(fLastWindowFrame)) + fLastWindowFrame.OffsetTo(50, 50); + + BrowserWindow* window = new BrowserWindow(fLastWindowFrame, + BMessenger(fDownloadWindow)); window->Show(); if (url.Length()) - window->CurrentWebView()->LoadURL(url.String()); + window->CurrentWebView()->LoadURL(url.String()); } -void LauncherApp::newTab(LauncherWindow* window, const BString& url, bool select) + +void +BrowserApp::_CreateNewTab(BrowserWindow* window, const BString& url, + bool select) { - if (!window->Lock()) - return; - window->newTab(url, select); - window->Unlock(); + if (!window->Lock()) + return; + window->CreateNewTab(url, select); + window->Unlock(); } + // #pragma mark - -int main(int, char**) -{ - new LauncherApp(); - be_app->Run(); - delete be_app; - return 0; +int +main(int, char**) +{ + new BrowserApp(); + be_app->Run(); + delete be_app; + + return 0; } diff --git a/src/apps/webpositive/BrowserApp.h b/src/apps/webpositive/BrowserApp.h index 15dabba6a2..f834d41f62 100644 --- a/src/apps/webpositive/BrowserApp.h +++ b/src/apps/webpositive/BrowserApp.h @@ -8,10 +8,10 @@ * 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. + * 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. + * 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 @@ -25,43 +25,49 @@ * (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 BROWSER_APP_H +#define BROWSER_APP_H -#ifndef LauncherApp_h -#define LauncherApp_h #include #include class BFile; class DownloadWindow; -class LauncherWindow; +class BrowserWindow; -class LauncherApp : public BApplication { + +class BrowserApp : public BApplication { public: - LauncherApp(); - virtual ~LauncherApp(); + BrowserApp(); + virtual ~BrowserApp(); - virtual void AboutRequested(); - virtual void ArgvReceived(int32, char**); - virtual void MessageReceived(BMessage*); - virtual void RefsReceived(BMessage*); - virtual void ReadyToRun(); - virtual bool QuitRequested(); + virtual void AboutRequested(); + virtual void ArgvReceived(int32 agrc, char** argv); + virtual void MessageReceived(BMessage* message); + virtual void RefsReceived(BMessage* message); + virtual void ReadyToRun(); + virtual bool QuitRequested(); private: - bool openSettingsFile(BFile& file, uint32 mode); - void newWindow(const BString& url); - void newTab(LauncherWindow* window, const BString& url, bool select); + bool _OpenSettingsFile(BFile& file, uint32 mode); + void _CreateNewWindow(const BString& url); + void _CreateNewTab(BrowserWindow* window, + const BString& url, bool select); - int m_windowCount; - BRect m_lastWindowFrame; - BMessage* m_launchRefsMessage; - bool m_initialized; +private: + int fWindowCount; + BRect fLastWindowFrame; + BMessage* fLaunchRefsMessage; + bool fInitialized; - DownloadWindow* m_downloadWindow; + DownloadWindow* fDownloadWindow; }; + extern const char* kApplicationSignature; +extern const char* kApplicationName; -#endif // LauncherApp_h + +#endif // BROWSER_APP_H diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index 37ff504ae6..ee11bf91ac 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -31,12 +31,12 @@ */ #include "config.h" -#include "LauncherWindow.h" +#include "BrowserWindow.h" #include "AuthenticationPanel.h" +#include "BrowserApp.h" #include "BrowsingHistory.h" #include "IconButton.h" -#include "LauncherApp.h" #include "WebPage.h" #include "WebTabView.h" #include "WebView.h" @@ -61,628 +61,687 @@ #include + enum { OPEN_LOCATION = 'open', - GO_BACK = 'goba', - GO_FORWARD = 'gofo', - STOP = 'stop', - GOTO_URL = 'goul', - RELOAD = 'reld', - CLEAR_HISTORY = 'clhs', + GO_BACK = 'goba', + GO_FORWARD = 'gofo', + STOP = 'stop', + GOTO_URL = 'goul', + RELOAD = 'reld', + CLEAR_HISTORY = 'clhs', - TEXT_SIZE_INCREASE = 'tsin', - TEXT_SIZE_DECREASE = 'tsdc', - TEXT_SIZE_RESET = 'tsrs', + TEXT_SIZE_INCREASE = 'tsin', + TEXT_SIZE_DECREASE = 'tsdc', + TEXT_SIZE_RESET = 'tsrs', - TEXT_SHOW_FIND_GROUP = 'sfnd', - TEXT_HIDE_FIND_GROUP = 'hfnd', - TEXT_FIND_NEXT = 'fndn', - TEXT_FIND_PREVIOUS = 'fndp', + TEXT_SHOW_FIND_GROUP = 'sfnd', + TEXT_HIDE_FIND_GROUP = 'hfnd', + TEXT_FIND_NEXT = 'fndn', + TEXT_FIND_PREVIOUS = 'fndp', }; -using namespace WebCore; -static BLayoutItem* layoutItemFor(BView* view) +static BLayoutItem* +layoutItemFor(BView* view) { - BLayout* layout = view->Parent()->GetLayout(); - int32 index = layout->IndexOfView(view); - return layout->ItemAt(index); + BLayout* layout = view->Parent()->GetLayout(); + int32 index = layout->IndexOfView(view); + return layout->ItemAt(index); } -LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener, - ToolbarPolicy toolbarPolicy) - : BWebWindow(frame, "HaikuLauncher", - B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS) - , m_downloadListener(downloadListener) + +BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener, + ToolbarPolicy toolbarPolicy) + : BWebWindow(frame, kApplicationName, + B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS) + , fDownloadListener(downloadListener) { - BMessage* newTabMessage = new BMessage(NEW_TAB); - newTabMessage->AddString("url", ""); - newTabMessage->AddPointer("window", this); - newTabMessage->AddBool("select", true); - m_tabManager = new TabManager(BMessenger(this), newTabMessage); + BMessage* newTabMessage = new BMessage(NEW_TAB); + newTabMessage->AddString("url", ""); + newTabMessage->AddPointer("window", this); + newTabMessage->AddBool("select", true); + fTabManager = new TabManager(BMessenger(this), newTabMessage); - if (toolbarPolicy == HaveToolbar) { - // Menu - m_menuBar = new BMenuBar("Main menu"); - BMenu* menu = new BMenu("Window"); - BMessage* newWindowMessage = new BMessage(NEW_WINDOW); - newWindowMessage->AddString("url", ""); - BMenuItem* newItem = new BMenuItem("New window", newWindowMessage, 'N'); - menu->AddItem(newItem); - newItem->SetTarget(be_app); - newItem = new BMenuItem("New tab", new BMessage(*newTabMessage), 'T'); - menu->AddItem(newItem); - newItem->SetTarget(be_app); - menu->AddItem(new BMenuItem("Open location", new BMessage(OPEN_LOCATION), 'L')); - menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("Close window", new BMessage(B_QUIT_REQUESTED), 'W', B_SHIFT_KEY)); - menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W')); - menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("Show downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'J')); - menu->AddSeparatorItem(); - BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); - menu->AddItem(quitItem); - quitItem->SetTarget(be_app); - m_menuBar->AddItem(menu); + if (toolbarPolicy == HaveToolbar) { + // Menu + fMenuBar = new BMenuBar("Main menu"); + BMenu* menu = new BMenu("Window"); + BMessage* newWindowMessage = new BMessage(NEW_WINDOW); + newWindowMessage->AddString("url", ""); + BMenuItem* newItem = new BMenuItem("New window", newWindowMessage, 'N'); + menu->AddItem(newItem); + newItem->SetTarget(be_app); + newItem = new BMenuItem("New tab", new BMessage(*newTabMessage), 'T'); + menu->AddItem(newItem); + newItem->SetTarget(be_app); + menu->AddItem(new BMenuItem("Open location", new BMessage(OPEN_LOCATION), 'L')); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Close window", new BMessage(B_QUIT_REQUESTED), 'W', B_SHIFT_KEY)); + menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W')); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Show downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'J')); + menu->AddSeparatorItem(); + BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); + menu->AddItem(quitItem); + quitItem->SetTarget(be_app); + fMenuBar->AddItem(menu); - menu = new BMenu("Text"); - menu->AddItem(new BMenuItem("Find", new BMessage(TEXT_SHOW_FIND_GROUP), 'F')); - menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("Increase size", new BMessage(TEXT_SIZE_INCREASE), '+')); - menu->AddItem(new BMenuItem("Decrease size", new BMessage(TEXT_SIZE_DECREASE), '-')); - menu->AddItem(new BMenuItem("Reset size", new BMessage(TEXT_SIZE_RESET), '0')); - m_menuBar->AddItem(menu); + menu = new BMenu("Text"); + menu->AddItem(new BMenuItem("Find", new BMessage(TEXT_SHOW_FIND_GROUP), 'F')); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Increase size", new BMessage(TEXT_SIZE_INCREASE), '+')); + menu->AddItem(new BMenuItem("Decrease size", new BMessage(TEXT_SIZE_DECREASE), '-')); + menu->AddItem(new BMenuItem("Reset size", new BMessage(TEXT_SIZE_RESET), '0')); + fMenuBar->AddItem(menu); - m_goMenu = new BMenu("Go"); - m_menuBar->AddItem(m_goMenu); + fGoMenu = new BMenu("Go"); + fMenuBar->AddItem(fGoMenu); - // Back, Forward & Stop - m_BackButton = new IconButton("Back", 0, NULL, new BMessage(GO_BACK)); - m_BackButton->SetIcon(201); - m_BackButton->TrimIcon(); + // Back, Forward & Stop + fBackButton = new IconButton("Back", 0, NULL, new BMessage(GO_BACK)); + fBackButton->SetIcon(201); + fBackButton->TrimIcon(); - m_ForwardButton = new IconButton("Forward", 0, NULL, new BMessage(GO_FORWARD)); - m_ForwardButton->SetIcon(202); - m_ForwardButton->TrimIcon(); + fForwardButton = new IconButton("Forward", 0, NULL, new BMessage(GO_FORWARD)); + fForwardButton->SetIcon(202); + fForwardButton->TrimIcon(); - m_StopButton = new IconButton("Stop", 0, NULL, new BMessage(STOP)); - m_StopButton->SetIcon(204); - m_StopButton->TrimIcon(); + fStopButton = new IconButton("Stop", 0, NULL, new BMessage(STOP)); + fStopButton->SetIcon(204); + fStopButton->TrimIcon(); - // URL - m_url = new BTextControl("url", "", "", NULL); - m_url->SetDivider(50.0); + // URL + fURLTextControl = new BTextControl("url", "", "", NULL); + fURLTextControl->SetDivider(50.0); - // Go - m_goButton = new BButton("", "Go", new BMessage(GOTO_URL)); + // Go + fGoButton = new BButton("", "Go", new BMessage(GOTO_URL)); - // Status Bar - m_statusText = new BStringView("status", ""); - m_statusText->SetAlignment(B_ALIGN_LEFT); - m_statusText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); - m_statusText->SetExplicitMinSize(BSize(150, 12)); - // Prevent the window from growing to fit a long status message... - BFont font(be_plain_font); - font.SetSize(ceilf(font.Size() * 0.8)); - m_statusText->SetFont(&font, B_FONT_SIZE); + // Status Bar + fStatusText = new BStringView("status", ""); + fStatusText->SetAlignment(B_ALIGN_LEFT); + fStatusText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + fStatusText->SetExplicitMinSize(BSize(150, 12)); + // Prevent the window from growing to fit a long status message... + BFont font(be_plain_font); + font.SetSize(ceilf(font.Size() * 0.8)); + fStatusText->SetFont(&font, B_FONT_SIZE); - // Loading progress bar - m_loadingProgressBar = new BStatusBar("progress"); - m_loadingProgressBar->SetMaxValue(100); - m_loadingProgressBar->Hide(); - m_loadingProgressBar->SetBarHeight(12); + // Loading progress bar + fLoadingProgressBar = new BStatusBar("progress"); + fLoadingProgressBar->SetMaxValue(100); + fLoadingProgressBar->Hide(); + fLoadingProgressBar->SetBarHeight(12); - const float kInsetSpacing = 5; - const float kElementSpacing = 7; + const float kInsetSpacing = 5; + const float kElementSpacing = 7; - m_findTextControl = new BTextControl("find", "Find:", "", - new BMessage(TEXT_FIND_NEXT)); - m_findCaseSensitiveCheckBox = new BCheckBox("Match case"); - BView* findGroup = BGroupLayoutBuilder(B_VERTICAL) - .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) - .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) - .Add(m_findTextControl) - .Add(new BButton("Previous", new BMessage(TEXT_FIND_PREVIOUS))) - .Add(new BButton("Next", new BMessage(TEXT_FIND_NEXT))) - .Add(m_findCaseSensitiveCheckBox) - .Add(BSpaceLayoutItem::CreateGlue()) - .Add(new BButton("Close", new BMessage(TEXT_HIDE_FIND_GROUP))) - .SetInsets(kInsetSpacing, kInsetSpacing, - kInsetSpacing, kInsetSpacing) - ) - ; - // Layout - AddChild(BGroupLayoutBuilder(B_VERTICAL) - .Add(m_menuBar) - .Add(m_tabManager->TabGroup()) - .Add(BGridLayoutBuilder(kElementSpacing, kElementSpacing) - .Add(m_BackButton, 0, 0) - .Add(m_ForwardButton, 1, 0) - .Add(m_StopButton, 2, 0) - .Add(m_url, 3, 0) - .Add(m_goButton, 4, 0) - .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing) - ) - .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) - .Add(m_tabManager->ContainerView()) - .Add(findGroup) - .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) - .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) - .Add(m_statusText) - .Add(m_loadingProgressBar, 0.2) - .AddStrut(12 - kElementSpacing) - .SetInsets(kInsetSpacing, 0, kInsetSpacing, 0) - ) - ); + fFindTextControl = new BTextControl("find", "Find:", "", + new BMessage(TEXT_FIND_NEXT)); + fFindCaseSensitiveCheckBox = new BCheckBox("Match case"); + BView* findGroup = BGroupLayoutBuilder(B_VERTICAL) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) + .Add(fFindTextControl) + .Add(new BButton("Previous", new BMessage(TEXT_FIND_PREVIOUS))) + .Add(new BButton("Next", new BMessage(TEXT_FIND_NEXT))) + .Add(fFindCaseSensitiveCheckBox) + .Add(BSpaceLayoutItem::CreateGlue()) + .Add(new BButton("Close", new BMessage(TEXT_HIDE_FIND_GROUP))) + .SetInsets(kInsetSpacing, kInsetSpacing, + kInsetSpacing, kInsetSpacing) + ) + ; + // Layout + AddChild(BGroupLayoutBuilder(B_VERTICAL) + .Add(fMenuBar) + .Add(fTabManager->TabGroup()) + .Add(BGridLayoutBuilder(kElementSpacing, kElementSpacing) + .Add(fBackButton, 0, 0) + .Add(fForwardButton, 1, 0) + .Add(fStopButton, 2, 0) + .Add(fURLTextControl, 3, 0) + .Add(fGoButton, 4, 0) + .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing) + ) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .Add(fTabManager->ContainerView()) + .Add(findGroup) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) + .Add(fStatusText) + .Add(fLoadingProgressBar, 0.2) + .AddStrut(12 - kElementSpacing) + .SetInsets(kInsetSpacing, 0, kInsetSpacing, 0) + ) + ); - m_url->MakeFocus(true); + fURLTextControl->MakeFocus(true); - m_findGroup = layoutItemFor(findGroup); - m_tabGroup = layoutItemFor(m_tabManager->TabGroup()); - } else { - m_BackButton = 0; - m_ForwardButton = 0; - m_StopButton = 0; - m_goButton = 0; - m_url = 0; - m_menuBar = 0; - m_statusText = 0; - m_loadingProgressBar = 0; + fFindGroup = layoutItemFor(findGroup); + fTabGroup = layoutItemFor(fTabManager->TabGroup()); + } else { + fBackButton = 0; + fForwardButton = 0; + fStopButton = 0; + fGoButton = 0; + fURLTextControl = 0; + fMenuBar = 0; + fStatusText = 0; + fLoadingProgressBar = 0; - BWebView* webView = new BWebView("web_view"); - SetCurrentWebView(webView); + BWebView* webView = new BWebView("web_view"); + SetCurrentWebView(webView); - AddChild(BGroupLayoutBuilder(B_VERTICAL, 7) - .Add(CurrentWebView()) - ); - } + AddChild(BGroupLayoutBuilder(B_VERTICAL, 7) + .Add(CurrentWebView()) + ); + } - newTab("", true); + CreateNewTab("", true); - m_findGroup->SetVisible(false); + fFindGroup->SetVisible(false); - AddShortcut('G', B_COMMAND_KEY, new BMessage(TEXT_FIND_NEXT)); - AddShortcut('G', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(TEXT_FIND_PREVIOUS)); - 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('R', B_COMMAND_KEY, new BMessage(RELOAD)); + AddShortcut('G', B_COMMAND_KEY, new BMessage(TEXT_FIND_NEXT)); + AddShortcut('G', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(TEXT_FIND_PREVIOUS)); + 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('R', B_COMMAND_KEY, new BMessage(RELOAD)); - be_app->PostMessage(WINDOW_OPENED); + be_app->PostMessage(WINDOW_OPENED); } -LauncherWindow::~LauncherWindow() + +BrowserWindow::~BrowserWindow() { } -void LauncherWindow::DispatchMessage(BMessage* message, BHandler* target) + +void +BrowserWindow::DispatchMessage(BMessage* message, BHandler* target) { - if (m_url && message->what == B_KEY_DOWN && target == m_url->TextView()) { + if (fURLTextControl && message->what == B_KEY_DOWN + && target == fURLTextControl->TextView()) { // Handle B_RETURN in the URL text control. This is the easiest // way to react *only* when the user presses the return key in the // address bar, as opposed to trying to load whatever is in there when // the text control just goes out of focus. - const char* bytes; - if (message->FindString("bytes", &bytes) == B_OK - && bytes[0] == B_RETURN) { - // Do it in such a way that the user sees the Go-button go down. - m_goButton->SetValue(B_CONTROL_ON); - UpdateIfNeeded(); - m_goButton->Invoke(); - snooze(1000); - m_goButton->SetValue(B_CONTROL_OFF); - } + const char* bytes; + if (message->FindString("bytes", &bytes) == B_OK + && bytes[0] == B_RETURN) { + // Do it in such a way that the user sees the Go-button go down. + fGoButton->SetValue(B_CONTROL_ON); + UpdateIfNeeded(); + fGoButton->Invoke(); + snooze(1000); + fGoButton->SetValue(B_CONTROL_OFF); + } } BWebWindow::DispatchMessage(message, target); } -void LauncherWindow::MessageReceived(BMessage* message) + +void +BrowserWindow::MessageReceived(BMessage* message) { - switch (message->what) { - case OPEN_LOCATION: - if (m_url) { - if (m_url->TextView()->IsFocus()) - m_url->TextView()->SelectAll(); - else - m_url->MakeFocus(true); - } - break; - case RELOAD: - CurrentWebView()->Reload(); - break; - case GOTO_URL: { - BString url; - if (message->FindString("url", &url) != B_OK) - url = m_url->Text(); - CurrentWebView()->LoadURL(url.String()); - break; - } - case GO_BACK: - CurrentWebView()->GoBack(); - break; - case GO_FORWARD: - CurrentWebView()->GoForward(); - break; - case STOP: - CurrentWebView()->StopLoading(); - break; + switch (message->what) { + case OPEN_LOCATION: + if (fURLTextControl) { + if (fURLTextControl->TextView()->IsFocus()) + fURLTextControl->TextView()->SelectAll(); + else + fURLTextControl->MakeFocus(true); + } + break; + case RELOAD: + CurrentWebView()->Reload(); + break; + case GOTO_URL: { + BString url; + if (message->FindString("url", &url) != B_OK) + url = fURLTextControl->Text(); + CurrentWebView()->LoadURL(url.String()); + break; + } + case GO_BACK: + CurrentWebView()->GoBack(); + break; + case GO_FORWARD: + CurrentWebView()->GoForward(); + break; + case STOP: + CurrentWebView()->StopLoading(); + break; - case CLEAR_HISTORY: { - BrowsingHistory* history = BrowsingHistory::defaultInstance(); - if (history->countItems() == 0) - break; - BAlert* alert = new BAlert("Confirmation", "Do you really want to clear " - "the browsing history?", "Clear", "Cancel"); - if (alert->Go() == 0) - history->clear(); - break; - } + case CLEAR_HISTORY: { + BrowsingHistory* history = BrowsingHistory::defaultInstance(); + if (history->countItems() == 0) + break; + BAlert* alert = new BAlert("Confirmation", "Do you really want to " + "clear the browsing history?", "Clear", "Cancel"); + if (alert->Go() == 0) + history->clear(); + break; + } - case B_SIMPLE_DATA: { - // User possibly dropped files on this window. - // If there is more than one entry_ref, let the app handle it (open one - // new page per ref). If there is one ref, open it in this window. - type_code type; - int32 countFound; - if (message->GetInfo("refs", &type, &countFound) != B_OK - || type != B_REF_TYPE) { - break; - } - if (countFound > 1) { - message->what = B_REFS_RECEIVED; - be_app->PostMessage(message); - break; - } - entry_ref ref; - if (message->FindRef("refs", &ref) != B_OK) - break; - BEntry entry(&ref, true); - BPath path; - if (!entry.Exists() || entry.GetPath(&path) != B_OK) - break; - CurrentWebView()->LoadURL(path.Path()); - break; - } + case B_SIMPLE_DATA: { + // User possibly dropped files on this window. + // If there is more than one entry_ref, let the app handle it (open one + // new page per ref). If there is one ref, open it in this window. + type_code type; + int32 countFound; + if (message->GetInfo("refs", &type, &countFound) != B_OK + || type != B_REF_TYPE) { + break; + } + if (countFound > 1) { + message->what = B_REFS_RECEIVED; + be_app->PostMessage(message); + break; + } + entry_ref ref; + if (message->FindRef("refs", &ref) != B_OK) + break; + BEntry entry(&ref, true); + BPath path; + if (!entry.Exists() || entry.GetPath(&path) != B_OK) + break; + CurrentWebView()->LoadURL(path.Path()); + break; + } - case TEXT_SIZE_INCREASE: - CurrentWebView()->IncreaseTextSize(); - break; - case TEXT_SIZE_DECREASE: - CurrentWebView()->DecreaseTextSize(); - break; - case TEXT_SIZE_RESET: - CurrentWebView()->ResetTextSize(); - break; + case TEXT_SIZE_INCREASE: + CurrentWebView()->IncreaseTextSize(); + break; + case TEXT_SIZE_DECREASE: + CurrentWebView()->DecreaseTextSize(); + break; + case TEXT_SIZE_RESET: + CurrentWebView()->ResetTextSize(); + break; - case TEXT_FIND_NEXT: - CurrentWebView()->FindString(m_findTextControl->Text(), true, - m_findCaseSensitiveCheckBox->Value()); - break; - case TEXT_FIND_PREVIOUS: - CurrentWebView()->FindString(m_findTextControl->Text(), false, - m_findCaseSensitiveCheckBox->Value()); - break; - case TEXT_SHOW_FIND_GROUP: - if (!m_findGroup->IsVisible()) - m_findGroup->SetVisible(true); - m_findTextControl->MakeFocus(true); - break; - case TEXT_HIDE_FIND_GROUP: - if (m_findGroup->IsVisible()) - m_findGroup->SetVisible(false); - break; + case TEXT_FIND_NEXT: + CurrentWebView()->FindString(fFindTextControl->Text(), true, + fFindCaseSensitiveCheckBox->Value()); + break; + case TEXT_FIND_PREVIOUS: + CurrentWebView()->FindString(fFindTextControl->Text(), false, + fFindCaseSensitiveCheckBox->Value()); + break; + case TEXT_SHOW_FIND_GROUP: + if (!fFindGroup->IsVisible()) + fFindGroup->SetVisible(true); + fFindTextControl->MakeFocus(true); + break; + case TEXT_HIDE_FIND_GROUP: + if (fFindGroup->IsVisible()) + fFindGroup->SetVisible(false); + break; - case SHOW_DOWNLOAD_WINDOW: - message->AddUInt32("workspaces", Workspaces()); - be_app->PostMessage(message); - break; + case SHOW_DOWNLOAD_WINDOW: + message->AddUInt32("workspaces", Workspaces()); + be_app->PostMessage(message); + break; - case CLOSE_TAB: - if (m_tabManager->CountTabs() > 1) { - int32 index; - if (message->FindInt32("tab index", &index) != B_OK) - index = m_tabManager->SelectedTabIndex(); - delete m_tabManager->RemoveTab(index); - updateTabGroupVisibility(); - } else - PostMessage(B_QUIT_REQUESTED); - break; + case CLOSE_TAB: + if (fTabManager->CountTabs() > 1) { + int32 index; + if (message->FindInt32("tab index", &index) != B_OK) + index = fTabManager->SelectedTabIndex(); + delete fTabManager->RemoveTab(index); + _UpdateTabGroupVisibility(); + } else + PostMessage(B_QUIT_REQUESTED); + break; - case TAB_CHANGED: { - // This message may be received also when the last tab closed, i.e. with index == -1. - int32 index; - if (message->FindInt32("tab index", &index) != B_OK) - index = -1; - BWebView* webView = dynamic_cast(m_tabManager->ViewForTab(index)); - if (webView == CurrentWebView()) - break; - SetCurrentWebView(webView); - if (webView) - updateTitle(webView->MainFrameTitle()); - else - updateTitle(""); - if (webView) { - m_url->SetText(webView->MainFrameURL()); - // Trigger update of the interface to the new page, by requesting - // to resend all notifications. - webView->WebPage()->ResendNotifications(); - } - break; - } + case TAB_CHANGED: { + // This message may be received also when the last tab closed, i.e. with index == -1. + int32 index; + if (message->FindInt32("tab index", &index) != B_OK) + index = -1; + BWebView* webView = dynamic_cast(fTabManager->ViewForTab(index)); + if (webView == CurrentWebView()) + break; + SetCurrentWebView(webView); + if (webView) + _UpdateTitle(webView->MainFrameTitle()); + else + _UpdateTitle(""); + if (webView) { + fURLTextControl->SetText(webView->MainFrameURL()); + // Trigger update of the interface to the new page, by requesting + // to resend all notifications. + webView->WebPage()->ResendNotifications(); + } + break; + } - default: - BWebWindow::MessageReceived(message); - break; - } + default: + BWebWindow::MessageReceived(message); + break; + } } -bool LauncherWindow::QuitRequested() + +bool +BrowserWindow::QuitRequested() { - // TODO: Check for modified form data and ask user for confirmation, etc. + // TODO: Check for modified form data and ask user for confirmation, etc. - // Iterate over all tabs to delete all BWebViews. - // Do this here, so WebKit tear down happens earlier. - while (m_tabManager->CountTabs() > 0) - delete m_tabManager->RemoveTab(0L); - SetCurrentWebView(0); + // Iterate over all tabs to delete all BWebViews. + // Do this here, so WebKit tear down happens earlier. + while (fTabManager->CountTabs() > 0) + delete fTabManager->RemoveTab(0L); + SetCurrentWebView(0); - BMessage message(WINDOW_CLOSED); - message.AddRect("window frame", Frame()); - be_app->PostMessage(&message); - return true; + BMessage message(WINDOW_CLOSED); + message.AddRect("window frame", Frame()); + be_app->PostMessage(&message); + return true; } -void LauncherWindow::MenusBeginning() + +void +BrowserWindow::MenusBeginning() { - BMenuItem* menuItem; - while ((menuItem = m_goMenu->RemoveItem(0L))) - delete menuItem; + BMenuItem* menuItem; + while ((menuItem = fGoMenu->RemoveItem(0L))) + delete menuItem; - BrowsingHistory* history = BrowsingHistory::defaultInstance(); - if (!history->Lock()) - return; + BrowsingHistory* history = BrowsingHistory::defaultInstance(); + if (!history->Lock()) + return; - int32 count = history->countItems(); - for (int32 i = 0; i < count; i++) { - BrowsingHistoryItem historyItem = history->historyItemAt(i); - BMessage* message = new BMessage(GOTO_URL); - message->AddString("url", historyItem.url().String()); - // TODO: More sophisticated menu structure... sorted by days/weeks... - BString truncatedUrl(historyItem.url()); - be_plain_font->TruncateString(&truncatedUrl, B_TRUNCATE_END, 480); - menuItem = new BMenuItem(truncatedUrl, message); - m_goMenu->AddItem(menuItem); - } + int32 count = history->countItems(); + for (int32 i = 0; i < count; i++) { + BrowsingHistoryItem historyItem = history->historyItemAt(i); + BMessage* message = new BMessage(GOTO_URL); + message->AddString("url", historyItem.url().String()); + // TODO: More sophisticated menu structure... sorted by days/weeks... + BString truncatedUrl(historyItem.url()); + be_plain_font->TruncateString(&truncatedUrl, B_TRUNCATE_END, 480); + menuItem = new BMenuItem(truncatedUrl, message); + fGoMenu->AddItem(menuItem); + } - if (m_goMenu->CountItems() > 3) { - m_goMenu->AddSeparatorItem(); - m_goMenu->AddItem(new BMenuItem("Clear history", new BMessage(CLEAR_HISTORY))); - } + if (fGoMenu->CountItems() > 3) { + fGoMenu->AddSeparatorItem(); + fGoMenu->AddItem(new BMenuItem("Clear history", + new BMessage(CLEAR_HISTORY))); + } - history->Unlock(); + history->Unlock(); } -void LauncherWindow::newTab(const BString& url, bool select, BWebView* webView) + +void +BrowserWindow::CreateNewTab(const BString& url, bool select, BWebView* webView) { - // Executed in app thread (new BWebPage needs to be created in app thread). - if (!webView) - webView = new BWebView("web view"); - webView->WebPage()->SetDownloadListener(m_downloadListener); + // Executed in app thread (new BWebPage needs to be created in app thread). + if (!webView) + webView = new BWebView("web view"); + webView->WebPage()->SetDownloadListener(fDownloadListener); - m_tabManager->AddTab(webView, "New tab"); + fTabManager->AddTab(webView, "New tab"); - if (url.Length()) - webView->LoadURL(url.String()); + if (url.Length()) + webView->LoadURL(url.String()); - if (select) { - m_tabManager->SelectTab(m_tabManager->CountTabs() - 1); - SetCurrentWebView(webView); - NavigationCapabilitiesChanged(false, false, false, webView); - if (m_url) { - m_url->SetText(url.String()); - m_url->MakeFocus(true); - } - } + if (select) { + fTabManager->SelectTab(fTabManager->CountTabs() - 1); + SetCurrentWebView(webView); + NavigationCapabilitiesChanged(false, false, false, webView); + if (fURLTextControl) { + fURLTextControl->SetText(url.String()); + fURLTextControl->MakeFocus(true); + } + } - updateTabGroupVisibility(); + _UpdateTabGroupVisibility(); } + // #pragma mark - Notification API -void LauncherWindow::NavigationRequested(const BString& url, BWebView* view) + +void +BrowserWindow::NavigationRequested(const BString& url, BWebView* view) { } -void LauncherWindow::NewWindowRequested(const BString& url, bool primaryAction) + +void +BrowserWindow::NewWindowRequested(const BString& url, bool primaryAction) { - // Always open new windows in the application thread, since - // creating a BWebView will try to grab the application lock. - // But our own WebPage may already try to lock us from within - // the application thread -> dead-lock. Thus we can't wait for - // a reply here. - BMessage message(NEW_TAB); - message.AddPointer("window", this); - message.AddString("url", url); - message.AddBool("select", primaryAction); - be_app->PostMessage(&message); + // Always open new windows in the application thread, since + // creating a BWebView will try to grab the application lock. + // But our own WebPage may already try to lock us from within + // the application thread -> dead-lock. Thus we can't wait for + // a reply here. + BMessage message(NEW_TAB); + message.AddPointer("window", this); + message.AddString("url", url); + message.AddBool("select", primaryAction); + be_app->PostMessage(&message); } -void LauncherWindow::NewPageCreated(BWebView* view) + +void +BrowserWindow::NewPageCreated(BWebView* view) { - newTab(BString(), true, view); + CreateNewTab(BString(), true, view); } -void LauncherWindow::LoadNegotiating(const BString& url, BWebView* view) + +void +BrowserWindow::LoadNegotiating(const BString& url, BWebView* view) { - BString status("Requesting: "); - status << url; - StatusChanged(status, view); + BString status("Requesting: "); + status << url; + StatusChanged(status, view); } -void LauncherWindow::LoadCommitted(const BString& url, BWebView* view) + +void +BrowserWindow::LoadCommitted(const BString& url, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) + return; // This hook is invoked when the load is commited. - if (m_url) - m_url->SetText(url.String()); + if (fURLTextControl) + fURLTextControl->SetText(url.String()); - BString status("Loading: "); - status << url; - StatusChanged(status, view); + BString status("Loading: "); + status << url; + StatusChanged(status, view); } -void LauncherWindow::LoadProgress(float progress, BWebView* view) + +void +BrowserWindow::LoadProgress(float progress, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) + return; - if (m_loadingProgressBar) { - if (progress < 100 && m_loadingProgressBar->IsHidden()) - m_loadingProgressBar->Show(); - m_loadingProgressBar->SetTo(progress); - } + if (fLoadingProgressBar) { + if (progress < 100 && fLoadingProgressBar->IsHidden()) + fLoadingProgressBar->Show(); + fLoadingProgressBar->SetTo(progress); + } } -void LauncherWindow::LoadFailed(const BString& url, BWebView* view) + +void +BrowserWindow::LoadFailed(const BString& url, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) + return; - BString status(url); - status << " failed."; - StatusChanged(status, view); - if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden()) - m_loadingProgressBar->Hide(); + BString status(url); + status << " failed."; + StatusChanged(status, view); + if (fLoadingProgressBar && !fLoadingProgressBar->IsHidden()) + fLoadingProgressBar->Hide(); } -void LauncherWindow::LoadFinished(const BString& url, BWebView* view) + +void +BrowserWindow::LoadFinished(const BString& url, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) + return; - BString status(url); - status << " finished."; - StatusChanged(status, view); - if (m_loadingProgressBar && !m_loadingProgressBar->IsHidden()) - m_loadingProgressBar->Hide(); + BString status(url); + status << " finished."; + StatusChanged(status, view); + if (fLoadingProgressBar && !fLoadingProgressBar->IsHidden()) + fLoadingProgressBar->Hide(); - NavigationCapabilitiesChanged(m_BackButton->IsEnabled(), - m_ForwardButton->IsEnabled(), false, view); + NavigationCapabilitiesChanged(fBackButton->IsEnabled(), + fForwardButton->IsEnabled(), false, view); } -void LauncherWindow::ResizeRequested(float width, float height, BWebView* view) + +void +BrowserWindow::ResizeRequested(float width, float height, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) + return; - // TODO: Ignore request when there is more than one BWebView embedded! + // TODO: Ignore request when there is more than one BWebView embedded! - ResizeTo(width, height); + ResizeTo(width, height); } -void LauncherWindow::SetToolBarsVisible(bool flag, BWebView* view) + +void +BrowserWindow::SetToolBarsVisible(bool flag, BWebView* view) { - // TODO - // TODO: Ignore request when there is more than one BWebView embedded! + // TODO + // TODO: Ignore request when there is more than one BWebView embedded! } -void LauncherWindow::SetStatusBarVisible(bool flag, BWebView* view) + +void +BrowserWindow::SetStatusBarVisible(bool flag, BWebView* view) { - // TODO - // TODO: Ignore request when there is more than one BWebView embedded! + // TODO + // TODO: Ignore request when there is more than one BWebView embedded! } -void LauncherWindow::SetMenuBarVisible(bool flag, BWebView* view) + +void +BrowserWindow::SetMenuBarVisible(bool flag, BWebView* view) { - // TODO - // TODO: Ignore request when there is more than one BWebView embedded! + // TODO + // TODO: Ignore request when there is more than one BWebView embedded! } -void LauncherWindow::SetResizable(bool flag, BWebView* view) + +void +BrowserWindow::SetResizable(bool flag, BWebView* view) { - // TODO: Ignore request when there is more than one BWebView embedded! + // TODO: Ignore request when there is more than one BWebView embedded! - if (flag) - SetFlags(Flags() & ~B_NOT_RESIZABLE); - else - SetFlags(Flags() | B_NOT_RESIZABLE); + if (flag) + SetFlags(Flags() & ~B_NOT_RESIZABLE); + else + SetFlags(Flags() | B_NOT_RESIZABLE); } -void LauncherWindow::TitleChanged(const BString& title, BWebView* view) + +void +BrowserWindow::TitleChanged(const BString& title, BWebView* view) { - for (int32 i = 0; i < m_tabManager->CountTabs(); i++) { - if (m_tabManager->ViewForTab(i) == view) { - m_tabManager->SetTabLabel(i, title); - break; - } - } - if (view != CurrentWebView()) - return; + for (int32 i = 0; i < fTabManager->CountTabs(); i++) { + if (fTabManager->ViewForTab(i) == view) { + fTabManager->SetTabLabel(i, title); + break; + } + } + if (view != CurrentWebView()) + return; - updateTitle(title); + _UpdateTitle(title); } -void LauncherWindow::StatusChanged(const BString& statusText, BWebView* view) + +void +BrowserWindow::StatusChanged(const BString& statusText, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) + return; - if (m_statusText) - m_statusText->SetText(statusText.String()); + if (fStatusText) + fStatusText->SetText(statusText.String()); } -void LauncherWindow::NavigationCapabilitiesChanged(bool canGoBackward, - bool canGoForward, bool canStop, BWebView* view) + +void +BrowserWindow::NavigationCapabilitiesChanged(bool canGoBackward, + bool canGoForward, bool canStop, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) + return; - if (m_BackButton) - m_BackButton->SetEnabled(canGoBackward); - if (m_ForwardButton) - m_ForwardButton->SetEnabled(canGoForward); - if (m_StopButton) - m_StopButton->SetEnabled(canStop); + if (fBackButton) + fBackButton->SetEnabled(canGoBackward); + if (fForwardButton) + fForwardButton->SetEnabled(canGoForward); + if (fStopButton) + fStopButton->SetEnabled(canStop); } -void LauncherWindow::UpdateGlobalHistory(const BString& url) + +void +BrowserWindow::UpdateGlobalHistory(const BString& url) { - BrowsingHistory::defaultInstance()->addItem(BrowsingHistoryItem(url)); + BrowsingHistory::defaultInstance()->addItem(BrowsingHistoryItem(url)); } -bool LauncherWindow::AuthenticationChallenge(BString message, BString& inOutUser, + +bool +BrowserWindow::AuthenticationChallenge(BString message, BString& inOutUser, BString& inOutPassword, bool& inOutRememberCredentials, uint32 failureCount, BWebView* view) { // Switch to the page for which this authentication is required. if (view != CurrentWebView()) { - m_tabManager->SelectTab(view); + fTabManager->SelectTab(view); UpdateIfNeeded(); } - AuthenticationPanel* panel = new AuthenticationPanel(Frame()); - // Panel auto-destructs. - return panel->getAuthentication(message, inOutUser, inOutPassword, - inOutRememberCredentials, failureCount > 0, inOutUser, inOutPassword, - &inOutRememberCredentials); + AuthenticationPanel* panel = new AuthenticationPanel(Frame()); + // Panel auto-destructs. + return panel->getAuthentication(message, inOutUser, inOutPassword, + inOutRememberCredentials, failureCount > 0, inOutUser, inOutPassword, + &inOutRememberCredentials); } -void LauncherWindow::updateTitle(const BString& title) + +// #pragma mark - private + + +void +BrowserWindow::_UpdateTitle(const BString& title) { - BString windowTitle = title; - if (windowTitle.Length() > 0) - windowTitle << " - "; - windowTitle << "HaikuLauncher"; - SetTitle(windowTitle.String()); + BString windowTitle = title; + if (windowTitle.Length() > 0) + windowTitle << " - "; + windowTitle << kApplicationName; + SetTitle(windowTitle.String()); } -void LauncherWindow::updateTabGroupVisibility() + +void +BrowserWindow::_UpdateTabGroupVisibility() { if (Lock()) { - //m_tabGroup->SetVisible(m_tabManager->CountTabs() > 1); - m_tabManager->SetCloseButtonsAvailable(m_tabManager->CountTabs() > 1); - Unlock(); + //fTabGroup->SetVisible(fTabManager->CountTabs() > 1); + fTabManager->SetCloseButtonsAvailable(fTabManager->CountTabs() > 1); + Unlock(); } } diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index 018ac29a16..c646a4ab59 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -26,9 +26,9 @@ * (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 BROWSER_WINDOW_H +#define BROWSER_WINDOW_H -#ifndef LauncherWindow_h -#define LauncherWindow_h #include "WebWindow.h" #include @@ -46,75 +46,91 @@ class TabManager; class BWebView; enum ToolbarPolicy { - HaveToolbar, - DoNotHaveToolbar + HaveToolbar, + DoNotHaveToolbar }; enum { - NEW_WINDOW = 'nwnd', - NEW_TAB = 'ntab', - WINDOW_OPENED = 'wndo', - WINDOW_CLOSED = 'wndc', - SHOW_DOWNLOAD_WINDOW = 'sdwd' + NEW_WINDOW = 'nwnd', + NEW_TAB = 'ntab', + WINDOW_OPENED = 'wndo', + WINDOW_CLOSED = 'wndc', + SHOW_DOWNLOAD_WINDOW = 'sdwd' }; -class LauncherWindow : public BWebWindow { + +class BrowserWindow : public BWebWindow { public: - LauncherWindow(BRect frame, const BMessenger& downloadListener, - ToolbarPolicy = HaveToolbar); - virtual ~LauncherWindow(); + BrowserWindow(BRect frame, + const BMessenger& downloadListener, + ToolbarPolicy = HaveToolbar); + virtual ~BrowserWindow(); - virtual void DispatchMessage(BMessage* message, BHandler* target); - virtual void MessageReceived(BMessage* message); - virtual bool QuitRequested(); - virtual void MenusBeginning(); + virtual void DispatchMessage(BMessage* message, + BHandler* target); + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); + virtual void MenusBeginning(); - void newTab(const BString& url, bool select, BWebView* webView = 0); + void CreateNewTab(const BString& url, bool select, + BWebView* webView = 0); private: - // WebPage notification API implementations - virtual void NavigationRequested(const BString& url, BWebView* view); - virtual void NewWindowRequested(const BString& url, bool primaryAction); - virtual void NewPageCreated(BWebView* view); - virtual void LoadNegotiating(const BString& url, BWebView* view); - virtual void LoadCommitted(const BString& url, BWebView* view); - virtual void LoadProgress(float progress, BWebView* view); - virtual void LoadFailed(const BString& url, BWebView* view); - virtual void LoadFinished(const BString& url, BWebView* view); - virtual void TitleChanged(const BString& title, BWebView* view); - virtual void ResizeRequested(float width, float height, BWebView* view); - virtual void SetToolBarsVisible(bool flag, BWebView* view); - virtual void SetStatusBarVisible(bool flag, BWebView* view); - virtual void SetMenuBarVisible(bool flag, BWebView* view); - virtual void SetResizable(bool flag, BWebView* view); - virtual void StatusChanged(const BString& status, BWebView* view); - virtual void NavigationCapabilitiesChanged(bool canGoBackward, - bool canGoForward, bool canStop, BWebView* view); - virtual void UpdateGlobalHistory(const BString& url); - virtual bool AuthenticationChallenge(BString message, BString& inOutUser, - BString& inOutPassword, bool& inOutRememberCredentials, - uint32 failureCount, BWebView* view); - - void updateTitle(const BString &title); - void updateTabGroupVisibility(); + // WebPage notification API implementations + virtual void NavigationRequested(const BString& url, + BWebView* view); + virtual void NewWindowRequested(const BString& url, + bool primaryAction); + virtual void NewPageCreated(BWebView* view); + virtual void LoadNegotiating(const BString& url, + BWebView* view); + virtual void LoadCommitted(const BString& url, + BWebView* view); + virtual void LoadProgress(float progress, BWebView* view); + virtual void LoadFailed(const BString& url, BWebView* view); + virtual void LoadFinished(const BString& url, + BWebView* view); + virtual void TitleChanged(const BString& title, + BWebView* view); + virtual void ResizeRequested(float width, float height, + BWebView* view); + virtual void SetToolBarsVisible(bool flag, BWebView* view); + virtual void SetStatusBarVisible(bool flag, BWebView* view); + virtual void SetMenuBarVisible(bool flag, BWebView* view); + virtual void SetResizable(bool flag, BWebView* view); + virtual void StatusChanged(const BString& status, + BWebView* view); + virtual void NavigationCapabilitiesChanged( + bool canGoBackward, bool canGoForward, + bool canStop, BWebView* view); + virtual void UpdateGlobalHistory(const BString& url); + virtual bool AuthenticationChallenge(BString message, + BString& inOutUser, BString& inOutPassword, + bool& inOutRememberCredentials, + uint32 failureCount, BWebView* view); private: - BMessenger m_downloadListener; - BMenuBar* m_menuBar; - BMenu* m_goMenu; - IconButton* m_BackButton; - IconButton* m_ForwardButton; - IconButton* m_StopButton; - BButton* m_goButton; - BTextControl* m_url; - BStringView* m_statusText; - BStatusBar* m_loadingProgressBar; - BLayoutItem* m_findGroup; - BLayoutItem* m_tabGroup; - BTextControl* m_findTextControl; - BCheckBox* m_findCaseSensitiveCheckBox; - TabManager* m_tabManager; + void _UpdateTitle(const BString &title); + void _UpdateTabGroupVisibility(); + +private: + BMessenger fDownloadListener; + BMenuBar* fMenuBar; + BMenu* fGoMenu; + IconButton* fBackButton; + IconButton* fForwardButton; + IconButton* fStopButton; + BButton* fGoButton; + BTextControl* fURLTextControl; + BStringView* fStatusText; + BStatusBar* fLoadingProgressBar; + BLayoutItem* fFindGroup; + BLayoutItem* fTabGroup; + BTextControl* fFindTextControl; + BCheckBox* fFindCaseSensitiveCheckBox; + TabManager* fTabManager; }; -#endif // LauncherWindow_h + +#endif // BROWSER_WINDOW_H diff --git a/src/apps/webpositive/BrowsingHistory.cpp b/src/apps/webpositive/BrowsingHistory.cpp index 7c5246df11..e5a7e8afe4 100644 --- a/src/apps/webpositive/BrowsingHistory.cpp +++ b/src/apps/webpositive/BrowsingHistory.cpp @@ -28,6 +28,7 @@ #include "config.h" #include "BrowsingHistory.h" +#include "BrowserApp.h" #include #include #include @@ -262,7 +263,8 @@ bool BrowsingHistory::openSettingsFile(BFile& file, uint32 mode) { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK - || path.Append("HaikuLauncher_BrowsingHistory") != B_OK) { + || path.Append(kApplicationName) != B_OK + || path.Append("BrowsingHistory") != B_OK) { return false; } return file.SetTo(path.Path(), mode) == B_OK; diff --git a/src/apps/webpositive/DownloadWindow.cpp b/src/apps/webpositive/DownloadWindow.cpp index 248e3bde44..fbbe932118 100644 --- a/src/apps/webpositive/DownloadWindow.cpp +++ b/src/apps/webpositive/DownloadWindow.cpp @@ -28,6 +28,7 @@ #include "config.h" #include "DownloadWindow.h" +#include "BrowserApp.h" #include "WebDownload.h" #include "WebPage.h" #include @@ -550,7 +551,8 @@ bool DownloadWindow::openSettingsFile(BFile& file, uint32 mode) { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK - || path.Append("HaikuLauncher_Downloads") != B_OK) { + || path.Append(kApplicationName) != B_OK + || path.Append("Downloads") != B_OK) { return false; } return file.SetTo(path.Path(), mode) == B_OK; diff --git a/src/apps/webpositive/WebPositive.rdef b/src/apps/webpositive/WebPositive.rdef index fee9516509..f741a6a3e9 100644 --- a/src/apps/webpositive/WebPositive.rdef +++ b/src/apps/webpositive/WebPositive.rdef @@ -1,4 +1,4 @@ -resource app_signature "application/x-vnd.RJL-HaikuLauncher"; +resource app_signature "application/x-vnd.Haiku-WebPositive"; resource app_version { major = 0, @@ -6,8 +6,8 @@ resource app_version { minor = 1, variety = B_APPV_ALPHA, internal = 0, - short_info = "HaikuLauncher", - long_info = "HaikuLauncher ©2007-2010 The WebKit Haiku Project" + short_info = "WebPositive", + long_info = "WebPositive ©2007-2010 The WebKit Haiku Project" }; resource app_flags B_SINGLE_LAUNCH;