1 /* 2 * Copyright (C) 2007 Ryan Leavengood <leavengood@gmail.com> 3 * Copyright (C) 2009 Maxime Simon <simon.maxime@gmail.com> 4 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de> 5 * Copyright 2013-2014 Haiku, Inc. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #ifndef BROWSER_WINDOW_H 29 #define BROWSER_WINDOW_H 30 31 32 #include "WebWindow.h" 33 #include <Messenger.h> 34 #include <String.h> 35 36 class BButton; 37 class BCheckBox; 38 class BDirectory; 39 class BFile; 40 class BLayoutItem; 41 class BMenu; 42 class BMenuItem; 43 class BMessageRunner; 44 class BPath; 45 class BStatusBar; 46 class BStringView; 47 class BTextControl; 48 class BUrlContext; 49 class BWebView; 50 51 class BookmarkBar; 52 class SettingsMessage; 53 class TabManager; 54 class URLInputGroup; 55 56 namespace BPrivate { 57 class BIconButton; 58 } 59 60 using BPrivate::BIconButton; 61 62 enum { 63 INTERFACE_ELEMENT_MENU = 1 << 0, 64 INTERFACE_ELEMENT_TABS = 1 << 1, 65 INTERFACE_ELEMENT_NAVIGATION = 1 << 2, 66 INTERFACE_ELEMENT_STATUS = 1 << 3, 67 68 INTERFACE_ELEMENT_ALL = 0xffff 69 }; 70 71 enum NewPagePolicy { 72 OpenBlankPage = 0, 73 OpenStartPage = 1, 74 OpenSearchPage = 2, 75 CloneCurrentPage = 3 76 }; 77 78 enum { 79 NEW_WINDOW = 'nwnd', 80 NEW_TAB = 'ntab', 81 WINDOW_OPENED = 'wndo', 82 WINDOW_CLOSED = 'wndc', 83 SHOW_DOWNLOAD_WINDOW = 'sdwd', 84 SHOW_SETTINGS_WINDOW = 'sswd', 85 SHOW_CONSOLE_WINDOW = 'scwd' 86 }; 87 88 #define INTEGRATE_MENU_INTO_TAB_BAR 0 89 90 91 class BrowserWindow : public BWebWindow { 92 public: 93 BrowserWindow(BRect frame, 94 SettingsMessage* appSettings, 95 const BString& url, 96 BUrlContext* context, 97 uint32 interfaceElements 98 = INTERFACE_ELEMENT_ALL, 99 BWebView* webView = NULL); 100 virtual ~BrowserWindow(); 101 102 virtual void DispatchMessage(BMessage* message, 103 BHandler* target); 104 virtual void MessageReceived(BMessage* message); 105 virtual bool QuitRequested(); 106 virtual void MenusBeginning(); 107 virtual void MenusEnded(); 108 109 virtual void ScreenChanged(BRect screenSize, 110 color_space format); 111 virtual void WorkspacesChanged(uint32 oldWorkspaces, 112 uint32 newWorkspaces); 113 114 virtual void SetCurrentWebView(BWebView* view); 115 116 bool IsBlankTab() const; 117 void CreateNewTab(const BString& url, bool select, 118 BWebView* webView = 0); 119 120 BRect WindowFrame() const; 121 122 void ToggleFullscreen(); 123 124 private: 125 // WebPage notification API implementations 126 virtual void NavigationRequested(const BString& url, 127 BWebView* view); 128 virtual void NewWindowRequested(const BString& url, 129 bool primaryAction); 130 virtual void CloseWindowRequested(BWebView* view); 131 virtual void NewPageCreated(BWebView* view, 132 BRect windowFrame, bool modalDialog, 133 bool resizable, bool activate); 134 virtual void LoadNegotiating(const BString& url, 135 BWebView* view); 136 virtual void LoadCommitted(const BString& url, 137 BWebView* view); 138 virtual void LoadProgress(float progress, BWebView* view); 139 virtual void LoadFailed(const BString& url, BWebView* view); 140 virtual void LoadFinished(const BString& url, 141 BWebView* view); 142 virtual void MainDocumentError(const BString& failingURL, 143 const BString& localizedDescription, 144 BWebView* view); 145 virtual void TitleChanged(const BString& title, 146 BWebView* view); 147 virtual void IconReceived(const BBitmap* icon, 148 BWebView* view); 149 virtual void ResizeRequested(float width, float height, 150 BWebView* view); 151 virtual void SetToolBarsVisible(bool flag, BWebView* view); 152 virtual void SetStatusBarVisible(bool flag, BWebView* view); 153 virtual void SetMenuBarVisible(bool flag, BWebView* view); 154 virtual void SetResizable(bool flag, BWebView* view); 155 virtual void StatusChanged(const BString& status, 156 BWebView* view); 157 virtual void NavigationCapabilitiesChanged( 158 bool canGoBackward, bool canGoForward, 159 bool canStop, BWebView* view); 160 virtual void UpdateGlobalHistory(const BString& url); 161 virtual bool AuthenticationChallenge(BString message, 162 BString& inOutUser, BString& inOutPassword, 163 bool& inOutRememberCredentials, 164 uint32 failureCount, BWebView* view); 165 166 private: 167 void _UpdateTitle(const BString &title); 168 void _UpdateTabGroupVisibility(); 169 bool _TabGroupShouldBeVisible() const; 170 void _ShutdownTab(int32 index); 171 void _TabChanged(int32 index); 172 173 status_t _BookmarkPath(BPath& path) const; 174 void _CreateBookmark(); 175 void _ShowBookmarks(); 176 bool _CheckBookmarkExists(BDirectory& directory, 177 const BString& fileName, 178 const BString& url) const; 179 bool _ReadURLAttr(BFile& bookmarkFile, 180 BString& url) const; 181 void _AddBookmarkURLsRecursively( 182 BDirectory& directory, 183 BMessage* message, 184 uint32& addedCount) const; 185 186 void _SetPageIcon(BWebView* view, 187 const BBitmap* icon); 188 189 void _UpdateHistoryMenu(); 190 void _UpdateClipboardItems(); 191 192 bool _ShowPage(BWebView* view); 193 194 void _ToggleFullscreen(); 195 void _ResizeToScreen(); 196 void _SetAutoHideInterfaceInFullscreen(bool doIt); 197 void _CheckAutoHideInterface(); 198 void _ShowInterface(bool show); 199 void _ShowProgressBar(bool); 200 void _InvokeButtonVisibly(BButton* button); 201 202 BString _NewTabURL(bool isNewWindow) const; 203 204 BString _EncodeURIComponent(const BString& search); 205 void _VisitURL(const BString& url); 206 void _VisitSearchEngine(const BString& search); 207 inline bool _IsValidDomainChar(char ch); 208 void _SmartURLHandler(const BString& url); 209 210 void _HandlePageSourceResult( 211 const BMessage* message); 212 213 void _ShowBookmarkBar(bool show); 214 215 private: 216 BMenu* fHistoryMenu; 217 int32 fHistoryMenuFixedItemCount; 218 219 BMenuItem* fCutMenuItem; 220 BMenuItem* fCopyMenuItem; 221 BMenuItem* fPasteMenuItem; 222 BMenuItem* fFindPreviousMenuItem; 223 BMenuItem* fFindNextMenuItem; 224 BMenuItem* fZoomTextOnlyMenuItem; 225 BMenuItem* fFullscreenItem; 226 BMenuItem* fBackMenuItem; 227 BMenuItem* fForwardMenuItem; 228 229 BIconButton* fBackButton; 230 BIconButton* fForwardButton; 231 BIconButton* fStopButton; 232 BIconButton* fHomeButton; 233 URLInputGroup* fURLInputGroup; 234 BStringView* fStatusText; 235 BStatusBar* fLoadingProgressBar; 236 237 BLayoutItem* fMenuGroup; 238 BLayoutItem* fTabGroup; 239 BLayoutItem* fNavigationGroup; 240 BLayoutItem* fFindGroup; 241 BLayoutItem* fStatusGroup; 242 BLayoutItem* fToggleFullscreenButton; 243 244 BTextControl* fFindTextControl; 245 BButton* fFindPreviousButton; 246 BButton* fFindNextButton; 247 BButton* fFindCloseButton; 248 BCheckBox* fFindCaseSensitiveCheckBox; 249 TabManager* fTabManager; 250 251 bool fIsFullscreen; 252 bool fInterfaceVisible; 253 bool fMenusRunning; 254 BRect fNonFullscreenWindowFrame; 255 BMessageRunner* fPulseRunner; 256 uint32 fVisibleInterfaceElements; 257 bigtime_t fLastMouseMovedTime; 258 BPoint fLastMousePos; 259 260 BUrlContext* fContext; 261 262 // cached settings 263 SettingsMessage* fAppSettings; 264 bool fZoomTextOnly; 265 bool fShowTabsIfSinglePageOpen; 266 bool fAutoHideInterfaceInFullscreenMode; 267 bool fAutoHidePointer; 268 uint32 fNewWindowPolicy; 269 uint32 fNewTabPolicy; 270 BString fStartPageURL; 271 BString fSearchPageURL; 272 273 BMenuItem* fBookmarkBarMenuItem; 274 BookmarkBar* fBookmarkBar; 275 }; 276 277 278 #endif // BROWSER_WINDOW_H 279 280