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