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