xref: /haiku/src/apps/webpositive/BrowserWindow.h (revision 7a74a5df454197933bc6e80a542102362ee98703)
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 			BString				_SmartURLHandler(const BString& url) const;
194 
195 			void				_HandlePageSourceResult(
196 									const BMessage* message);
197 
198 private:
199 			BMenu*				fHistoryMenu;
200 			int32				fHistoryMenuFixedItemCount;
201 
202 			BMenuItem*			fCutMenuItem;
203 			BMenuItem*			fCopyMenuItem;
204 			BMenuItem*			fPasteMenuItem;
205 			BMenuItem*			fFindPreviousMenuItem;
206 			BMenuItem*			fFindNextMenuItem;
207 			BMenuItem*			fZoomTextOnlyMenuItem;
208 			BMenuItem*			fFullscreenItem;
209 			BMenuItem*			fBackMenuItem;
210 			BMenuItem*			fForwardMenuItem;
211 
212 			IconButton*			fBackButton;
213 			IconButton*			fForwardButton;
214 			IconButton*			fStopButton;
215 			IconButton*			fHomeButton;
216 			URLInputGroup*		fURLInputGroup;
217 			BStringView*		fStatusText;
218 			BStatusBar*			fLoadingProgressBar;
219 
220 			BLayoutItem*		fMenuGroup;
221 			BLayoutItem*		fTabGroup;
222 			BLayoutItem*		fNavigationGroup;
223 			BLayoutItem*		fFindGroup;
224 			BLayoutItem*		fStatusGroup;
225 			BLayoutItem*		fToggleFullscreenButton;
226 
227 			BTextControl*		fFindTextControl;
228 			BButton*			fFindPreviousButton;
229 			BButton*			fFindNextButton;
230 			BButton*			fFindCloseButton;
231 			BCheckBox*			fFindCaseSensitiveCheckBox;
232 			TabManager*			fTabManager;
233 
234 			bool				fIsFullscreen;
235 			bool				fInterfaceVisible;
236 			BRect				fNonFullscreenWindowFrame;
237 			BMessageRunner*		fPulseRunner;
238 			uint32				fVisibleInterfaceElements;
239 			bigtime_t			fLastMouseMovedTime;
240 			BPoint				fLastMousePos;
241 
242 			// cached settings
243 			SettingsMessage*	fAppSettings;
244 			bool				fZoomTextOnly;
245 			bool				fShowTabsIfSinglePageOpen;
246 			bool				fAutoHideInterfaceInFullscreenMode;
247 			bool				fAutoHidePointer;
248 			uint32				fNewWindowPolicy;
249 			uint32				fNewTabPolicy;
250 			BString				fStartPageURL;
251 			BString				fSearchPageURL;
252 };
253 
254 
255 #endif // BROWSER_WINDOW_H
256 
257