/* * This file is part of LibNSLayout * Licensed under the ISC License, http://opensource.org/licenses/ISC * Copyright 2015 Michael Drake */ /** \file src/layout.c * Layout object handling */ #include #include #include #include "layout.h" #include "dom/watcher.h" #include "util/dom-str.h" /** * The layout object for a DOM document */ struct nslayout_layout { dom_document *document; css_select_ctx *css_ctx; css_media_type *media; nslayout_callback cb; void *pw; struct nsl_dom_watcher *watcher; }; /* Publically exported function, documented in include/libnslayout/nslayout.h */ nslayout_error nslayout_init(void) { return nsl_dom_str_init(); } /* Publically exported function, documented in include/libnslayout/nslayout.h */ nslayout_error nslayout_fini(void) { return nsl_dom_str_fini(); } /* Publically exported function, documented in include/libnslayout/nslayout.h */ 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) { nslayout_layout *l = NULL; nslayout_error err; assert(doc != NULL); assert(css_ctx != NULL); assert(media != NULL); assert(cb != NULL); l = calloc(1, sizeof(nslayout_layout)); if (l == NULL) { return NSLAYOUT_NO_MEM; } /* TODO: Decide: ownership will probably be passed to libnslayout */ l->document = doc; l->css_ctx = css_ctx; l->media = media; l->cb = cb; l->pw = pw; err = nsl_dom_watcher_create(&l->watcher, l->document); if (err != NSLAYOUT_OK) { return err; } *layout = l; return NSLAYOUT_OK; } /* Publically exported function, documented in include/libnslayout/nslayout.h */ nslayout_error nslayout_layout_destroy( nslayout_layout *layout) { nslayout_error err; assert(layout != NULL); /* TODO: free/unref the stuff we own in the layout */ err = nsl_dom_watcher_destroy(layout->watcher); if (err != NSLAYOUT_OK) { return err; } free(layout); return NSLAYOUT_OK; }