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