/* * This file is part of LibNSLayout * Licensed under the ISC License, http://opensource.org/licenses/ISC * Copyright 2015 Michael Drake * Copyright 2015 John-Mark Bell */ /** \file include/libnslayout/nslayout.h * Layout object handling */ #ifndef nslayout_nslayout_h_ #define nslayout_nslayout_h_ #ifdef __cplusplus extern "C" { #endif #include #include #include /** A client-defined replaced element structure */ typedef struct nslayout_replaced nslayout_replaced; /** A rectangle */ typedef struct nslayout_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 */ } nslayout_rect; /***/ enum nslayout_dom_node_event_type { NSLAYOUT_DOM_NODE_INSERTED, NSLAYOUT_DOM_NODE_MODIFIED, NSLAYOUT_DOM_NODE_REMOVED, NSLAYOUT_DOM_NODE__COUNT, }; /** Render list */ typedef struct nslayout_render_list { } nslayout_render_list; /** Opaque layout tree object */ typedef struct nslayout_layout nslayout_layout; /** * A LibNSLayout request * Client calls to set replaced element intrinsic dimensions. * * Passed to the client via nslayout_callback */ typedef struct nslayout_request { /** Request type */ enum { NSLAYOUT_GET_RESOURCE, 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 { nslayout_render_list *list; /**< Render list */ } render; struct { unsigned int width; /**< Document width in px */ unsigned int 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 { unsigned int *width; /** Replacement object's width */ unsigned int *height; /** Replacement object's height */ } get_intrinsic_size; } response; } nslayout_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 NSLAYOUT_OK on success, appropriate error otherwise. */ nslayout_error nslayout_dom_node_event( nslayout_layout *layout, dom_event_target *node, enum nslayout_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 NSLAYOUT_OK on success, appropriate error otherwise. */ nslayout_error nslayout_node_event_set_replaced( nslayout_layout *layout, dom_event_target *node, nslayout_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 NSLAYOUT_OK on success, appropriate error otherwise. */ nslayout_error nslayout_node_event_set_intrinsic_dimensions( nslayout_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 NSLAYOUT_OK on success, appropriate error otherwise. */ nslayout_error nslayout_selection_context_updated( nslayout_layout *layout); /** * 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[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 NSLAYOUT_OK on success, appropriate error otherwise. */ typedef nslayout_error (*nslayout_callback)( nslayout_layout *layout, void *pw, nslayout_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 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[in] 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[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 NSLAYOUT_OK on success, appropriate error otherwise. */ nslayout_error nslayout_update_viewport( nslayout_layout *layout, nslayout_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 NSLAYOUT_OK on success, appropriate error otherwise. */ nslayout_error nslayout_element_get_location( nslayout_layout *layout, dom_element *element, nslayout_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 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[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 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[in] layout Layout to indicate redraw is required for. * \param[in] 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); #ifdef __cplusplus } #endif #endif