summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2015-07-21 19:53:40 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2015-08-03 21:30:20 (GMT)
commit601a2cbbcbd28c4170b453e7bd476adcf1eb1266 (patch)
treed4002caeb714a8187d06660c25941460d96a557b
parent304c68b4eef1efba7ec59a89a8239e66cfb55d2a (diff)
downloadlibnslayout-601a2cbbcbd28c4170b453e7bd476adcf1eb1266.tar.gz
libnslayout-601a2cbbcbd28c4170b453e7bd476adcf1eb1266.tar.bz2
Add request callback wrappers.
-rw-r--r--src/request.h141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/request.h b/src/request.h
new file mode 100644
index 0000000..c28468e
--- a/dev/null
+++ b/src/request.h
@@ -0,0 +1,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 nslayout_request_h_
+#define nslayout_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 NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_get_resource(
+ nslayout_layout *layout,
+ const char *url,
+ nslayout_replaced **replaced)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_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 NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_create_replaced(
+ nslayout_layout *layout,
+ dom_element *element,
+ nslayout_replaced **replaced)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_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 NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_render(
+ nslayout_layout *layout,
+ nslayout_render_list *list)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_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 NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_set_extents(
+ nslayout_layout *layout,
+ unsigned int width,
+ unsigned int height)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_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 NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+static inline nslayout_error nsl_request_get_intrinsic_size(
+ nslayout_layout *layout,
+ nslayout_replaced *replaced,
+ unsigned int *width,
+ unsigned int *height)
+{
+ nslayout_error err;
+ nslayout_request req;
+
+ req.type = NSLAYOUT_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