summaryrefslogtreecommitdiff
path: root/src/core/document.h
blob: a2b18010d2908b9abddeb5d57ef286e7e8ae9b84 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
 * This file is part of libdom.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef dom_internal_core_document_h_
#define dom_internal_core_document_h_

#include <inttypes.h>
#include <stddef.h>

#include <dom/core/node.h>
#include <dom/core/attr.h>
#include <dom/core/cdatasection.h>
#include <dom/core/comment.h>
#include <dom/core/document.h>
#include <dom/core/document_type.h>
#include <dom/core/doc_fragment.h>
#include <dom/core/element.h>
#include <dom/core/entity_ref.h>
#include <dom/core/pi.h>
#include <dom/core/text.h>
#include <dom/core/implementation.h>

#include "core/string.h"
#include "core/node.h"
#include "core/nodelist.h"

#include "utils/hashtable.h"
#include "utils/list.h"

#include "events/document_event.h"

struct dom_doc_nl;

/**
 * DOM document
 * This should be protected, because later the HTMLDocument will inherit from
 * this. 
 */
struct dom_document {
	dom_node_internal base;		/**< Base node */

	struct dom_doc_nl *nodelists;	/**< List of active nodelists */

	dom_string *uri;		/**< The uri of this document */

	struct list_entry pending_nodes;
			/**< The deletion pending list */

	dom_string *id_name;		/**< The ID attribute's name */

	dom_string *class_string;	/**< The string "class". */

	dom_document_event_internal dei;
			/**< The DocumentEvent interface */
	dom_document_quirks_mode quirks;
				/**< Document is in quirks mode */
};

/* Create a DOM document */
dom_exception _dom_document_create(dom_events_default_action_fetcher daf,
		dom_document **doc);

/* Initialise the document */
dom_exception _dom_document_initialise(dom_document *doc, 
		dom_events_default_action_fetcher daf);

/* Finalise the document */
bool _dom_document_finalise(dom_document *doc);

/* Begin the virtual functions */
dom_exception _dom_document_get_doctype(dom_document *doc,
		dom_document_type **result);
dom_exception _dom_document_get_implementation(dom_document *doc,
		dom_implementation **result);
dom_exception _dom_document_get_document_element(dom_document *doc,
		dom_element **result);
dom_exception _dom_document_create_element(dom_document *doc,
		dom_string *tag_name, dom_element **result);
dom_exception _dom_document_create_document_fragment(dom_document *doc,
		dom_document_fragment **result);
dom_exception _dom_document_create_text_node(dom_document *doc,
		dom_string *data, dom_text **result);
dom_exception _dom_document_create_comment(dom_document *doc,
		dom_string *data, dom_comment **result);
dom_exception _dom_document_create_cdata_section(dom_document *doc,
		dom_string *data, dom_cdata_section **result);
dom_exception _dom_document_create_processing_instruction(
		dom_document *doc, dom_string *target,
		dom_string *data,
		dom_processing_instruction **result);
dom_exception _dom_document_create_attribute(dom_document *doc,
		dom_string *name, dom_attr **result);
dom_exception _dom_document_create_entity_reference(dom_document *doc,
		dom_string *name,
		dom_entity_reference **result);
dom_exception _dom_document_get_elements_by_tag_name(dom_document *doc,
		dom_string *tagname, dom_nodelist **result);
dom_exception _dom_document_import_node(dom_document *doc,
		dom_node *node, bool deep, dom_node **result);
dom_exception _dom_document_create_element_ns(dom_document *doc,
		dom_string *namespace, dom_string *qname,
		dom_element **result);
dom_exception _dom_document_create_attribute_ns(dom_document *doc,
		dom_string *namespace, dom_string *qname,
		dom_attr **result);
dom_exception _dom_document_get_elements_by_tag_name_ns(
		dom_document *doc, dom_string *namespace,
		dom_string *localname, dom_nodelist **result);
dom_exception _dom_document_get_element_by_id(dom_document *doc,
		dom_string *id, dom_element **result);
dom_exception _dom_document_get_input_encoding(dom_document *doc,
		dom_string **result);
dom_exception _dom_document_get_xml_encoding(dom_document *doc,
		dom_string **result);
dom_exception _dom_document_get_xml_standalone(dom_document *doc,
		bool *result);
dom_exception _dom_document_set_xml_standalone(dom_document *doc,
		bool standalone);
dom_exception _dom_document_get_xml_version(dom_document *doc,
		dom_string **result);
dom_exception _dom_document_set_xml_version(dom_document *doc,
		dom_string *version);
dom_exception _dom_document_get_strict_error_checking(
		dom_document *doc, bool *result);
dom_exception _dom_document_set_strict_error_checking(
		dom_document *doc, bool strict);
dom_exception _dom_document_get_uri(dom_document *doc,
		dom_string **result);
dom_exception _dom_document_set_uri(dom_document *doc,
		dom_string *uri);
dom_exception _dom_document_adopt_node(dom_document *doc,
		dom_node *node, dom_node **result);
dom_exception _dom_document_get_dom_config(dom_document *doc,
		struct dom_configuration **result);
dom_exception _dom_document_normalize(dom_document *doc);
dom_exception _dom_document_rename_node(dom_document *doc,
		dom_node *node,
		dom_string *namespace, dom_string *qname,
		dom_node **result);
dom_exception _dom_document_get_quirks_mode(dom_document *doc,
		dom_document_quirks_mode *result);
dom_exception _dom_document_set_quirks_mode(dom_document *doc,
		dom_document_quirks_mode result);


dom_exception _dom_document_get_text_content(dom_node_internal *node,
					     dom_string **result);
dom_exception _dom_document_set_text_content(dom_node_internal *node,
					     dom_string *content);

#define DOM_DOCUMENT_VTABLE \
	_dom_document_get_doctype, \
	_dom_document_get_implementation, \
	_dom_document_get_document_element, \
	_dom_document_create_element, \
	_dom_document_create_document_fragment, \
	_dom_document_create_text_node, \
	_dom_document_create_comment, \
	_dom_document_create_cdata_section, \
	_dom_document_create_processing_instruction, \
	_dom_document_create_attribute, \
	_dom_document_create_entity_reference, \
	_dom_document_get_elements_by_tag_name, \
	_dom_document_import_node, \
	_dom_document_create_element_ns, \
	_dom_document_create_attribute_ns, \
	_dom_document_get_elements_by_tag_name_ns, \
	_dom_document_get_element_by_id, \
	_dom_document_get_input_encoding, \
	_dom_document_get_xml_encoding, \
	_dom_document_get_xml_standalone, \
	_dom_document_set_xml_standalone, \
	_dom_document_get_xml_version, \
	_dom_document_set_xml_version, \
	_dom_document_get_strict_error_checking, \
	_dom_document_set_strict_error_checking, \
	_dom_document_get_uri, \
	_dom_document_set_uri, \
	_dom_document_adopt_node, \
	_dom_document_get_dom_config, \
	_dom_document_normalize, \
	_dom_document_rename_node, \
	_dom_document_get_quirks_mode, \
	_dom_document_set_quirks_mode

/* End of vtable */

#define DOM_NODE_VTABLE_DOCUMENT \
	_dom_node_try_destroy, \
	_dom_node_get_node_name, \
	_dom_node_get_node_value, \
	_dom_node_set_node_value, \
	_dom_node_get_node_type, \
	_dom_node_get_parent_node, \
	_dom_node_get_child_nodes, \
	_dom_node_get_first_child, \
	_dom_node_get_last_child, \
	_dom_node_get_previous_sibling, \
	_dom_node_get_next_sibling, \
	_dom_node_get_attributes, \
	_dom_node_get_owner_document, \
	_dom_node_insert_before, \
	_dom_node_replace_child, \
	_dom_node_remove_child, \
	_dom_node_append_child, \
	_dom_node_has_child_nodes, \
	_dom_node_clone_node, \
	_dom_node_normalize, \
	_dom_node_is_supported, \
	_dom_node_get_namespace, \
	_dom_node_get_prefix, \
	_dom_node_set_prefix, \
	_dom_node_get_local_name, \
	_dom_node_has_attributes, \
	_dom_node_get_base, \
	_dom_node_compare_document_position, \
	_dom_document_get_text_content, \
	_dom_document_set_text_content, \
	_dom_node_is_same, \
	_dom_node_lookup_prefix, \
	_dom_node_is_default_namespace, \
	_dom_node_lookup_namespace, \
	_dom_node_is_equal, \
	_dom_node_get_feature, \
	_dom_node_set_user_data, \
	_dom_node_get_user_data

/** \todo Unused! */
/**
 * The internal used vtable for document
 */
struct dom_document_protected_vtable {
	struct dom_node_protect_vtable base;
	dom_exception (*dom_document_get_base)(dom_document *doc,
			dom_string **base_uri);
			/* Get the document's base uri */
};

typedef struct dom_document_protected_vtable dom_document_protected_vtable;

/* Get the document's base URI */
static inline dom_exception dom_document_get_base(dom_document *doc,
		dom_string **base_uri)
{
	dom_node_internal *node = (dom_node_internal *) doc;
	return ((dom_document_protected_vtable *) node->vtable)->
			dom_document_get_base(doc, base_uri);
}
#define dom_document_get_base(d, b) dom_document_get_base( \
		(dom_document *) (d), (dom_string **) (b))

/* Following comes the protected vtable  */
void _dom_document_destroy(dom_node_internal *node);
dom_exception _dom_document_copy(dom_node_internal *old, 
		dom_node_internal **copy);

#define DOM_DOCUMENT_PROTECT_VTABLE \
	_dom_document_destroy, \
	_dom_document_copy


/*---------------------------- Helper functions ---------------------------*/

/* Try to destroy the document:
 * When the refcnt is zero and the pending list is empty, we can destroy this
 * document. */
void _dom_document_try_destroy(dom_document *doc);

/* Get a nodelist, creating one if necessary */
dom_exception _dom_document_get_nodelist(dom_document *doc,
		nodelist_type type, dom_node_internal *root,
		dom_string *tagname, dom_string *namespace,
		dom_string *localname, dom_nodelist **list);
/* Remove a nodelist */
void _dom_document_remove_nodelist(dom_document *doc, dom_nodelist *list);

/* Find element with certain ID in the subtree rooted at root */
dom_exception _dom_find_element_by_id(dom_node_internal *root, 
		dom_string *id, dom_element **result);

/* Set the ID attribute name of this document */
void _dom_document_set_id_name(dom_document *doc, dom_string *name);

#define _dom_document_get_id_name(d) (d->id_name)

#endif