libdom
Loading...
Searching...
No Matches
node.h
Go to the documentation of this file.
1/*
2 * This file is part of libdom.
3 * Licensed under the MIT License,
4 * http://www.opensource.org/licenses/mit-license.php
5 * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
6 */
7
8#ifndef dom_internal_core_node_h_
9#define dom_internal_core_node_h_
10
11#include <stdbool.h>
12
13#include <libwapcaplet/libwapcaplet.h>
14
15#include <dom/core/node.h>
16#include <dom/functypes.h>
17
18#include "events/event_target.h"
19#include "events/mutation_event.h"
20
21#include "utils/list.h"
22
35
48
80
82
84 struct dom_document *doc, dom_node_type type,
85 dom_string *name, dom_string *value,
86 dom_string *namespace, dom_string *prefix);
87
89
92
93/* Event Target implementation */
95 dom_string *type, struct dom_event_listener *listener,
96 bool capture);
98 dom_string *type, struct dom_event_listener *listener,
99 bool capture);
101 dom_string *namespace, dom_string *type,
102 struct dom_event_listener *listener, bool capture);
104 dom_string *namespace, dom_string *type,
105 struct dom_event_listener *listener, bool capture);
107 struct dom_event *evt, bool *success);
108
109/* The DOM Node's vtable methods */
111 dom_string **result);
113 dom_string **result);
115 dom_string *value);
117 dom_node_type *result);
119 dom_node_internal **result);
121 struct dom_nodelist **result);
123 dom_node_internal **result);
125 dom_node_internal **result);
127 dom_node_internal **result);
129 dom_node_internal **result);
131 struct dom_namednodemap **result);
133 struct dom_document **result);
135 dom_node_internal *new_child, dom_node_internal *ref_child,
136 dom_node_internal **result);
138 dom_node_internal *new_child, dom_node_internal *old_child,
139 dom_node_internal **result);
141 dom_node_internal *old_child,
142 dom_node_internal **result);
144 dom_node_internal *new_child,
145 dom_node_internal **result);
148 dom_node_internal **result);
151 dom_string *feature, dom_string *version,
152 bool *result);
154 dom_string **result);
156 dom_string **result);
158 dom_string *prefix);
160 dom_string **result);
163 dom_string **result);
165 dom_node_internal *other, uint16_t *result);
167 dom_string **result);
169 dom_string *content);
171 dom_node_internal *other, bool *result);
173 dom_string *namespace, dom_string **result);
175 dom_string *namespace, bool *result);
177 dom_string *prefix, dom_string **result);
179 dom_node_internal *other, bool *result);
181 dom_string *feature, dom_string *version,
182 void **result);
184 dom_string *key, void *data,
185 dom_user_data_handler handler, void **result);
187 const dom_string *key, void **result);
188
189#define DOM_NODE_EVENT_TARGET_VTABLE \
190 _dom_node_add_event_listener, \
191 _dom_node_remove_event_listener, \
192 _dom_node_dispatch_event, \
193 _dom_node_add_event_listener_ns, \
194 _dom_node_remove_event_listener_ns
195
196#define DOM_NODE_VTABLE \
197 _dom_node_try_destroy, \
198 _dom_node_get_node_name, \
199 _dom_node_get_node_value, \
200 _dom_node_set_node_value, \
201 _dom_node_get_node_type, \
202 _dom_node_get_parent_node, \
203 _dom_node_get_child_nodes, \
204 _dom_node_get_first_child, \
205 _dom_node_get_last_child, \
206 _dom_node_get_previous_sibling, \
207 _dom_node_get_next_sibling, \
208 _dom_node_get_attributes, \
209 _dom_node_get_owner_document, \
210 _dom_node_insert_before, \
211 _dom_node_replace_child, \
212 _dom_node_remove_child, \
213 _dom_node_append_child, \
214 _dom_node_has_child_nodes, \
215 _dom_node_clone_node, \
216 _dom_node_normalize, \
217 _dom_node_is_supported, \
218 _dom_node_get_namespace, \
219 _dom_node_get_prefix, \
220 _dom_node_set_prefix, \
221 _dom_node_get_local_name, \
222 _dom_node_has_attributes, \
223 _dom_node_get_base, \
224 _dom_node_compare_document_position, \
225 _dom_node_get_text_content, \
226 _dom_node_set_text_content, \
227 _dom_node_is_same, \
228 _dom_node_lookup_prefix, \
229 _dom_node_is_default_namespace, \
230 _dom_node_lookup_namespace, \
231 _dom_node_is_equal, \
232 _dom_node_get_feature, \
233 _dom_node_set_user_data, \
234 _dom_node_get_user_data
235
236
237/* Following comes the protected vtable */
238void _dom_node_destroy(struct dom_node_internal *node);
240 struct dom_node_internal **copy);
241
242#define DOM_NODE_PROTECT_VTABLE \
243 _dom_node_destroy, \
244 _dom_node_copy
245
246
247/* The destroy API should be used inside DOM module */
248static inline void dom_node_destroy(struct dom_node_internal *node)
249{
250 ((dom_node_protect_vtable *) node->vtable)->destroy(node);
251}
252#define dom_node_destroy(n) dom_node_destroy((dom_node_internal *) (n))
253
254/* Copy the Node old to new */
255static inline dom_exception dom_node_copy(struct dom_node_internal *old,
256 struct dom_node_internal **copy)
257{
258 return ((dom_node_protect_vtable *) old->vtable)->copy(old, copy);
259}
260#define dom_node_copy(o,c) dom_node_copy((dom_node_internal *) (o), \
261 (dom_node_internal **) (c))
262
263/* Following are some helper functions */
265 dom_node_internal *new);
266#define dom_node_copy_internal(o, n) _dom_node_copy_internal( \
267 (dom_node_internal *) (o), (dom_node_internal *) (n))
268
269#define dom_node_get_owner(n) ((dom_node_internal *) (n))->owner
270
271#define dom_node_set_owner(n, d) ((dom_node_internal *) (n))->owner = \
272 (struct dom_document *) (d)
273
274#define dom_node_get_parent(n) ((dom_node_internal *) (n))->parent
275
276#define dom_node_set_parent(n, p) ((dom_node_internal *) (n))->parent = \
277 (dom_node_internal *) (p)
278
279#define dom_node_get_refcount(n) ((dom_node_internal *) (n))->refcnt
280
283
284/* Try to destroy the node, if its refcnt is not zero, then append it to the
285 * owner document's pending list */
287
288/* To add some node to the pending list */
290#define dom_node_mark_pending(n) _dom_node_mark_pending(\
291 (dom_node_internal *) (n))
292/* To remove the node from the pending list, this may happen when
293 * a node is removed and then appended to another parent */
295#define dom_node_remove_pending(n) _dom_node_remove_pending(\
296 (dom_node_internal *) (n))
297
299 dom_node_internal *node, dom_node_internal *related,
300 dom_mutation_type change, bool *success);
301#define dom_node_dispatch_node_change_event( \
302 doc, node, related, change, success) \
303 _dom_node_dispatch_node_change_event((dom_document *) (doc), \
304 (dom_node_internal *) (node), \
305 (dom_node_internal *) (related), \
306 (dom_mutation_type) (change), \
307 (bool *) (success))
308
309#endif
dom_exception
Definition exceptions.h:24
void(* dom_user_data_handler)(dom_node_operation operation, dom_string *key, void *data, struct dom_node *src, struct dom_node *dst)
Definition node.h:49
dom_node_type
Definition node.h:56
dom_mutation_type
Definition mutation_event.h:17
dom_exception _dom_node_remove_child(dom_node_internal *node, dom_node_internal *old_child, dom_node_internal **result)
Definition node.c:966
dom_exception _dom_node_get_text_content(dom_node_internal *node, dom_string **result)
Definition node.c:1454
dom_exception _dom_node_set_user_data(dom_node_internal *node, dom_string *key, void *data, dom_user_data_handler handler, void **result)
Definition node.c:1779
bool _dom_node_readonly(const dom_node_internal *node)
Definition node.c:2054
dom_exception _dom_node_initialise(struct dom_node_internal *node, struct dom_document *doc, dom_node_type type, dom_string *name, dom_string *value, dom_string *namespace, dom_string *prefix)
Definition node.c:146
dom_exception _dom_node_is_default_namespace(dom_node_internal *node, dom_string *namespace, bool *result)
Definition node.c:1593
dom_exception _dom_node_add_event_listener_ns(dom_event_target *et, dom_string *namespace, dom_string *type, struct dom_event_listener *listener, bool capture)
Definition node.c:2394
dom_exception _dom_merge_adjacent_text(dom_node_internal *p, dom_node_internal *n)
Definition node.c:2279
dom_exception _dom_node_is_equal(dom_node_internal *node, dom_node_internal *other, bool *result)
Definition node.c:1647
bool _dom_node_readonly_owner(const dom_node_internal *node)
Definition node.c:2027
dom_exception _dom_node_get_base(dom_node_internal *node, dom_string **result)
Definition node.c:1404
void _dom_node_destroy(struct dom_node_internal *node)
Definition node.c:101
dom_exception _dom_node_lookup_prefix(dom_node_internal *node, dom_string *namespace, dom_string **result)
Definition node.c:1574
dom_exception _dom_node_get_previous_sibling(dom_node_internal *node, dom_node_internal **result)
Definition node.c:595
dom_exception _dom_node_get_first_child(dom_node_internal *node, dom_node_internal **result)
Definition node.c:549
void _dom_node_mark_pending(dom_node_internal *node)
Definition node.c:2336
dom_exception _dom_node_get_user_data(const dom_node_internal *node, const dom_string *key, void **result)
Definition node.c:1848
dom_exception _dom_node_has_child_nodes(dom_node_internal *node, bool *result)
Definition node.c:1048
dom_exception _dom_node_get_namespace(dom_node_internal *node, dom_string **result)
Definition node.c:1243
dom_exception _dom_node_has_attributes(dom_node_internal *node, bool *result)
Definition node.c:1382
dom_exception _dom_node_try_destroy(dom_node_internal *node)
Definition node.c:2312
#define dom_node_destroy(n)
Definition node.h:252
dom_exception _dom_node_set_prefix(dom_node_internal *node, dom_string *prefix)
Definition node.c:1305
dom_exception _dom_node_set_text_content(dom_node_internal *node, dom_string *content)
Definition node.c:1497
dom_exception _dom_node_replace_child(dom_node_internal *node, dom_node_internal *new_child, dom_node_internal *old_child, dom_node_internal **result)
Definition node.c:868
dom_exception _dom_node_get_feature(dom_node_internal *node, dom_string *feature, dom_string *version, void **result)
Definition node.c:1751
dom_exception _dom_node_clone_node(dom_node_internal *node, bool deep, dom_node_internal **result)
Definition node.c:1099
dom_exception _dom_node_is_same(dom_node_internal *node, dom_node_internal *other, bool *result)
Definition node.c:1554
dom_exception _dom_node_append_child(dom_node_internal *node, dom_node_internal *new_child, dom_node_internal **result)
Definition node.c:1033
dom_exception _dom_node_copy(struct dom_node_internal *old, struct dom_node_internal **copy)
Definition node.c:1873
void _dom_node_remove_pending(dom_node_internal *node)
Definition node.c:2358
dom_exception _dom_node_add_event_listener(dom_event_target *et, dom_string *type, struct dom_event_listener *listener, bool capture)
Definition node.c:2374
dom_exception _dom_node_get_owner_document(dom_node_internal *node, struct dom_document **result)
Definition node.c:674
dom_exception _dom_node_get_prefix(dom_node_internal *node, dom_string **result)
Definition node.c:1268
dom_exception _dom_node_is_supported(dom_node_internal *node, dom_string *feature, dom_string *version, bool *result)
Definition node.c:1216
dom_exception _dom_node_get_local_name(dom_node_internal *node, dom_string **result)
Definition node.c:1354
dom_exception _dom_node_lookup_namespace(dom_node_internal *node, dom_string *prefix, dom_string **result)
Definition node.c:1615
dom_exception _dom_node_insert_before(dom_node_internal *node, dom_node_internal *new_child, dom_node_internal *ref_child, dom_node_internal **result)
Definition node.c:725
dom_exception _dom_node_normalize(dom_node_internal *node)
Definition node.c:1168
#define dom_node_copy(o, c)
Definition node.h:260
void _dom_node_finalise(dom_node_internal *node)
Definition node.c:221
dom_exception _dom_node_get_node_value(dom_node_internal *node, dom_string **result)
Definition node.c:409
dom_node_internal * _dom_node_create(void)
Definition node.c:76
dom_exception _dom_node_get_node_name(dom_node_internal *node, dom_string **result)
Definition node.c:342
dom_exception _dom_node_remove_event_listener(dom_event_target *et, dom_string *type, struct dom_event_listener *listener, bool capture)
Definition node.c:2384
dom_exception _dom_node_get_child_nodes(dom_node_internal *node, struct dom_nodelist **result)
Definition node.c:524
dom_exception _dom_node_set_node_value(dom_node_internal *node, dom_string *value)
Definition node.c:433
dom_exception _dom_node_compare_document_position(dom_node_internal *node, dom_node_internal *other, uint16_t *result)
Definition node.c:1428
dom_exception _dom_node_dispatch_event(dom_event_target *et, struct dom_event *evt, bool *success)
Definition node.c:2480
dom_exception _dom_node_get_parent_node(dom_node_internal *node, dom_node_internal **result)
Definition node.c:496
dom_exception _dom_node_remove_event_listener_ns(dom_event_target *et, dom_string *namespace, dom_string *type, struct dom_event_listener *listener, bool capture)
Definition node.c:2404
dom_exception _dom_node_get_node_type(dom_node_internal *node, dom_node_type *result)
Definition node.c:477
dom_exception _dom_node_get_last_child(dom_node_internal *node, dom_node_internal **result)
Definition node.c:572
dom_exception _dom_node_get_next_sibling(dom_node_internal *node, dom_node_internal **result)
Definition node.c:624
dom_exception _dom_node_dispatch_node_change_event(dom_document *doc, dom_node_internal *node, dom_node_internal *related, dom_mutation_type change, bool *success)
Definition node.c:2664
dom_exception _dom_node_copy_internal(dom_node_internal *old, dom_node_internal *new)
Definition node.c:1893
dom_exception _dom_node_get_attributes(dom_node_internal *node, struct dom_namednodemap **result)
Definition node.c:654
Definition document.h:43
Definition event_listener.h:18
Definition event_target.h:36
Definition event_target.h:20
Definition event.h:27
Definition namednodemap.c:26
Definition node.h:54
dom_string * value
Definition node.h:61
struct dom_document * owner
Definition node.h:69
dom_node_internal * parent
Definition node.h:63
dom_node_internal * first_child
Definition node.h:64
const void * vtable
Definition node.h:56
dom_node_type type
Definition node.h:62
dom_node_internal * last_child
Definition node.h:65
struct list_entry pending_list
Definition node.h:76
dom_string * prefix
Definition node.h:71
dom_node_internal * next
Definition node.h:67
dom_node_internal * previous
Definition node.h:66
struct dom_node base
Definition node.h:55
dom_string * name
Definition node.h:58
dom_event_target_internal eti
Definition node.h:78
struct dom_user_data * user_data
Definition node.h:74
Definition node.h:39
void(* destroy)(dom_node_internal *n)
Definition node.h:41
dom_exception(* copy)(dom_node_internal *old, dom_node_internal **copy)
Definition node.h:44
Definition node.h:79
Definition nodelist.c:26
Definition string.h:19
Definition node.h:26
dom_user_data_handler handler
Definition node.h:29
void * data
Definition node.h:28
struct dom_user_data * next
Definition node.h:31
dom_string * key
Definition node.h:27
struct dom_user_data * prev
Definition node.h:32
Definition list.h:17