summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2015-07-18 21:48:47 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2015-07-18 21:48:47 (GMT)
commitc721328b2ce5775a6dbee4b8f37a8c949394c8d8 (patch)
treebf2a4da32b11784ce3278286ce6a85dcfedaed1a
downloadlibnslayout-c721328b2ce5775a6dbee4b8f37a8c949394c8d8.tar.gz
libnslayout-c721328b2ce5775a6dbee4b8f37a8c949394c8d8.tar.bz2
Initial interface plan.
-rw-r--r--COPYING13
-rw-r--r--include/nslayout.c191
2 files changed, 204 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..e7d1026
--- a/dev/null
+++ b/COPYING
@@ -0,0 +1,13 @@
+Copyright (c) 2015, Michael Drake
+
+Permission to use, copy, modify, and/or distribute this software for any purpose
+with or without fee is hereby granted, provided that the above copyright notice
+and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
diff --git a/include/nslayout.c b/include/nslayout.c
new file mode 100644
index 0000000..1144e4b
--- a/dev/null
+++ b/include/nslayout.c
@@ -0,0 +1,191 @@
+/*
+ * 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>
+ */
+
+/** An opaque client-owned replaced element */
+typedef void nslayout_replaced;
+
+/** A rectangle */
+typedef struct nslayout_rect {
+ int x;
+ int y;
+ int w;
+ int h;
+} nslayout_rect;
+
+/**
+ * A LibNSLayout request
+ *
+ * Passed to the client via nslayout_callback
+ */
+typedef struct nslayout_request {
+ /** Request type */
+ enum type {
+ NSLAYOUT_GET_RESOURCE,
+ NSLAYOUT_CREATE_REPLACED,
+ NSLAYOUT_RENDER,
+ NSLAYOUT_SET_EXTENTS,
+ NSLAYOUT_GET_INTRINSIC_SIZE
+ } type;
+ /** Request's type-specific parameters */
+ union {
+ struct {
+ const char *url; /**< Absolute URL */
+ } get_resource;
+ struct {
+ dom_element *element; /**< DOM element */
+ } create_replaced;
+ struct {
+ nslayout_render_list *list; /**< Render list */
+ } render;
+ struct {
+ width; /**< Document width in px */
+ height; /**< Document height in px */
+ } set_extents;
+ struct {
+ nslayout_replaced *replaced; /** A replacement object */
+ } get_intrinsic_size;
+ } request;
+ /** Request's type-specific return values */
+ union {
+ struct {
+ nslayout_replaced **replaced; /** Replacement object */
+ } get_resource;
+ struct {
+ nslayout_replaced **replaced; /** Replacement object */
+ } create_replaced;
+ struct {
+ unsigned int *width; /** Replacement object's width */
+ unsigned int *height; /** Replacement object's height */
+ } get_intrinsic_size;
+ } response;
+} nslayout_request;
+
+/**
+ * Initialise LibNSLayout
+ *
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_init(void);
+
+/**
+ * Finalise LibNSLayout
+ *
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_fini(void);
+
+/**
+ * LibNSLayout client callback function
+ *
+ * \param req The request details.
+ * \param layout The layout we're making a request for.
+ * \param pw The client's private data for this layout.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+typedef nslayout_error (*nslayout_callback)(
+ nslayout_request *req,
+ nslayout_layout *layout,
+ void *pw);
+
+/**
+ * Create a Layout object for a given DOM
+ *
+ * \param doc The LibDOM document to build a layout for.
+ * \param css_ctx The LibCSS selection context for the document.
+ * \param media The LibCSS media to use when selecting for this layout.
+ * \param cb The client's private data for this layout.
+ * \param pw The client's private data for this layout.
+ * \param layout Returns a pointer to the created layout object.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_layout_create(
+ dom_document *doc,
+ css_select_ctx *css_ctx,
+ css_media_type *media,
+ nslayout_callback *cb;
+ void *pw,
+ nslayout_layout **layout);
+
+/**
+ * Destroy a Layout object
+ *
+ * \param layout Returns a pointer to the created layout object.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_layout_destroy(
+ nslayout_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 layout Layout to set viewport for.
+ * \param viewport Viewport dimensions and offset.
+ * \param scale Rendering scale.
+ * \param dpi DPI of render target with viewport.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_update_viewport(
+ nslayout_layout *layout,
+ nslayout_rect *viewport,
+ css_fixed scale
+ int dpi);
+
+/**
+ * Find the top-most element at a given point, in terms of z-order.
+ *
+ * \param layout Layout to locate an element in.
+ * \param element Updated to area with position relative to viewport.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_element_get_location(
+ nslayout_layout *layout,
+ nslayout_rect *area);
+
+/**
+ * Find the top-most element at a given point, in terms of z-order.
+ *
+ * \param layout Layout to find an element in.
+ * \param x Mouse x-coordinate (viewport relative).
+ * \param y Mouse y-coordinate (viewport relative).
+ * \param element Updated to point at the element we found.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_element_at_point(
+ nslayout_layout *layout,
+ unsigned int x,
+ unsigned int y,
+ dom_event_target **element);
+
+/**
+ * Mark an element (or part of it) as needing redraw.
+ *
+ * \param layout Layout to indicate redraw is required for.
+ * \param element Element to mark as needing redraw.
+ * \param rel_area Area of element to redraw relative to object's top-left.
+ * May be NULL, to redraw whole element.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_layout_dirty_element(
+ nslayout_layout *layout,
+ dom_element *element,
+ nslayout_rect *rel_area);
+
+/**
+ * Mark an area as needing redraw.
+ *
+ * \param layout Layout to indicate redraw is required for.
+ * \param area Area to redraw relative to viewport's top-left.
+ * \return NSLAYOUT_OK on success, appropriate error otherwise.
+ */
+nslayout_error nslayout_layout_dirty_area(
+ nslayout_layout *layout,
+ nslayout_rect *area);
+