summaryrefslogtreecommitdiff
path: root/src/request.h
blob: ea151478286719e9877c4dc232e0973433e6f566 (plain)
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
/*
 * This file is part of LibNSLayout
 * Licensed under the ISC License, http://opensource.org/licenses/ISC
 * Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
 */

/** \file src/request.h
 * Client callback wrappers
 */

#ifndef nsl_request_h_
#define nsl_request_h_

#include <libnslayout/nslayout.h>

/**
 * Perform GET_RESOURCE client callback
 *
 * \param[in]  layout    Layout object that the request concerns.
 * \param[in]  url       Absolute URL to request replaced object handle for.
 * \param[out] replaced  Returns the replaced element content handle.
 * \return NSL_OK on success, appropriate error otherwise.
 */
static inline nsl_error nsl_request_get_resource(
		nsl_layout *layout,
		const char *url,
		nsl_replaced **replaced)
{
	nsl_error err;
	nsl_request req;

	req.type = NSL_GET_RESOURCE;
	req.request.get_resource.url = url;

	err = layout->cb(layout, layout->pw, &req);

	*replaced = *req.response.get_resource.replaced;
	return err;
}

/**
 * Perform CREATE_REPLACED client callback
 *
 * \param[in]  layout    Layout object that the request concerns.
 * \param[in]  element   DOM element that needs replacement object.
 * \param[out] replaced  Returns the replaced element content handle.
 * \return NSL_OK on success, appropriate error otherwise.
 */
static inline nsl_error nsl_request_create_replaced(
		nsl_layout *layout,
		dom_element *element,
		nsl_replaced **replaced)
{
	nsl_error err;
	nsl_request req;

	req.type = NSL_CREATE_REPLACED;
	req.request.create_replaced.element = element;

	err = layout->cb(layout, layout->pw, &req);

	*replaced = *req.response.create_replaced.replaced;
	return err;
}

/**
 * Perform RENDER client callback
 *
 * \param[in] layout  Layout object being rendered.
 * \param[in] list    Render list to render.
 * \return NSL_OK on success, appropriate error otherwise.
 */
static inline nsl_error nsl_request_render(
		nsl_layout *layout,
		nsl_render_list *list)
{
	nsl_error err;
	nsl_request req;

	req.type = NSL_RENDER;
	req.request.render.list = list;

	err = layout->cb(layout, layout->pw, &req);

	return err;
}

/**
 * Perform SET_EXTENTS client callback
 *
 * \param[in] layout  Layout object that the request concerns.
 * \param[in] width   The layout's full width.
 * \param[in] height  The layout's full height.
 * \return NSL_OK on success, appropriate error otherwise.
 */
static inline nsl_error nsl_request_set_extents(
		nsl_layout *layout,
		unsigned int width,
		unsigned int height)
{
	nsl_error err;
	nsl_request req;

	req.type = NSL_SET_EXTENTS;
	req.request.set_extents.width  = width;
	req.request.set_extents.height = height;

	err = layout->cb(layout, layout->pw, &req);

	return err;
}

/**
 * Perform GET_INTRINSIC_SIZE client callback
 *
 * \param[in]  layout    Layout object that the request concerns.
 * \param[in]  replaced  Replaced object to get intrinsic size of.
 * \param[out] width     Returns the replaced object's width.
 * \param[out] height    Returns the replaced object's height.
 * \return NSL_OK on success, appropriate error otherwise.
 */
static inline nsl_error nsl_request_get_intrinsic_size(
		nsl_layout *layout,
		nsl_replaced *replaced,
		unsigned int *width,
		unsigned int *height)
{
	nsl_error err;
	nsl_request req;

	req.type = NSL_GET_INTRINSIC_SIZE;
	req.request.get_intrinsic_size.replaced = replaced;

	err = layout->cb(layout, layout->pw, &req);

	*width  = *req.response.get_intrinsic_size.width;
	*height = *req.response.get_intrinsic_size.height;
	return err;
}

#endif