1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/*
* This file is part of LibNSLayout
* Licensed under the ISC License, http://opensource.org/licenses/ISC
* Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
* Copyright 2015 John-Mark Bell <jmb@netsurf-browser.org>
*/
/** \file include/libnslayout/nslayout.h
* Layout object handling
*/
#ifndef nsl_nslayout_h_
#define nsl_nslayout_h_
#ifdef __cplusplus
extern "C"
{
#endif
#include <libcss/libcss.h>
#include <dom/dom.h>
#include <libnslayout/error.h>
/** A client-defined replaced element structure */
typedef struct nsl_replaced nsl_replaced;
/** A rectangle */
typedef struct nsl_rect {
int x; /**< X position of left of rect in px */
int y; /**< Y position of top of rect in px */
int w; /**< Width of rect in px */
int h; /**< Height of rect in px */
} nsl_rect;
/***/
enum nsl_dom_node_event_type {
NSL_DOM_NODE_INSERTED,
NSL_DOM_NODE_MODIFIED,
NSL_DOM_NODE_REMOVED,
NSL_DOM_NODE__COUNT,
};
/** Render list */
typedef struct nsl_render_list {
} nsl_render_list;
/** Opaque layout tree object */
typedef struct nsl_layout nsl_layout;
/**
* A LibNSLayout request
* Client calls to set replaced element intrinsic dimensions.
*
* Passed to the client via nsl_callback
*/
typedef struct nsl_request {
/** Request type */
enum {
NSL_GET_RESOURCE,
NSL_RENDER,
NSL_SET_EXTENTS,
NSL_GET_INTRINSIC_SIZE
} type;
/** Request's type-specific parameters */
union {
struct {
const char *url; /**< Absolute URL */
} get_resource;
struct {
nsl_render_list *list; /**< Render list */
} render;
struct {
unsigned int width; /**< Document width in px */
unsigned int height; /**< Document height in px */
} set_extents;
struct {
nsl_replaced *replaced; /** A replacement object */
} get_intrinsic_size;
} request;
/** Request's type-specific return values */
union {
struct {
nsl_replaced **replaced; /** Replacement object */
} get_resource;
struct {
unsigned int *width; /** Replacement object's width */
unsigned int *height; /** Replacement object's height */
} get_intrinsic_size;
} response;
} nsl_request;
/**
* Client calls for DOM tree change events.
*
* \param[in] layout The layout requiring update for DOM change.
* \param[in] node The DOM node which is concerned in the event.
* \param[in] type The type of DOM change event.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_dom_node_event(
nsl_layout *layout,
dom_event_target *node,
enum nsl_dom_node_event_type type);
/**
* Client calls to set node as client-replaced.
*
* \param[in] layout The layout to replace an element in.
* \param[in] node The DOM node which is to be replaced.
* \param[in] replaced The client's replacement object to register with node.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_node_event_set_replaced(
nsl_layout *layout,
dom_event_target *node,
nsl_replaced *replaced);
/**
* Client calls to set replaced element intrinsic dimensions.
*
* \param[in] layout The layout to replace an element in.
* \param[in] node The DOM node which is to be replaced.
* \param[in] width Width in pixels.
* \param[in] height Height in pixels.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_node_event_set_intrinsic_dimensions(
nsl_layout *layout,
dom_event_target *node,
unsigned int width,
unsigned int height);
/**
* Client calls to tell NSLayout that everything requires reselection.
*
* \param[in] layout The layout to who's selection context has changed.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_selection_context_updated(
nsl_layout *layout);
/**
* Initialise LibNSLayout
*
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_init(void);
/**
* Finalise LibNSLayout
*
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_fini(void);
/**
* LibNSLayout client callback function
*
* \param[in] layout The layout we're making a request for.
* \param[in] pw The client's private data for this layout.
* \param[in,out] req The request details.
* \return NSL_OK on success, appropriate error otherwise.
*/
typedef nsl_error (*nsl_callback)(
nsl_layout *layout,
void *pw,
nsl_request *req);
/**
* Create a Layout object for a given DOM
*
* \param[in] doc The LibDOM document to build a layout for.
* \param[in] css_ctx The LibCSS selection context for the document.
* \param[in] media The LibCSS media to use when selecting.
* \param[in] cb The client's private data for this layout.
* \param[in] pw The client's private data for this layout.
* \param[out] layout Returns a pointer to the created layout object.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_create(
dom_document *doc,
css_select_ctx *css_ctx,
css_media_type *media,
nsl_callback cb,
void *pw,
nsl_layout **layout);
/**
* Destroy a Layout object
*
* \param[in] layout Returns a pointer to the created layout object.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_destroy(
nsl_layout *layout);
/**
* Update the viewport for a layout
*
* Note: Before this is called, the layout engine will create internal
* data structures for the document, but will not start to position
* things and will not emit render lists.
*
* \param[in] layout Layout to set viewport for.
* \param[in] viewport Viewport dimensions and offset.
* \param[in] scale Rendering scale.
* \param[in] dpi DPI of render target with viewport.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_update_viewport(
nsl_layout *layout,
nsl_rect *viewport,
css_fixed scale,
unsigned int dpi);
/**
* Find the area occupied by element.
*
* \param[in] layout Layout to locate an element in.
* \param[in] element Element to get area of.
* \param[out] area Returns area with position relative to viewport.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_element_get_location(
nsl_layout *layout,
dom_element *element,
nsl_rect *area);
/**
* Find the top-most element at a given point, in terms of z-order.
*
* \param[in] layout Layout to find an element in.
* \param[in] x Mouse x-coordinate (viewport relative).
* \param[in] y Mouse y-coordinate (viewport relative).
* \param[out] element Returns the element we found.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_element_at_point(
nsl_layout *layout,
unsigned int x,
unsigned int y,
dom_event_target **element);
/**
* Mark an element (or part of it) as needing redraw.
*
* \param[in] layout Layout to indicate redraw is required for.
* \param[in] element Element to mark as needing redraw.
* \param[in] rel_area Area of element to redraw relative to object's top-left.
* May be NULL, to redraw whole element.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_dirty_element(
nsl_layout *layout,
dom_element *element,
nsl_rect *rel_area);
/**
* Mark an area as needing redraw.
*
* \param[in] layout Layout to indicate redraw is required for.
* \param[in] area Area to redraw relative to viewport's top-left.
* \return NSL_OK on success, appropriate error otherwise.
*/
nsl_error nsl_layout_dirty_area(
nsl_layout *layout,
nsl_rect *area);
#ifdef __cplusplus
}
#endif
#endif
|