NetSurf
box_construct.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * HTML Box tree construction interface.
22 *
23 * This stage of rendering converts a tree of dom_nodes (produced by libdom)
24 * to a tree of struct box. The box tree represents the structure of the
25 * document as given by the CSS display and float properties.
26 *
27 * For example, consider the following HTML:
28 * \code
29 * <h1>Example Heading</h1>
30 * <p>Example paragraph <em>with emphasised text</em> etc.</p> \endcode
31 *
32 * This would produce approximately the following box tree with default CSS
33 * rules:
34 * \code
35 * BOX_BLOCK (corresponds to h1)
36 * BOX_INLINE_CONTAINER
37 * BOX_INLINE "Example Heading"
38 * BOX_BLOCK (p)
39 * BOX_INLINE_CONTAINER
40 * BOX_INLINE "Example paragraph "
41 * BOX_INLINE "with emphasised text" (em)
42 * BOX_INLINE "etc." \endcode
43 *
44 * Note that the em has been collapsed into the INLINE_CONTAINER.
45 *
46 * If these CSS rules were applied:
47 * \code
48 * h1 { display: table-cell }
49 * p { display: table-cell }
50 * em { float: left; width: 5em } \endcode
51 *
52 * then the box tree would instead look like this:
53 * \code
54 * BOX_TABLE
55 * BOX_TABLE_ROW_GROUP
56 * BOX_TABLE_ROW
57 * BOX_TABLE_CELL (h1)
58 * BOX_INLINE_CONTAINER
59 * BOX_INLINE "Example Heading"
60 * BOX_TABLE_CELL (p)
61 * BOX_INLINE_CONTAINER
62 * BOX_INLINE "Example paragraph "
63 * BOX_FLOAT_LEFT (em)
64 * BOX_BLOCK
65 * BOX_INLINE_CONTAINER
66 * BOX_INLINE "with emphasised text"
67 * BOX_INLINE "etc." \endcode
68 *
69 * Here implied boxes have been added and a float is present.
70 */
71
72#ifndef NETSURF_HTML_BOX_CONSTRUCT_H
73#define NETSURF_HTML_BOX_CONSTRUCT_H
74
75/**
76 * Construct a box tree from a dom and html content
77 *
78 * \param n dom document
79 * \param c content of type CONTENT_HTML to construct box tree in
80 * \param cb callback to report conversion completion
81 * \param box_conversion_context pointer that recives the conversion context
82 * \return netsurf error code indicating status of call
83 */
84nserror dom_to_box(struct dom_node *n, struct html_content *c, box_construct_complete_cb cb, void **box_conversion_context);
85
86
87/**
88 * aborts any ongoing box construction
89 */
90nserror cancel_dom_to_box(void *box_conversion_context);
91
92
93/**
94 * Retrieve the box for a dom node, if there is one
95 *
96 * \param node The DOM node
97 * \return The box if there is one
98 */
99struct box *box_for_node(struct dom_node *node);
100
101/**
102 * Extract a URL from a relative link, handling junk like whitespace and
103 * attempting to read a real URL from "javascript:" links.
104 *
105 * \param content html content
106 * \param dsrel relative URL text taken from page
107 * \param base base for relative URLs
108 * \param result updated to target URL on heap, unchanged if extract failed
109 * \return true on success, false on memory exhaustion
110 */
111bool box_extract_link(const struct html_content *content, const struct dom_string *dsrel, struct nsurl *base, struct nsurl **result);
112
113#endif
STATIC char result[100]
Definition: arexx.c:77
void(* box_construct_complete_cb)(struct html_content *c, bool success)
Definition: box.h:49
nserror dom_to_box(struct dom_node *n, struct html_content *c, box_construct_complete_cb cb, void **box_conversion_context)
Construct a box tree from a dom and html content.
bool box_extract_link(const struct html_content *content, const struct dom_string *dsrel, struct nsurl *base, struct nsurl **result)
Extract a URL from a relative link, handling junk like whitespace and attempting to read a real URL f...
struct box * box_for_node(struct dom_node *node)
Retrieve the box for a dom node, if there is one.
nserror cancel_dom_to_box(void *box_conversion_context)
aborts any ongoing box construction
nserror
Enumeration of error codes.
Definition: errors.h:29
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
@ base
Definition: punycode.c:19
Node in box tree.
Definition: box.h:177
struct dom_node * node
DOM node that generated this box or NULL.
Definition: box.h:191
Content which corresponds to a single URL.
Data specific to CONTENT_HTML.
Definition: private.h:93