Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/*
2
 * Copyright 2005 James Bursa 
3
 * Copyright 2003 Phil Mellor 
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 .
18
 */
19
 
20
typedef unsigned int uint32_t;
21
 
22
/** \file
23
 * Box tree construction and manipulation (interface).
24
 *
25
 * This stage of rendering converts a tree of dom_nodes (produced by libdom)
26
 * to a tree of struct box. The box tree represents the structure of the
27
 * document as given by the CSS display and float properties.
28
 *
29
 * For example, consider the following HTML:
30
 * \code
31
 *   

Example Heading

32
 *   

Example paragraph with emphasised text etc.

\endcode
33
 *
34
 * This would produce approximately the following box tree with default CSS
35
 * rules:
36
 * \code
37
 *   BOX_BLOCK (corresponds to h1)
38
 *     BOX_INLINE_CONTAINER
39
 *       BOX_INLINE "Example Heading"
40
 *   BOX_BLOCK (p)
41
 *     BOX_INLINE_CONTAINER
42
 *       BOX_INLINE "Example paragraph "
43
 *       BOX_INLINE "with emphasised text" (em)
44
 *       BOX_INLINE "etc."                                             \endcode
45
 *
46
 * Note that the em has been collapsed into the INLINE_CONTAINER.
47
 *
48
 * If these CSS rules were applied:
49
 * \code
50
 *   h1 { display: table-cell }
51
 *   p { display: table-cell }
52
 *   em { float: left; width: 5em }                                    \endcode
53
 *
54
 * then the box tree would instead look like this:
55
 * \code
56
 *   BOX_TABLE
57
 *     BOX_TABLE_ROW_GROUP
58
 *       BOX_TABLE_ROW
59
 *         BOX_TABLE_CELL (h1)
60
 *           BOX_INLINE_CONTAINER
61
 *             BOX_INLINE "Example Heading"
62
 *         BOX_TABLE_CELL (p)
63
 *           BOX_INLINE_CONTAINER
64
 *             BOX_INLINE "Example paragraph "
65
 *             BOX_FLOAT_LEFT (em)
66
 *               BOX_BLOCK
67
 *                 BOX_INLINE_CONTAINER
68
 *                   BOX_INLINE "with emphasised text"
69
 *             BOX_INLINE "etc."                                       \endcode
70
 *
71
 * Here implied boxes have been added and a float is present.
72
 *
73
 * A box tree is "normalized" if the following is satisfied:
74
 * \code
75
 * parent               permitted child nodes
76
 * BLOCK, INLINE_BLOCK  BLOCK, INLINE_CONTAINER, TABLE
77
 * INLINE_CONTAINER     INLINE, INLINE_BLOCK, FLOAT_LEFT, FLOAT_RIGHT, BR, TEXT,
78
 *                      INLINE_END
79
 * INLINE               none
80
 * TABLE                at least 1 TABLE_ROW_GROUP
81
 * TABLE_ROW_GROUP      at least 1 TABLE_ROW
82
 * TABLE_ROW            at least 1 TABLE_CELL
83
 * TABLE_CELL           BLOCK, INLINE_CONTAINER, TABLE (same as BLOCK)
84
 * FLOAT_(LEFT|RIGHT)   exactly 1 BLOCK or TABLE
85
 * \endcode
86
 */
87
 
88
#ifndef _NETSURF_RENDER_BOX_H_
89
#define _NETSURF_RENDER_BOX_H_
90
 
91
#include 
92
#include 
93
#include 
94
 
95
#include "css/css.h"
96
#include "utils/nsurl.h"
97
#include "utils/types.h"
98
 
99
struct box;
100
struct browser_window;
101
struct column;
102
struct object_params;
103
struct object_param;
104
struct html_content;
105
 
106
struct dom_node;
107
 
108
#define UNKNOWN_WIDTH INT_MAX
109
#define UNKNOWN_MAX_WIDTH INT_MAX
110
 
111
typedef void (*box_construct_complete_cb)(struct html_content *c, bool success);
112
 
113
/** Type of a struct box. */
114
typedef enum {
115
	BOX_BLOCK, BOX_INLINE_CONTAINER, BOX_INLINE,
116
	BOX_TABLE, BOX_TABLE_ROW, BOX_TABLE_CELL,
117
	BOX_TABLE_ROW_GROUP,
118
	BOX_FLOAT_LEFT, BOX_FLOAT_RIGHT,
119
	BOX_INLINE_BLOCK, BOX_BR, BOX_TEXT,
120
	BOX_INLINE_END, BOX_NONE
121
} box_type;
122
 
123
 
124
/** Flags for a struct box. */
125
typedef enum {
126
	NEW_LINE    = 1 << 0,	/* first inline on a new line */
127
	STYLE_OWNED = 1 << 1,	/* style is owned by this box */
128
	PRINTED     = 1 << 2,	/* box has already been printed */
129
	PRE_STRIP   = 1 << 3,	/* PRE tag needing leading newline stripped */
130
	CLONE       = 1 << 4,	/* continuation of previous box from wrapping */
131
	MEASURED    = 1 << 5,	/* text box width has been measured */
132
	HAS_HEIGHT  = 1 << 6,	/* box has height (perhaps due to children) */
133
	MAKE_HEIGHT = 1 << 7,	/* box causes its own height */
134
	NEED_MIN    = 1 << 8,	/* minimum width is required for layout */
135
	REPLACE_DIM = 1 << 9,	/* replaced element has given dimensions */
136
	IFRAME      = 1 << 10,	/* box contains an iframe */
137
	CONVERT_CHILDREN = 1 << 11  /* wanted children converting */
138
} box_flags;
139
 
140
/* Sides of a box */
141
enum box_side { TOP, RIGHT, BOTTOM, LEFT };
142
 
143
/**
144
 * Container for box border details
145
 */
146
struct box_border {
147
	enum css_border_style_e style;	/**< border-style */
148
	css_color c;			/**< border-color value */
149
	int width;			/**< border-width (pixels) */
150
};
151
 
152
/** Node in box tree. All dimensions are in pixels. */
153
struct box {
154
	/** Type of box. */
155
	box_type type;
156
 
157
	/** Box flags */
158
	box_flags flags;
159
 
160
	/** Computed styles for elements and their pseudo elements.  NULL on
161
	 *  non-element boxes. */
162
	css_select_results *styles;
163
 
164
	/** Style for this box. 0 for INLINE_CONTAINER and FLOAT_*. Pointer into
165
	 *  a box's 'styles' select results, except for implied boxes, where it
166
	 *  is a pointer to an owned computed style. */
167
	css_computed_style *style;
168
 
169
	/** Coordinate of left padding edge relative to parent box, or relative
170
	 * to ancestor that contains this box in float_children for FLOAT_. */
171
	int x;
172
	/** Coordinate of top padding edge, relative as for x. */
173
	int y;
174
 
175
	int width;   /**< Width of content box (excluding padding etc.). */
176
	int height;  /**< Height of content box (excluding padding etc.). */
177
 
178
	/* These four variables determine the maximum extent of a box's
179
	 * descendants. They are relative to the x,y coordinates of the box.
180
	 *
181
	 * Their use depends on the overflow CSS property:
182
	 *
183
	 * Overflow:	Usage:
184
	 * visible	The content of the box is displayed within these
185
	 *		dimensions.
186
	 * hidden	These are ignored. Content is plotted within the box
187
	 *		dimensions.
188
	 * scroll	These are used to determine the extent of the
189
	 *		scrollable area.
190
	 * auto		As "scroll".
191
	 */
192
	int descendant_x0;  /**< left edge of descendants */
193
	int descendant_y0;  /**< top edge of descendants */
194
	int descendant_x1;  /**< right edge of descendants */
195
	int descendant_y1;  /**< bottom edge of descendants */
196
 
197
	int margin[4];   /**< Margin: TOP, RIGHT, BOTTOM, LEFT. */
198
	int padding[4];  /**< Padding: TOP, RIGHT, BOTTOM, LEFT. */
199
	struct box_border border[4];   /**< Border: TOP, RIGHT, BOTTOM, LEFT. */
200
 
201
	struct scrollbar *scroll_x;  /**< Horizontal scroll. */
202
	struct scrollbar *scroll_y;  /**< Vertical scroll. */
203
 
204
	/** Width of box taking all line breaks (including margins etc). Must
205
	 * be non-negative. */
206
	int min_width;
207
	/** Width that would be taken with no line breaks. Must be
208
	 * non-negative. */
209
	int max_width;
210
 
211
	/**< Byte offset within a textual representation of this content. */
212
	size_t byte_offset;
213
 
214
	char *text;     /**< Text, or 0 if none. Unterminated. */
215
	size_t length;  /**< Length of text. */
216
 
217
	/** Width of space after current text (depends on font and size). */
218
	int space;
219
 
220
	nsurl *href;   /**< Link, or 0. */
221
	const char *target;  /**< Link target, or 0. */
222
	const char *title;  /**< Title, or 0. */
223
 
224
	unsigned int columns;  /**< Number of columns for TABLE / TABLE_CELL. */
225
	unsigned int rows;     /**< Number of rows for TABLE only. */
226
	unsigned int start_column;  /**< Start column for TABLE_CELL only. */
227
 
228
	struct box *next;      /**< Next sibling box, or 0. */
229
	struct box *prev;      /**< Previous sibling box, or 0. */
230
	struct box *children;  /**< First child box, or 0. */
231
	struct box *last;      /**< Last child box, or 0. */
232
	struct box *parent;    /**< Parent box, or 0. */
233
	/** INLINE_END box corresponding to this INLINE box, or INLINE box
234
	 * corresponding to this INLINE_END box. */
235
	struct box *inline_end;
236
 
237
	/** First float child box, or 0. Float boxes are in the tree twice, in
238
	 * this list for the block box which defines the area for floats, and
239
	 * also in the standard tree given by children, next, prev, etc. */
240
	struct box *float_children;
241
	/** Next sibling float box. */
242
	struct box *next_float;
243
	/** If box is a float, points to box's containing block */
244
	struct box *float_container;
245
	/** Level below which subsequent floats must be cleared.
246
	 * This is used only for boxes with float_children */
247
	int clear_level;
248
 
249
	/** List marker box if this is a list-item, or 0. */
250
	struct box *list_marker;
251
 
252
	struct column *col;  /**< Array of table column data for TABLE only. */
253
 
254
	/** Form control data, or 0 if not a form control. */
255
	struct form_control* gadget;
256
 
257
	char *usemap; /** (Image)map to use with this object, or 0 if none */
258
	lwc_string *id; /**<  value of id attribute (or name for anchors) */
259
 
260
	/** Background image for this box, or 0 if none */
261
	struct hlcache_handle *background;
262
 
263
	/** Object in this box (usually an image), or 0 if none. */
264
	struct hlcache_handle* object;
265
	/** Parameters for the object, or 0. */
266
	struct object_params *object_params;
267
 
268
	/** Iframe's browser_window, or NULL if none */
269
	struct browser_window *iframe;
270
 
271
	struct dom_node *node; /**< DOM node that generated this box or NULL */
272
};
273
 
274
/** Table column data. */
275
struct column {
276
	/** Type of column. */
277
	enum { COLUMN_WIDTH_UNKNOWN, COLUMN_WIDTH_FIXED,
278
	       COLUMN_WIDTH_AUTO, COLUMN_WIDTH_PERCENT,
279
	       COLUMN_WIDTH_RELATIVE } type;
280
	/** Preferred width of column. Pixels for FIXED, percentage for PERCENT,
281
	 *  relative units for RELATIVE, unused for AUTO. */
282
	int width;
283
	/** Minimum width of content. */
284
	int min;
285
	/** Maximum width of content. */
286
	int max;
287
	/** Whether all of column's cells are css positioned. */
288
	bool positioned;
289
};
290
 
291
/** Parameters for object element and similar elements. */
292
struct object_params {
293
	nsurl *data;
294
	char *type;
295
	char *codetype;
296
	nsurl *codebase;
297
	nsurl *classid;
298
	struct object_param *params;
299
};
300
 
301
/** Linked list of object element parameters. */
302
struct object_param {
303
	char *name;
304
	char *value;
305
	char *type;
306
	char *valuetype;
307
	struct object_param *next;
308
};
309
 
310
/** Frame target names (constant pointers to save duplicating the strings many
311
 * times). We convert _blank to _top for user-friendliness. */
312
extern const char *TARGET_SELF;
313
extern const char *TARGET_PARENT;
314
extern const char *TARGET_TOP;
315
extern const char *TARGET_BLANK;
316
 
317
 
318
 
319
void *box_style_alloc(void *ptr, size_t len, void *pw);
320
struct box * box_create(css_select_results *styles, css_computed_style *style,
321
		bool style_owned, nsurl *href, const char *target,
322
		const char *title, lwc_string *id, void *context);
323
void box_add_child(struct box *parent, struct box *child);
324
void box_insert_sibling(struct box *box, struct box *new_box);
325
void box_unlink_and_free(struct box *box);
326
void box_free(struct box *box);
327
void box_free_box(struct box *box);
328
void box_bounds(struct box *box, struct rect *r);
329
void box_coords(struct box *box, int *x, int *y);
330
struct box *box_at_point(struct box *box, const int x, const int y,
331
		int *box_x, int *box_y);
332
struct box *box_pick_text_box(struct html_content *html,
333
		int x, int y, int dir, int *dx, int *dy);
334
struct box *box_find_by_id(struct box *box, lwc_string *id);
335
bool box_visible(struct box *box);
336
void box_dump(FILE *stream, struct box *box, unsigned int depth);
337
bool box_extract_link(const char *rel, nsurl *base, nsurl **result);
338
 
339
bool box_handle_scrollbars(struct content *c, struct box *box,
340
		bool bottom, bool right);
341
bool box_vscrollbar_present(const struct box *box);
342
bool box_hscrollbar_present(const struct box *box);
343
 
344
nserror box_construct_init(void);
345
void box_construct_fini(void);
346
nserror dom_to_box(struct dom_node *n, struct html_content *c,
347
		box_construct_complete_cb cb);
348
 
349
bool box_normalise_block(struct box *block, struct html_content *c);
350
 
351
#endif