summaryrefslogtreecommitdiff
path: root/render/html.h
blob: 8789f30e6a0a1bb5d194152617bb0188d17973d1 (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
/*
 * Copyright 2004 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
 * Content for text/html (interface).
 *
 * These functions should in general be called via the content interface.
 */

#ifndef _NETSURF_RENDER_HTML_H_
#define _NETSURF_RENDER_HTML_H_

#include <stdbool.h>
#include "content/content_type.h"
#include "css/css.h"
#include "desktop/mouse.h"
#include "desktop/plot_style.h"
#include "render/parser_binding.h"

struct fetch_multipart_data;
struct box;
struct rect;
struct browser_window;
struct content;
struct hlcache_handle;
struct http_parameter;
struct imagemap;
struct object_params;
struct plotters;
struct scroll;
struct scroll_msg_data;

/* entries in stylesheet_content */
#define STYLESHEET_BASE		0	/* base style sheet */
#define STYLESHEET_QUIRKS	1	/* quirks mode stylesheet */
#define STYLESHEET_ADBLOCK	2	/* adblocking stylesheet */
#define STYLESHEET_START	3	/* start of document stylesheets */

extern char *default_stylesheet_url;
extern char *adblock_stylesheet_url;
extern char *quirks_stylesheet_url;

/**
 * Container for stylesheets used by an HTML document
 */
struct html_stylesheet {
	/** Type of sheet */
	enum { HTML_STYLESHEET_EXTERNAL, HTML_STYLESHEET_INTERNAL } type;
	union {
		struct hlcache_handle *external;
		struct content_css_data *internal;
	} data;	/**< Sheet data */
};

struct frame_dimension {
  	float value;
	enum {
	  	FRAME_DIMENSION_PIXELS,		/* '100', '200' */
	  	FRAME_DIMENSION_PERCENT, 	/* '5%', '20%' */
	  	FRAME_DIMENSION_RELATIVE	/* '*', '2*' */
	} unit;
};

typedef enum {
  	SCROLLING_AUTO,
  	SCROLLING_YES,
  	SCROLLING_NO
} frame_scrolling;


/** An object (<img>, <object>, etc.) in a CONTENT_HTML document. */
struct content_html_object {
	struct content *parent;		/**< Parent document */
	struct content_html_object *next; /**< Next in chain */

	struct hlcache_handle *content;  /**< Content, or 0. */
	struct box *box;  /**< Node in box tree containing it. */
	/** Pointer to array of permitted content_type, terminated by
	 *  CONTENT_UNKNOWN, or 0 if any type is acceptable. */
	const content_type *permitted_types;
	bool background;  /**< This object is a background image. */
};

/** Frame tree (<frameset>, <frame>) */
struct content_html_frames {
	int cols;	/** number of columns in frameset */
	int rows;	/** number of rows in frameset */

	struct frame_dimension width;	/** frame width */
	struct frame_dimension height;	/** frame width */
	int margin_width;	/** frame margin width */
	int margin_height;	/** frame margin height */

	char *name;	/** frame name (for targetting) */
	char *url;	/** frame url */

	bool no_resize;	/** frame is not resizable */
	frame_scrolling scrolling;	/** scrolling characteristics */
	bool border;	/** frame has a border */
	colour border_colour;	/** frame border colour */

	struct content_html_frames *children; /** [cols * rows] children */
};

/** Inline frame list (<iframe>) */
struct content_html_iframe {
  	struct box *box;

	int margin_width;	/** frame margin width */
	int margin_height;	/** frame margin height */

	char *name;	/** frame name (for targetting) */
	char *url;	/** frame url */

	frame_scrolling scrolling;	/** scrolling characteristics */
	bool border;	/** frame has a border */
	colour border_colour;	/** frame border colour */

 	struct content_html_iframe *next;
};

/** Data specific to CONTENT_HTML. */
struct content_html_data {
	void *parser_binding;
	xmlDoc *document;
	binding_quirks_mode quirks; /**< Quirkyness of document */

	char *encoding;	/**< Encoding of source, 0 if unknown. */
	binding_encoding_source encoding_source;
				/**< Source of encoding information. */

	char *base_url;	/**< Base URL (may be a copy of content->url). */
	char *base_target;	/**< Base target */

	struct box *layout;  /**< Box tree, or 0. */
	colour background_colour;  /**< Document background colour. */
	const struct font_functions *font_func;

	struct hlcache_handle *favicon; /**< the favicon for the page */
	
	/** Number of entries in stylesheet_content. */
	unsigned int stylesheet_count;
	/** Stylesheets. Each may be 0. */
	struct html_stylesheet *stylesheets;
	/**< Style selection context */
	css_select_ctx *select_ctx;

	/** Number of entries in object_list. */
	unsigned int num_objects;
	/** List of objects. */
	struct content_html_object *object_list;
	/** Forms, in reverse order to document. */
	struct form *forms;
	/** Hash table of imagemaps. */
	struct imagemap **imagemaps;

	/** Browser window containing this document, or 0 if not open. */
	struct browser_window *bw;

	/** Frameset information */
	struct content_html_frames *frameset;

	/** Inline frame information */
	struct content_html_iframe *iframe;

	/** Content of type CONTENT_HTML containing this, or 0 if not an object
	 * within a page. */
	struct content *page;
	/** Box containing this, or 0 if not an object. */
	struct box *box;
};

/** Render padding and margin box outlines in html_redraw(). */
extern bool html_redraw_debug;


bool html_create(struct content *c, const struct http_parameter *params);
bool html_process_data(struct content *c, const char *data, unsigned int size);
bool html_convert(struct content *c);
void html_reformat(struct content *c, int width, int height);
void html_destroy(struct content *c);
bool html_clone(const struct content *old, struct content *new_content);
bool html_fetch_object(struct content *c, const char *url, struct box *box,
		const content_type *permitted_types,
		int available_width, int available_height,
		bool background);
void html_stop(struct content *c);
void html_open(struct content *c, struct browser_window *bw,
		struct content *page, struct box *box,
		struct object_params *params);
void html_close(struct content *c);
void html_set_status(struct content *c, const char *extra);

void html_redraw_a_box(struct hlcache_handle *h, struct box *box);

/* in render/html_redraw.c */
bool html_redraw(struct content *c, int x, int y,
		int width, int height, const struct rect *clip,
		float scale, colour background_colour);

/* in render/html_interaction.c */
void html_mouse_track(struct content *c, struct browser_window *bw,
			browser_mouse_state mouse, int x, int y);
void html_mouse_action(struct content *c, struct browser_window *bw,
			browser_mouse_state mouse, int x, int y);
void html_overflow_scroll_callback(void *client_data,
		struct scroll_msg_data *scroll_data);
void html_overflow_scroll_drag_end(struct scroll *scroll,
		browser_mouse_state mouse, int x, int y);
size_t html_selection_drag_end(struct hlcache_handle *h,
		browser_mouse_state mouse, int x, int y, int dir);

bool text_redraw(const char *utf8_text, size_t utf8_len,
		size_t offset, int space,
		const plot_font_style_t *fstyle,
		int x, int y,
		const struct rect *clip,
		int height,
		float scale,
		bool excluded);

xmlDoc *html_get_document(struct hlcache_handle *h);
struct box *html_get_box_tree(struct hlcache_handle *h);
const char *html_get_encoding(struct hlcache_handle *h);
binding_encoding_source html_get_encoding_source(struct hlcache_handle *h);
struct content_html_frames *html_get_frameset(struct hlcache_handle *h);
struct content_html_iframe *html_get_iframe(struct hlcache_handle *h);
const char *html_get_base_url(struct hlcache_handle *h);
const char *html_get_base_target(struct hlcache_handle *h);
struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h, 
		unsigned int *n);
struct content_html_object *html_get_objects(struct hlcache_handle *h, 
		unsigned int *n);
struct hlcache_handle *html_get_favicon(struct hlcache_handle *h);
bool html_get_id_offset(struct hlcache_handle *h, const char *frag_id,
		int *x, int *y);

#endif