1 /*
2  * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
3  * Copyright 2006 James Bursa <bursa@users.sourceforge.net>
4  *
5  * This file is part of NetSurf, http://www.netsurf-browser.org/
6  *
7  * NetSurf is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * NetSurf is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 /**
21  * \file
22  * Browser window private structure.
23  */
24 
25 #ifndef NETSURF_DESKTOP_BROWSER_PRIVATE_H_
26 #define NETSURF_DESKTOP_BROWSER_PRIVATE_H_
27 
28 #include "content/fetch.h"
29 #include "desktop/frame_types.h"
30 
31 struct box;
32 struct hlcache_handle;
33 struct gui_window;
34 struct selection;
35 struct nsurl;
36 
37 /**
38  * history entry page information
39  */
40 struct history_page {
41 	struct nsurl *url;    /**< Page URL, never NULL. */
42 	lwc_string *frag_id; /** Fragment identifier, or NULL. */
43 	char *title;  /**< Page title, never NULL. */
44 	struct bitmap *bitmap;  /**< Thumbnail bitmap, or NULL. */
45 	float scroll_x; /**< Scroll X offset when visited */
46 	float scroll_y; /**< Scroll Y offset when visited */
47 };
48 
49 /**
50  * A node in the history tree.
51  */
52 struct history_entry {
53 	struct history_page page;
54 	struct history_entry *back;  /**< Parent. */
55 	struct history_entry *next;  /**< Next sibling. */
56 	struct history_entry *forward;  /**< First child. */
57 	struct history_entry *forward_pref;  /**< Child in direction of
58 						  current entry. */
59 	struct history_entry *forward_last;  /**< Last child. */
60 	unsigned int children;  /**< Number of children. */
61 	int x;  /**< Position of node. */
62 	int y;  /**< Position of node. */
63 };
64 
65 /**
66  * History tree for a window.
67  */
68 struct history {
69 	/** First page in tree (page that window opened with). */
70 	struct history_entry *start;
71 	/** Current position in tree. */
72 	struct history_entry *current;
73 	/** Width of layout. */
74 	int width;
75 	/** Height of layout. */
76 	int height;
77 };
78 
79 /**
80  * The parameters for a fetch.
81  */
82 struct browser_fetch_parameters {
83 	struct nsurl *url;                           /**< The URL to fetch */
84 	struct nsurl *referrer;			     /**< Optional refererer */
85 	enum browser_window_nav_flags flags;	     /**< Navigation flags */
86 	char *post_urlenc;			     /**< URL encoded post data */
87 	struct fetch_multipart_data *post_multipart; /**< Multipart post data */
88 	char *parent_charset;			     /**< Optional parent character set */
89 	bool parent_quirks;			     /**< Optional parent quirks */
90 };
91 
92 
93 /**
94  * Browser window data.
95  */
96 struct browser_window {
97 	/**
98 	 * Content handle of page currently displayed which must have
99 	 *  READY or DONE status or NULL for no content.
100 	 */
101 	struct hlcache_handle *current_content;
102 
103 	/**
104 	 * The fetch parameters for the current content
105 	 */
106 	struct browser_fetch_parameters current_parameters;
107 
108 	/**
109 	 * The certificate chain for the current content
110 	 */
111 	struct cert_chain *current_cert_chain;
112 
113 	/**
114 	 * Content handle of page in process of being loaded or NULL
115 	 * if no page is being loaded.
116 	 */
117 	struct hlcache_handle *loading_content;
118 
119 	/**
120 	 * The fetch parameters for the loading content
121 	 */
122 	struct browser_fetch_parameters loading_parameters;
123 
124 	/**
125 	 * The certificate chain for the loading content
126 	 */
127 	struct cert_chain *loading_cert_chain;
128 
129 	/**
130 	 * Favicon
131 	 */
132 	struct {
133 		/**
134 		 * content handle of current page favicon
135 		 */
136 		struct hlcache_handle *current;
137 
138 		/**
139 		 * content handle for favicon which we started loading
140 		 * early
141 		 */
142 		struct hlcache_handle *loading;
143 
144 		/**
145 		 * flag to indicate favicon fetch already failed which
146 		 * prevents infinite error looping.
147 		 */
148 		bool failed;
149 	} favicon;
150 
151 	/** local history handle. */
152 	struct history *history;
153 
154 	/**
155 	 * Platform specific window data only valid at top level.
156 	 */
157 	struct gui_window *window;
158 
159 	/** Busy indicator is active. */
160 	bool throbbing;
161 	/** Add loading_content to the window history when it loads. */
162 	bool history_add;
163 	/** Internal navigation, do not update URL etc */
164 	bool internal_nav;
165 
166 	/** Fragment identifier for current_content. */
167 	lwc_string *frag_id;
168 
169 	/**
170 	 * Current drag status.
171 	 *
172 	 * These values are only vald whle type is not DRAGGING_NONE
173 	 */
174 	struct {
175 		/** the type of drag in progress */
176 		browser_drag_type type;
177 
178 		/** Current drag's browser window, when not in root bw. */
179 		struct browser_window *window;
180 
181 		/** Mouse position at start of current scroll drag. */
182 		int start_x;
183 		int start_y;
184 
185 		/** Scroll offsets at start of current scroll draw. */
186 		int start_scroll_x;
187 		int start_scroll_y;
188 
189 		/** Frame resize directions for current frame resize drag. */
190 		unsigned int resize_left : 1;
191 		unsigned int resize_right : 1;
192 		unsigned int resize_up : 1;
193 		unsigned int resize_down : 1;
194 	} drag;
195 
196 	/** Current fetch is download */
197 	bool download;
198 
199 	/** Refresh interval (-1 if undefined) */
200 	int refresh_interval;
201 
202 	/** Window dimensions */
203 	int x;
204 	int y;
205 	int width;
206 	int height;
207 
208 	struct scrollbar *scroll_x;  /**< Horizontal scroll. */
209 	struct scrollbar *scroll_y;  /**< Vertical scroll. */
210 
211 	/** scale of window contents */
212 	float scale;
213 
214 	/** Window characteristics */
215 	enum {
216 		BROWSER_WINDOW_NORMAL,
217 		BROWSER_WINDOW_IFRAME,
218 		BROWSER_WINDOW_FRAME,
219 		BROWSER_WINDOW_FRAMESET,
220 	} browser_window_type;
221 
222 	/** frameset characteristics */
223 	int rows;
224 	int cols;
225 
226 	/** frame dimensions */
227 	struct frame_dimension frame_width;
228 	struct frame_dimension frame_height;
229 	int margin_width;
230 	int margin_height;
231 
232 	/** frame name for targetting */
233 	char *name;
234 
235 	/** frame characteristics */
236 	bool no_resize;
237 	browser_scrolling scrolling;
238 	bool border;
239 	colour border_colour;
240 
241 	/** iframe parent box */
242 	struct box *box;
243 
244 	/** [cols * rows] children */
245 	struct browser_window *children;
246 	struct browser_window *parent;
247 
248 	/** [iframe_count] iframes */
249 	int iframe_count;
250 	struct browser_window *iframes;
251 
252 	/** browser window child of root browser window which has input focus */
253 	struct browser_window *focus;
254 
255 	/** Last time a link was followed in this window */
256 	uint64_t last_action;
257 
258 	/** Current selection */
259 	struct {
260 		struct browser_window *bw;
261 		bool read_only;
262 	} selection;
263 	bool can_edit;
264 
265 	/** current javascript context */
266 	struct jsheap *jsheap;
267 
268 	/** cache of the currently displayed status text. */
269 	struct {
270 		char *text; /**< Current status bar text. */
271 		int text_len; /**< Length of the status::text buffer. */
272 		int match; /**< Number of times an idempotent status-set operation was performed. */
273 		int miss; /**< Number of times status was really updated. */
274 	} status;
275 };
276 
277 
278 /**
279  * Initialise common parts of a browser window
280  *
281  * \param flags     Flags to control operation
282  * \param bw        The window to initialise
283  * \param existing  The existing window if cloning, else NULL
284  */
285 nserror browser_window_initialise_common(enum browser_window_create_flags flags,
286 		struct browser_window *bw,
287 		const struct browser_window *existing);
288 
289 
290 /**
291  * Get the dimensions of the area a browser window occupies
292  *
293  * \param  bw      The browser window to get dimensions of
294  * \param  width   Updated to the browser window viewport width
295  * \param  height  Updated to the browser window viewport height
296  * \return NSERROR_OK and width and height updated otherwise error code
297  */
298 nserror browser_window_get_dimensions(struct browser_window *bw,
299 		int *width, int *height);
300 
301 
302 /**
303  * Update the extent of the inside of a browser window to that of the current
304  * content
305  *
306  * \param bw browser_window to update the extent of
307  */
308 void browser_window_update_extent(struct browser_window *bw);
309 
310 
311 /**
312  * update an area of a browser window.
313  *
314  * \param bw The browser window to update.
315  * \param rect The area to redraw
316  */
317 void browser_window_update_box(struct browser_window *bw, struct rect *rect);
318 
319 
320 /**
321  * Change the status bar of a browser window.
322  *
323  * \param  bw	 browser window
324  * \param  text  new status text (copied)
325  */
326 void browser_window_set_status(struct browser_window *bw, const char *text);
327 
328 
329 /**
330  * Get the root level browser window
331  *
332  * \param  bw     browser window to set the type of the current drag for
333  * \return  root browser window
334  */
335 struct browser_window * browser_window_get_root(
336 		struct browser_window *bw);
337 
338 
339 /**
340  * Create a new history tree for a browser window window.
341  *
342  * \param bw browser window to create history for.
343  *
344  * \return NSERROR_OK or appropriate error otherwise
345  */
346 nserror browser_window_history_create(struct browser_window *bw);
347 
348 /**
349  * Clone a bw's history tree for new bw
350  *
351  * \param  existing	browser window with history to clone.
352  * \param  clone	browser window to make cloned history for.
353  *
354  * \return  NSERROR_OK or appropriate error otherwise
355  */
356 nserror browser_window_history_clone(const struct browser_window *existing,
357 		struct browser_window *clone);
358 
359 
360 /**
361  * Insert a url into the history tree.
362  *
363  * \param  bw       browser window with history object
364  * \param  content  content to add to history
365  * \param  frag_id  fragment identifier, or NULL.
366  * \return NSERROR_OK or error code on faliure.
367  *
368  * The page is added after the current entry and becomes current.
369  */
370 nserror browser_window_history_add(struct browser_window *bw,
371 		struct hlcache_handle *content, lwc_string *frag_id);
372 
373 /**
374  * Update the thumbnail and scroll offsets for the current entry.
375  *
376  * \param bw The browser window to update the history within.
377  * \param content content for current entry
378  * \return NSERROR_OK or error code on faliure.
379  */
380 nserror browser_window_history_update(struct browser_window *bw,
381 		struct hlcache_handle *content);
382 
383 /**
384  * Retrieve the stored scroll offsets for the current history entry
385  *
386  * \param bw The browser window to retrieve scroll offsets for.
387  * \param sx Pointer to a float for the X scroll offset
388  * \param sy Pointer to a float for the Y scroll offset
389  * \return NSERROR_OK or error code on failure.
390  */
391 nserror browser_window_history_get_scroll(struct browser_window *bw,
392 					  float *sx, float *sy);
393 
394 /**
395  * Free a history structure.
396  *
397  * \param bw The browser window to destroy the history within.
398  */
399 void browser_window_history_destroy(struct browser_window *bw);
400 
401 /**
402  * Type for handling query responses short-term
403  */
404 typedef nserror (*browser_window_query_callback)(bool proceed, void *pw);
405 
406 /**
407  * Navigate a browser window to the current parameters
408  *
409  * \param bw The browser window to cause to navigate
410  */
411 nserror browser_window__reload_current_parameters(struct browser_window *bw);
412 
413 #endif
414