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