NetSurf
box.h
Go to the documentation of this file.
1/*
2 * Copyright 2005 James Bursa <bursa@users.sourceforge.net>
3 * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
4 * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
5 *
6 * This file is part of NetSurf, http://www.netsurf-browser.org/
7 *
8 * NetSurf is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * NetSurf is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21/**
22 * \file
23 * Box interface.
24 *
25 */
26
27#ifndef NETSURF_HTML_BOX_H
28#define NETSURF_HTML_BOX_H
29
30#include <limits.h>
31#include <stdbool.h>
32#include <libcss/libcss.h>
33
35
36struct content;
37struct box;
38struct browser_window;
39struct html_content;
40struct nsurl;
41struct dom_node;
42struct dom_string;
43struct rect;
44
45#define UNKNOWN_WIDTH INT_MAX
46#define UNKNOWN_MAX_WIDTH INT_MAX
47
48
49typedef void (*box_construct_complete_cb)(struct html_content *c, bool success);
50
51
52/**
53 * Type of a struct box.
54 */
55typedef enum {
72} box_type;
73
74
75/**
76 * Flags for a struct box.
77 */
78typedef enum {
79 NEW_LINE = 1 << 0, /* first inline on a new line */
80 STYLE_OWNED = 1 << 1, /* style is owned by this box */
81 PRINTED = 1 << 2, /* box has already been printed */
82 PRE_STRIP = 1 << 3, /* PRE tag needing leading newline stripped */
83 CLONE = 1 << 4, /* continuation of previous box from wrapping */
84 MEASURED = 1 << 5, /* text box width has been measured */
85 HAS_HEIGHT = 1 << 6, /* box has height (perhaps due to children) */
86 MAKE_HEIGHT = 1 << 7, /* box causes its own height */
87 NEED_MIN = 1 << 8, /* minimum width is required for layout */
88 REPLACE_DIM = 1 << 9, /* replaced element has given dimensions */
89 IFRAME = 1 << 10, /* box contains an iframe */
90 CONVERT_CHILDREN = 1 << 11, /* wanted children converting */
91 IS_REPLACED = 1 << 12 /* box is a replaced element */
93
94
95/**
96 * Sides of a box
97 */
99
100
101/**
102 * Container for box border details
103 */
105 enum css_border_style_e style; /**< border-style */
106 css_color c; /**< border-color value */
107 int width; /**< border-width (pixels) */
108};
109
110
111/**
112 * Table column data.
113 */
114struct column {
115 /**
116 * Type of column.
117 */
118 enum {
125
126 /**
127 * Preferred width of column. Pixels for FIXED, percentage for
128 * PERCENT, relative units for RELATIVE, unused for AUTO.
129 */
130 int width;
131
132 /**
133 * Minimum width of content.
134 */
135 int min;
136
137 /**
138 * Maximum width of content.
139 */
140 int max;
141
142 /**
143 * Whether all of column's cells are css positioned.
144 */
146};
147
148
149/**
150 * Linked list of object element parameters.
151 */
153 char *name;
154 char *value;
155 char *type;
158};
159
160
161/**
162 * Parameters for object element and similar elements.
163 */
165 struct nsurl *data;
166 char *type;
167 char *codetype;
169 struct nsurl *classid;
171};
172
173
174/**
175 * Node in box tree. All dimensions are in pixels.
176 */
177struct box {
178 /**
179 * Type of box.
180 */
182
183 /**
184 * Box flags
185 */
187
188 /**
189 * DOM node that generated this box or NULL
190 */
191 struct dom_node *node;
192
193 /**
194 * Computed styles for elements and their pseudo elements.
195 * NULL on non-element boxes.
196 */
197 css_select_results *styles;
198
199 /**
200 * Style for this box. 0 for INLINE_CONTAINER and
201 * FLOAT_*. Pointer into a box's 'styles' select results,
202 * except for implied boxes, where it is a pointer to an
203 * owned computed style.
204 */
205 css_computed_style *style;
206
207 /**
208 * value of id attribute (or name for anchors)
209 */
210 lwc_string *id;
211
212
213 /**
214 * Next sibling box, or NULL.
215 */
216 struct box *next;
217
218 /**
219 * Previous sibling box, or NULL.
220 */
221 struct box *prev;
222
223 /**
224 * First child box, or NULL.
225 */
226 struct box *children;
227
228 /**
229 * Last child box, or NULL.
230 */
231 struct box *last;
232
233 /**
234 * Parent box, or NULL.
235 */
236 struct box *parent;
237
238 /**
239 * INLINE_END box corresponding to this INLINE box, or INLINE
240 * box corresponding to this INLINE_END box.
241 */
243
244
245 /**
246 * First float child box, or NULL. Float boxes are in the tree
247 * twice, in this list for the block box which defines the
248 * area for floats, and also in the standard tree given by
249 * children, next, prev, etc.
250 */
252
253 /**
254 * Next sibling float box.
255 */
257
258 /**
259 * If box is a float, points to box's containing block
260 */
262
263 /**
264 * Level below which subsequent floats must be cleared. This
265 * is used only for boxes with float_children
266 */
268
269 /**
270 * Level below which floats have been placed.
271 */
273
274
275 /**
276 * Coordinate of left padding edge relative to parent box, or
277 * relative to ancestor that contains this box in
278 * float_children for FLOAT_.
279 */
280 int x;
281 /**
282 * Coordinate of top padding edge, relative as for x.
283 */
284 int y;
285
286 /**
287 * Width of content box (excluding padding etc.).
288 */
289 int width;
290 /**
291 * Height of content box (excluding padding etc.).
292 */
294
295 /* These four variables determine the maximum extent of a box's
296 * descendants. They are relative to the x,y coordinates of the box.
297 *
298 * Their use depends on the overflow CSS property:
299 *
300 * Overflow: Usage:
301 * visible The content of the box is displayed within these
302 * dimensions.
303 * hidden These are ignored. Content is plotted within the box
304 * dimensions.
305 * scroll These are used to determine the extent of the
306 * scrollable area.
307 * auto As "scroll".
308 */
309 int descendant_x0; /**< left edge of descendants */
310 int descendant_y0; /**< top edge of descendants */
311 int descendant_x1; /**< right edge of descendants */
312 int descendant_y1; /**< bottom edge of descendants */
313
314 /**
315 * Margin: TOP, RIGHT, BOTTOM, LEFT.
316 */
317 int margin[4];
318
319 /**
320 * Padding: TOP, RIGHT, BOTTOM, LEFT.
321 */
322 int padding[4];
323
324 /**
325 * Border: TOP, RIGHT, BOTTOM, LEFT.
326 */
328
329 /**
330 * Horizontal scroll.
331 */
333
334 /**
335 * Vertical scroll.
336 */
338
339 /**
340 * Width of box taking all line breaks (including margins
341 * etc). Must be non-negative.
342 */
344
345 /**
346 * Width that would be taken with no line breaks. Must be
347 * non-negative.
348 */
350
351
352 /**
353 * Text, or NULL if none. Unterminated.
354 */
355 char *text;
356
357 /**
358 * Length of text.
359 */
360 size_t length;
361
362 /**
363 * Width of space after current text (depends on font and size).
364 */
365 int space;
366
367 /**
368 * Byte offset within a textual representation of this content.
369 */
371
372
373 /**
374 * Link, or NULL.
375 */
376 struct nsurl *href;
377
378 /**
379 * Link target, or NULL.
380 */
381 const char *target;
382
383 /**
384 * Title, or NULL.
385 */
386 const char *title;
387
388
389 /**
390 * Number of columns for TABLE / TABLE_CELL.
391 */
392 unsigned int columns;
393
394 /**
395 * Number of rows for TABLE only.
396 */
397 unsigned int rows;
398
399 /**
400 * Start column for TABLE_CELL only.
401 */
402 unsigned int start_column;
403
404 /**
405 * Array of table column data for TABLE only.
406 */
407 struct column *col;
408
409 /**
410 * List item value.
411 */
413
414 /**
415 * List marker box if this is a list-item, or NULL.
416 */
418
419
420 /**
421 * Form control data, or NULL if not a form control.
422 */
424
425
426 /**
427 * (Image)map to use with this object, or NULL if none
428 */
429 char *usemap;
430
431
432 /**
433 * Background image for this box, or NULL if none
434 */
436
437
438 /**
439 * Object in this box (usually an image), or NULL if none.
440 */
442
443 /**
444 * Parameters for the object, or NULL.
445 */
447
448
449 /**
450 * Iframe's browser_window, or NULL if none
451 */
453
454};
455
456
457#endif
void(* box_construct_complete_cb)(struct html_content *c, bool success)
Definition: box.h:49
box_type
Type of a struct box.
Definition: box.h:55
@ BOX_BLOCK
Definition: box.h:56
@ BOX_FLOAT_LEFT
Definition: box.h:63
@ BOX_INLINE_BLOCK
Definition: box.h:65
@ BOX_FLOAT_RIGHT
Definition: box.h:64
@ BOX_INLINE_CONTAINER
Definition: box.h:57
@ BOX_TABLE_CELL
Definition: box.h:61
@ BOX_TABLE_ROW_GROUP
Definition: box.h:62
@ BOX_INLINE_END
Definition: box.h:68
@ BOX_TABLE
Definition: box.h:59
@ BOX_INLINE
Definition: box.h:58
@ BOX_TABLE_ROW
Definition: box.h:60
@ BOX_TEXT
Definition: box.h:67
@ BOX_INLINE_FLEX
Definition: box.h:71
@ BOX_BR
Definition: box.h:66
@ BOX_FLEX
Definition: box.h:70
@ BOX_NONE
Definition: box.h:69
box_flags
Flags for a struct box.
Definition: box.h:78
@ CONVERT_CHILDREN
Definition: box.h:90
@ IFRAME
Definition: box.h:89
@ NEED_MIN
Definition: box.h:87
@ NEW_LINE
Definition: box.h:79
@ MEASURED
Definition: box.h:84
@ IS_REPLACED
Definition: box.h:91
@ PRE_STRIP
Definition: box.h:82
@ CLONE
Definition: box.h:83
@ MAKE_HEIGHT
Definition: box.h:86
@ HAS_HEIGHT
Definition: box.h:85
@ REPLACE_DIM
Definition: box.h:88
@ STYLE_OWNED
Definition: box.h:80
@ PRINTED
Definition: box.h:81
box_side
Sides of a box.
Definition: box.h:98
@ TOP
Definition: box.h:98
@ BOTTOM
Definition: box.h:98
@ LEFT
Definition: box.h:98
@ RIGHT
Definition: box.h:98
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Container for border values during table border calculations.
Definition: table.c:42
Container for box border details.
Definition: box.h:104
enum css_border_style_e style
border-style
Definition: box.h:105
css_color c
border-color value
Definition: box.h:106
int width
border-width (pixels)
Definition: box.h:107
Node in box tree.
Definition: box.h:177
int descendant_y1
bottom edge of descendants
Definition: box.h:312
int list_value
List item value.
Definition: box.h:412
int min_width
Width of box taking all line breaks (including margins etc).
Definition: box.h:343
int width
Width of content box (excluding padding etc.).
Definition: box.h:289
struct box * parent
Parent box, or NULL.
Definition: box.h:236
struct scrollbar * scroll_x
Horizontal scroll.
Definition: box.h:332
lwc_string * id
value of id attribute (or name for anchors)
Definition: box.h:210
size_t byte_offset
Byte offset within a textual representation of this content.
Definition: box.h:370
struct column * col
Array of table column data for TABLE only.
Definition: box.h:407
const char * title
Title, or NULL.
Definition: box.h:386
struct box * inline_end
INLINE_END box corresponding to this INLINE box, or INLINE box corresponding to this INLINE_END box.
Definition: box.h:242
struct box * children
First child box, or NULL.
Definition: box.h:226
int height
Height of content box (excluding padding etc.).
Definition: box.h:293
struct hlcache_handle * background
Background image for this box, or NULL if none.
Definition: box.h:435
struct box * float_container
If box is a float, points to box's containing block.
Definition: box.h:261
struct box * prev
Previous sibling box, or NULL.
Definition: box.h:221
struct box * list_marker
List marker box if this is a list-item, or NULL.
Definition: box.h:417
int margin[4]
Margin: TOP, RIGHT, BOTTOM, LEFT.
Definition: box.h:317
char * usemap
(Image)map to use with this object, or NULL if none
Definition: box.h:429
int max_width
Width that would be taken with no line breaks.
Definition: box.h:349
const char * target
Link target, or NULL.
Definition: box.h:381
int clear_level
Level below which subsequent floats must be cleared.
Definition: box.h:267
struct box * next_float
Next sibling float box.
Definition: box.h:256
css_select_results * styles
Computed styles for elements and their pseudo elements.
Definition: box.h:197
struct box * last
Last child box, or NULL.
Definition: box.h:231
struct box * next
Next sibling box, or NULL.
Definition: box.h:216
int descendant_x0
left edge of descendants
Definition: box.h:309
struct scrollbar * scroll_y
Vertical scroll.
Definition: box.h:337
unsigned int start_column
Start column for TABLE_CELL only.
Definition: box.h:402
box_type type
Type of box.
Definition: box.h:181
struct nsurl * href
Link, or NULL.
Definition: box.h:376
struct box * float_children
First float child box, or NULL.
Definition: box.h:251
int descendant_x1
right edge of descendants
Definition: box.h:311
struct browser_window * iframe
Iframe's browser_window, or NULL if none.
Definition: box.h:452
css_computed_style * style
Style for this box.
Definition: box.h:205
size_t length
Length of text.
Definition: box.h:360
struct object_params * object_params
Parameters for the object, or NULL.
Definition: box.h:446
struct hlcache_handle * object
Object in this box (usually an image), or NULL if none.
Definition: box.h:441
char * text
Text, or NULL if none.
Definition: box.h:355
int padding[4]
Padding: TOP, RIGHT, BOTTOM, LEFT.
Definition: box.h:322
int x
Coordinate of left padding edge relative to parent box, or relative to ancestor that contains this bo...
Definition: box.h:280
box_flags flags
Box flags.
Definition: box.h:186
int space
Width of space after current text (depends on font and size).
Definition: box.h:365
int cached_place_below_level
Level below which floats have been placed.
Definition: box.h:272
struct form_control * gadget
Form control data, or NULL if not a form control.
Definition: box.h:423
int descendant_y0
top edge of descendants
Definition: box.h:310
unsigned int rows
Number of rows for TABLE only.
Definition: box.h:397
struct dom_node * node
DOM node that generated this box or NULL.
Definition: box.h:191
unsigned int columns
Number of columns for TABLE / TABLE_CELL.
Definition: box.h:392
int y
Coordinate of top padding edge, relative as for x.
Definition: box.h:284
Browser window data.
Table column data.
Definition: box.h:114
@ COLUMN_WIDTH_UNKNOWN
Definition: box.h:119
@ COLUMN_WIDTH_AUTO
Definition: box.h:121
@ COLUMN_WIDTH_FIXED
Definition: box.h:120
@ COLUMN_WIDTH_PERCENT
Definition: box.h:122
@ COLUMN_WIDTH_RELATIVE
Definition: box.h:123
bool positioned
Whether all of column's cells are css positioned.
Definition: box.h:145
int width
Preferred width of column.
Definition: box.h:130
int max
Maximum width of content.
Definition: box.h:140
enum column::@131 type
Type of column.
int min
Minimum width of content.
Definition: box.h:135
Content which corresponds to a single URL.
Form control.
Definition: form_internal.h:73
High-level cache handle.
Definition: hlcache.c:66
Data specific to CONTENT_HTML.
Definition: private.h:93
Linked list of object element parameters.
Definition: box.h:152
char * value
Definition: box.h:154
struct object_param * next
Definition: box.h:157
char * name
Definition: box.h:153
char * valuetype
Definition: box.h:156
char * type
Definition: box.h:155
Parameters for object element and similar elements.
Definition: box.h:164
struct nsurl * data
Definition: box.h:165
char * codetype
Definition: box.h:167
struct nsurl * classid
Definition: box.h:169
struct nsurl * codebase
Definition: box.h:168
char * type
Definition: box.h:166
struct object_param * params
Definition: box.h:170
Rectangle coordinates.
Definition: types.h:40
Scrollbar context.
Definition: scrollbar.c:44