xref: /haiku/src/apps/webpositive/BrowserWindow.h (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
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 BFilePanel;
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 BUrlContext;
50 class BWebView;
51 
52 class BookmarkBar;
53 class SettingsMessage;
54 class TabManager;
55 class URLInputGroup;
56 
57 namespace BPrivate {
58 	class BIconButton;
59 }
60 
61 using BPrivate::BIconButton;
62 
63 enum {
64 	INTERFACE_ELEMENT_MENU			= 1 << 0,
65 	INTERFACE_ELEMENT_TABS			= 1 << 1,
66 	INTERFACE_ELEMENT_NAVIGATION	= 1 << 2,
67 	INTERFACE_ELEMENT_STATUS		= 1 << 3,
68 
69 	INTERFACE_ELEMENT_ALL			= 0xffff
70 };
71 
72 enum NewPagePolicy {
73 	OpenBlankPage					= 0,
74 	OpenStartPage					= 1,
75 	OpenSearchPage					= 2,
76 	CloneCurrentPage				= 3
77 };
78 
79 enum StartUpPolicy {
80 	ResumePriorSession				= 0,
81 	StartNewSession					= 1
82 };
83 
84 enum {
85 	NEW_WINDOW						= 'nwnd',
86 	NEW_TAB							= 'ntab',
87 	WINDOW_OPENED					= 'wndo',
88 	WINDOW_CLOSED					= 'wndc',
89 	SHOW_DOWNLOAD_WINDOW			= 'sdwd',
90 	SHOW_SETTINGS_WINDOW			= 'sswd',
91 	SHOW_CONSOLE_WINDOW				= 'scwd',
92 	SHOW_COOKIE_WINDOW				= 'skwd'
93 };
94 
95 #define INTEGRATE_MENU_INTO_TAB_BAR 0
96 
97 
98 class BrowserWindow : public BWebWindow {
99 public:
100 								BrowserWindow(BRect frame,
101 									SettingsMessage* appSettings,
102 									const BString& url,
103 									BUrlContext* context,
104 									uint32 interfaceElements
105 										= INTERFACE_ELEMENT_ALL,
106 									BWebView* webView = NULL);
107 	virtual						~BrowserWindow();
108 
109 	virtual	void				DispatchMessage(BMessage* message,
110 									BHandler* target);
111 	virtual	void				MessageReceived(BMessage* message);
112 	virtual	status_t			Archive(BMessage* archive, bool deep =true) const;
113 	virtual	bool				QuitRequested();
114 	virtual	void				MenusBeginning();
115 	virtual	void				MenusEnded();
116 
117 	virtual void				ScreenChanged(BRect screenSize,
118 									color_space format);
119 	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
120 									uint32 newWorkspaces);
121 
122 	virtual	void				SetCurrentWebView(BWebView* view);
123 
124 			bool				IsBlankTab() const;
125 			void				CreateNewTab(const BString& url, bool select,
126 									BWebView* webView = 0);
127 
128 			BRect				WindowFrame() const;
129 
130 			void				ToggleFullscreen();
131 
132 private:
133 	// WebPage notification API implementations
134 	virtual	void				NavigationRequested(const BString& url,
135 									BWebView* view);
136 	virtual	void				NewWindowRequested(const BString& url,
137 									bool primaryAction);
138 	virtual	void				CloseWindowRequested(BWebView* view);
139 	virtual	void				NewPageCreated(BWebView* view,
140 									BRect windowFrame, bool modalDialog,
141 									bool resizable, bool activate);
142 	virtual	void				LoadNegotiating(const BString& url,
143 									BWebView* view);
144 	virtual	void				LoadCommitted(const BString& url,
145 									BWebView* view);
146 	virtual	void				LoadProgress(float progress, BWebView* view);
147 	virtual	void				LoadFailed(const BString& url, BWebView* view);
148 	virtual	void				LoadFinished(const BString& url,
149 									BWebView* view);
150 	virtual	void				MainDocumentError(const BString& failingURL,
151 									const BString& localizedDescription,
152 									BWebView* view);
153 	virtual	void				TitleChanged(const BString& title,
154 									BWebView* view);
155 	virtual	void				IconReceived(const BBitmap* icon,
156 									BWebView* view);
157 	virtual	void				ResizeRequested(float width, float height,
158 									BWebView* view);
159 	virtual	void				SetToolBarsVisible(bool flag, BWebView* view);
160 	virtual	void				SetStatusBarVisible(bool flag, BWebView* view);
161 	virtual	void				SetMenuBarVisible(bool flag, BWebView* view);
162 	virtual	void				SetResizable(bool flag, BWebView* view);
163 	virtual	void				StatusChanged(const BString& status,
164 									BWebView* view);
165 	virtual	void				NavigationCapabilitiesChanged(
166 									bool canGoBackward, bool canGoForward,
167 									bool canStop, BWebView* view);
168 	virtual	void				UpdateGlobalHistory(const BString& url);
169 	virtual	bool				AuthenticationChallenge(BString message,
170 									BString& inOutUser, BString& inOutPassword,
171 									bool& inOutRememberCredentials,
172 									uint32 failureCount, BWebView* view);
173 
174 private:
175 			void				_UpdateTitle(const BString &title);
176 			void				_UpdateTabGroupVisibility();
177 			bool				_TabGroupShouldBeVisible() const;
178 			void				_ShutdownTab(int32 index);
179 			void				_TabChanged(int32 index);
180 
181 			status_t			_BookmarkPath(BPath& path) const;
182 			void				_CreateBookmark();
183 			void				_ShowBookmarks();
184 			bool				_CheckBookmarkExists(BDirectory& directory,
185 									const BString& fileName,
186 									const BString& url) const;
187 			bool				_ReadURLAttr(BFile& bookmarkFile,
188 									BString& url) const;
189 			void				_AddBookmarkURLsRecursively(
190 									BDirectory& directory,
191 									BMessage* message,
192 									uint32& addedCount) const;
193 
194 			void				_SetPageIcon(BWebView* view,
195 									const BBitmap* icon);
196 
197 			void				_UpdateHistoryMenu();
198 			void				_UpdateClipboardItems();
199 
200 			bool				_ShowPage(BWebView* view);
201 
202 			void				_ToggleFullscreen();
203 			void				_ResizeToScreen();
204 			void				_SetAutoHideInterfaceInFullscreen(bool doIt);
205 			void				_CheckAutoHideInterface();
206 			void				_ShowInterface(bool show);
207 			void				_ShowProgressBar(bool);
208 			void				_InvokeButtonVisibly(BButton* button);
209 
210 			BString				_NewTabURL(bool isNewWindow) const;
211 
212 			BString				_EncodeURIComponent(const BString& search);
213 			void				_VisitURL(const BString& url);
214 			void				_VisitSearchEngine(const BString& search);
215 	inline 	bool				_IsValidDomainChar(char ch);
216 			void 				_SmartURLHandler(const BString& url);
217 
218 			void				_HandlePageSourceResult(
219 									const BMessage* message);
220 
221 			void				_ShowBookmarkBar(bool show);
222 
223 private:
224 			BMenu*				fHistoryMenu;
225 			int32				fHistoryMenuFixedItemCount;
226 
227 			BMenuItem*			fCutMenuItem;
228 			BMenuItem*			fCopyMenuItem;
229 			BMenuItem*			fPasteMenuItem;
230 			BMenuItem*			fFindPreviousMenuItem;
231 			BMenuItem*			fFindNextMenuItem;
232 			BMenuItem*			fZoomTextOnlyMenuItem;
233 			BMenuItem*			fFullscreenItem;
234 			BMenuItem*			fBackMenuItem;
235 			BMenuItem*			fForwardMenuItem;
236 
237 			BIconButton*		fBackButton;
238 			BIconButton*		fForwardButton;
239 			BIconButton*		fStopButton;
240 			BIconButton*		fHomeButton;
241 			URLInputGroup*		fURLInputGroup;
242 			BStringView*		fStatusText;
243 			BStatusBar*			fLoadingProgressBar;
244 
245 			BLayoutItem*		fMenuGroup;
246 			BLayoutItem*		fTabGroup;
247 			BLayoutItem*		fNavigationGroup;
248 			BLayoutItem*		fFindGroup;
249 			BLayoutItem*		fStatusGroup;
250 			BLayoutItem*		fToggleFullscreenButton;
251 
252 			BTextControl*		fFindTextControl;
253 			BButton*			fFindPreviousButton;
254 			BButton*			fFindNextButton;
255 			BButton*			fFindCloseButton;
256 			BCheckBox*			fFindCaseSensitiveCheckBox;
257 			TabManager*			fTabManager;
258 
259 			bool				fIsFullscreen;
260 			bool				fInterfaceVisible;
261 			bool				fMenusRunning;
262 			BRect				fNonFullscreenWindowFrame;
263 			BMessageRunner*		fPulseRunner;
264 			uint32				fVisibleInterfaceElements;
265 			bigtime_t			fLastMouseMovedTime;
266 			BPoint				fLastMousePos;
267 
268 			BUrlContext*		fContext;
269 
270 			// cached settings
271 			SettingsMessage*	fAppSettings;
272 			bool				fZoomTextOnly;
273 			bool				fShowTabsIfSinglePageOpen;
274 			bool				fAutoHideInterfaceInFullscreenMode;
275 			bool				fAutoHidePointer;
276 			uint32				fNewWindowPolicy;
277 			uint32				fNewTabPolicy;
278 			BString				fStartPageURL;
279 			BString				fSearchPageURL;
280 
281 			BMenuItem*			fBookmarkBarMenuItem;
282 			BookmarkBar*		fBookmarkBar;
283 			BFilePanel*			fSavePanel;
284 };
285 
286 
287 #endif // BROWSER_WINDOW_H
288 
289