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
|
/*
* 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/dom/watcher.h
* Interface to DOM mutation watching.
*/
#ifndef nslayout_dom_watcher_h_
#define nslayout_dom_watcher_h_
struct dom_document;
struct nsl_dom_watcher;
/**
* DOM watcher's mutation types
*/
enum nsl_dom_watcher_type {
NSL_DOM_WATCHER_NODE_INSERTED,
NSL_DOM_WATCHER_NODE_REMOVED,
NSL_DOM_WATCHER_SUBTREE_MODIFIED,
NSL_DOM_WATCHER_ATTR_MODIFIED,
NSL_DOM_WATCHER_CHAR_DATA_MODIFIED,
NSL_DOM_WATCHER__COUNT,
};
/**
* Callback function for dom modifications.
*
* \param[in] type The mutation type.
* \param[in] node The target node. (Caller yields ownership.)
* \param[in] node_type The type of node.
* \param[in] pw The dom watcher owner's private data.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
typedef nslayout_error (*nsl_dom_watcher_cb)(
enum nsl_dom_watcher_type type,
dom_event_target *node,
dom_node_type node_type,
void *pw);
/**
* Create DOM change watcher for a DOM document.
*
* \param[out] watcher_out Returns a dom watcher object for layout.
* \param[in] document DOM document to create watcher for.
* \param[in] watcher_cb Function to call when dom modification happens.
* \param[in] pw Private data passed back to `watcher_cb`.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nsl_dom_watcher_create(
struct nsl_dom_watcher **watcher_out,
dom_document *document,
nsl_dom_watcher_cb watcher_cb,
void *pw);
/**
* Destroy a document change DOM change watcher.
*
* \param[in] watcher DOM change watcher to destroy.
* \return NSLAYOUT_OK on success, appropriate error otherwise.
*/
nslayout_error nsl_dom_watcher_destroy(
struct nsl_dom_watcher *watcher);
#endif
|