summaryrefslogtreecommitdiff
path: root/desktop/browser_private.h
blob: 3cdef5c895c73e46cd9f4435693ef7f2920e0c05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
 * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
 * Copyright 2006 James Bursa <bursa@users.sourceforge.net>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * \file
 * Browser window private structure.
 */

#ifndef _NETSURF_DESKTOP_BROWSER_PRIVATE_H_
#define _NETSURF_DESKTOP_BROWSER_PRIVATE_H_

#include <libwapcaplet/libwapcaplet.h>

#include "netsurf/types.h"
#include "netsurf/browser_window.h"

#include "desktop/frame_types.h"

struct box;
struct hlcache_handle;
struct gui_window;
struct selection;
struct nsurl;

/**
 * history entry page information
 */
struct history_page {
	struct nsurl *url;    /**< Page URL, never NULL. */
	lwc_string *frag_id; /** Fragment identifier, or NULL. */
	char *title;  /**< Page title, never NULL. */
	struct bitmap *bitmap;  /**< Thumbnail bitmap, or NULL. */
};

/**
 * A node in the history tree.
 */
struct history_entry {
	struct history_page page;
	struct history_entry *back;  /**< Parent. */
	struct history_entry *next;  /**< Next sibling. */
	struct history_entry *forward;  /**< First child. */
	struct history_entry *forward_pref;  /**< Child in direction of
						  current entry. */
	struct history_entry *forward_last;  /**< Last child. */
	unsigned int children;  /**< Number of children. */
	int x;  /**< Position of node. */
	int y;  /**< Position of node. */
};

/**
 * History tree for a window.
 */
struct history {
	/** First page in tree (page that window opened with). */
	struct history_entry *start;
	/** Current position in tree. */
	struct history_entry *current;
	/** Width of layout. */
	int width;
	/** Height of layout. */
	int height;
};

/**
 * Browser window data.
 */
struct browser_window {
	/**
	 * Content handle of page currently displayed which must have
	 *  READY or DONE status or NULL for no content.
	 */
	struct hlcache_handle *current_content;
	/**
	 * Content handle of page in process of being loaded or NULL
	 * if no page is being loaded.
	 */
	struct hlcache_handle *loading_content;

	/**
	 * Favicon
	 */
	struct {
		/**
		 * content handle of current page favicon
		 */
		struct hlcache_handle *current;

		/**
		 * content handle for favicon which we started loading
		 * early
		 */
		struct hlcache_handle *loading;

		/**
		 * flag to indicate favicon fetch already failed which
		 * prevents infinite error looping.
		 */
		bool failed;
	} favicon;

	/** local history handle. */
	struct history *history;

	/**
	 * Platform specific window data only valid at top level.
	 */
	struct gui_window *window;

	/** Busy indicator is active. */
	bool throbbing;
	/** Add loading_content to the window history when it loads. */
	bool history_add;

	/** Fragment identifier for current_content. */
	lwc_string *frag_id;

	/**
	 * Current drag status.
	 *
	 * These values are only vald whle type is not DRAGGING_NONE
	 */
	struct {
		/** the type of drag in progress */
		browser_drag_type type;

		/** Current drag's browser window, when not in root bw. */
		struct browser_window *window;

		/** Mouse position at start of current scroll drag. */
		int start_x;
		int start_y;

		/** Scroll offsets at start of current scroll draw. */
		int start_scroll_x;
		int start_scroll_y;

		/** Frame resize directions for current frame resize drag. */
		unsigned int resize_left : 1;
		unsigned int resize_right : 1;
		unsigned int resize_up : 1;
		unsigned int resize_down : 1;
	} drag;

	/** Current fetch is download */
	bool download;

	/** Refresh interval (-1 if undefined) */
	int refresh_interval;

	/** Window dimensions */
	int x;
	int y;
	int width;
	int height;

	struct scrollbar *scroll_x;  /**< Horizontal scroll. */
	struct scrollbar *scroll_y;  /**< Vertical scroll. */

	/** scale of window contents */
	float scale;

	/** Window characteristics */
	enum {
		BROWSER_WINDOW_NORMAL,
		BROWSER_WINDOW_IFRAME,
		BROWSER_WINDOW_FRAME,
		BROWSER_WINDOW_FRAMESET,
	} browser_window_type;

	/** frameset characteristics */
	int rows;
	int cols;

	/** frame dimensions */
	struct frame_dimension frame_width;
	struct frame_dimension frame_height;
	int margin_width;
	int margin_height;

	/** frame name for targetting */
	char *name;

	/** frame characteristics */
	bool no_resize;
	browser_scrolling scrolling;
	bool border;
	colour border_colour;

	/** iframe parent box */
	struct box *box;

	/** [cols * rows] children */
	struct browser_window *children;
	struct browser_window *parent;

	/** [iframe_count] iframes */
	int iframe_count;
	struct browser_window *iframes;

	/** browser window child of root browser window which has input focus */
	struct browser_window *focus;

	/** Last time a link was followed in this window */
	uint64_t last_action;

	/** Current selection */
	struct {
		struct browser_window *bw;
		bool read_only;
	} selection;
	bool can_edit;

	/** current javascript context */
	struct jscontext *jsctx;

	/** cache of the currently displayed status text. */
	struct {
		char *text; /**< Current status bar text. */
		int text_len; /**< Length of the status::text buffer. */
		int match; /**< Number of times an idempotent status-set operation was performed. */
		int miss; /**< Number of times status was really updated. */
	} status;
};


/**
 * Initialise common parts of a browser window
 *
 * \param flags     Flags to control operation
 * \param bw        The window to initialise
 * \param existing  The existing window if cloning, else NULL
 */
nserror browser_window_initialise_common(enum browser_window_create_flags flags,
		struct browser_window *bw, struct browser_window *existing);


/**
 * Get the dimensions of the area a browser window occupies
 *
 * \param  bw      The browser window to get dimensions of
 * \param  width   Updated to the browser window viewport width
 * \param  height  Updated to the browser window viewport height
 * \param  scaled  Whether we want the height with scale applied
 */
void browser_window_get_dimensions(struct browser_window *bw,
		int *width, int *height, bool scaled);


/**
 * Update the extent of the inside of a browser window to that of the current
 * content
 *
 * \param bw browser_window to update the extent of
 */
void browser_window_update_extent(struct browser_window *bw);


/**
 * Change the status bar of a browser window.
 *
 * \param  bw	 browser window
 * \param  text  new status text (copied)
 */
void browser_window_set_status(struct browser_window *bw, const char *text);


/**
 * Get the root level browser window
 *
 * \param  bw     browser window to set the type of the current drag for
 * \return  root browser window
 */
struct browser_window * browser_window_get_root(struct browser_window *bw);


/**
 * Create a new history tree for a browser window window.
 *
 * \param bw browser window to create history for.
 *
 * \return NSERROR_OK or appropriate error otherwise
 */
nserror browser_window_history_create(struct browser_window *bw);

/**
 * Clone a bw's history tree for new bw
 *
 * \param  existing	browser window with history to clone.
 * \param  clone	browser window to make cloned history for.
 *
 * \return  NSERROR_OK or appropriate error otherwise
 */
nserror browser_window_history_clone(const struct browser_window *existing,
		struct browser_window *clone);


/**
 * Insert a url into the history tree.
 *
 * \param  bw       browser window with history object
 * \param  content  content to add to history
 * \param  frag_id  fragment identifier, or NULL.
 * \return NSERROR_OK or error code on faliure.
 *
 * The page is added after the current entry and becomes current.
 */
nserror browser_window_history_add(struct browser_window *bw,
		struct hlcache_handle *content, lwc_string *frag_id);

/**
 * Update the thumbnail for the current entry.
 *
 * \param bw The browser window to update the history within.
 * \param content content for current entry
 * \return NSERROR_OK or error code on faliure.
 */
nserror browser_window_history_update(struct browser_window *bw,
		struct hlcache_handle *content);

/**
 * Free a history structure.
 *
 * \param bw The browser window to destroy the history within.
 */
void browser_window_history_destroy(struct browser_window *bw);


#endif