NetSurf
box_inspect.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 inspection interface.
22 */
23
24#ifndef NETSURF_HTML_BOX_INSPECT_H
25#define NETSURF_HTML_BOX_INSPECT_H
26
27/**
28 * Find the absolute coordinates of a box.
29 *
30 * \param box the box to calculate coordinates of
31 * \param x updated to x coordinate
32 * \param y updated to y coordinate
33 */
34void box_coords(struct box *box, int *x, int *y);
35
36
37/**
38 * Find the bounds of a box.
39 *
40 * \param box the box to calculate bounds of
41 * \param r receives bounds
42 */
43void box_bounds(struct box *box, struct rect *r);
44
45
46/**
47 * Find the boxes at a point.
48 *
49 * \param unit_len_ctx CSS length conversion context for document.
50 * \param box box to search children of
51 * \param x point to find, in global document coordinates
52 * \param y point to find, in global document coordinates
53 * \param box_x position of box, in global document coordinates, updated
54 * to position of returned box, if any
55 * \param box_y position of box, in global document coordinates, updated
56 * to position of returned box, if any
57 * \return box at given point, or 0 if none found
58 *
59 * To find all the boxes in the hierarchy at a certain point, use code like
60 * this:
61 * \code
62 * struct box *box = top_of_document_to_search;
63 * int box_x = 0, box_y = 0;
64 *
65 * while ((box = box_at_point(unit_len_ctx, box, x, y, &box_x, &box_y))) {
66 * // process box
67 * }
68 * \endcode
69 */
70struct box *box_at_point(const css_unit_ctx *unit_len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
71
72
73/**
74 * Find a box based upon its id attribute.
75 *
76 * \param box box tree to search
77 * \param id id to look for
78 * \return the box or 0 if not found
79 */
80struct box *box_find_by_id(struct box *box, lwc_string *id);
81
82
83/**
84 * Determine if a box is visible when the tree is rendered.
85 *
86 * \param box box to check
87 * \return true iff the box is rendered
88 */
89bool box_visible(struct box *box);
90
91
92/**
93 * Print a box tree to a file.
94 */
95void box_dump(FILE *stream, struct box *box, unsigned int depth, bool style);
96
97
98/**
99 * Determine if a box has a vertical scrollbar.
100 *
101 * \param box scrolling box
102 * \return the box has a vertical scrollbar
103 */
104bool box_vscrollbar_present(const struct box *box);
105
106
107/**
108 * Determine if a box has a horizontal scrollbar.
109 *
110 * \param box scrolling box
111 * \return the box has a horizontal scrollbar
112 */
113bool box_hscrollbar_present(const struct box *box);
114
115
116/**
117 * Peform pick text on browser window contents to locate the box under
118 * the mouse pointer, or nearest in the given direction if the pointer is
119 * not over a text box.
120 *
121 * \param html an HTML content
122 * \param x coordinate of mouse
123 * \param y coordinate of mouse
124 * \param dir direction to search (-1 = above-left, +1 = below-right)
125 * \param dx receives x ordinate of mouse relative to text box
126 * \param dy receives y ordinate of mouse relative to text box
127 */
128struct box *box_pick_text_box(struct html_content *html, int x, int y, int dir, int *dx, int *dy);
129
130
131/**
132 * Check if layout box is a first child.
133 *
134 * \param[in] b Box to check.
135 * \return true iff box is first child.
136 */
137static inline bool box_is_first_child(struct box *b)
138{
139 return (b->parent == NULL || b == b->parent->children);
140}
141
142static inline unsigned box_count_children(const struct box *b)
143{
144 const struct box *c = b->children;
145 unsigned count = 0;
146
147 while (c != NULL) {
148 count++;
149 c = c->next;
150 }
151
152 return count;
153}
154
155#endif
static unsigned box_count_children(const struct box *b)
Definition: box_inspect.h:142
bool box_vscrollbar_present(const struct box *box)
Determine if a box has a vertical scrollbar.
Definition: box_inspect.c:829
struct box * box_at_point(const css_unit_ctx *unit_len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y)
Find the boxes at a point.
Definition: box_inspect.c:583
bool box_hscrollbar_present(const struct box *box)
Determine if a box has a horizontal scrollbar.
Definition: box_inspect.c:839
void box_coords(struct box *box, int *x, int *y)
Find the absolute coordinates of a box.
Definition: box_inspect.c:549
void box_bounds(struct box *box, struct rect *r)
Find the bounds of a box.
Definition: box_inspect.c:567
bool box_visible(struct box *box)
Determine if a box is visible when the tree is rendered.
Definition: box_inspect.c:636
struct box * box_find_by_id(struct box *box, lwc_string *id)
Find a box based upon its id attribute.
Definition: box_inspect.c:614
static bool box_is_first_child(struct box *b)
Check if layout box is a first child.
Definition: box_inspect.h:137
void box_dump(FILE *stream, struct box *box, unsigned int depth, bool style)
Print a box tree to a file.
Definition: box_inspect.c:649
struct box * box_pick_text_box(struct html_content *html, int x, int y, int dir, int *dx, int *dy)
Peform pick text on browser window contents to locate the box under the mouse pointer,...
Definition: box_inspect.c:850
static uint32_t count(const http_directive *list, lwc_string *key)
Node in box tree.
Definition: box.h:177
struct box * parent
Parent box, or NULL.
Definition: box.h:236
struct box * children
First child box, or NULL.
Definition: box.h:226
struct box * next
Next sibling box, or NULL.
Definition: box.h:216
css_computed_style * style
Style for this box.
Definition: box.h:205
int x
Coordinate of left padding edge relative to parent box, or relative to ancestor that contains this bo...
Definition: box.h:280
int y
Coordinate of top padding edge, relative as for x.
Definition: box.h:284
Data specific to CONTENT_HTML.
Definition: private.h:93
Rectangle coordinates.
Definition: types.h:40