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