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