summaryrefslogtreecommitdiff
path: root/javascript/jsapi/htmlelement.bnd
blob: e1bd2c8133eed7133bb51cb47b7b401cd13cfd2d (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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
/* Binding to generate HTMLElement interface
 *
 * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * Released under the terms of the MIT License,
 *         http://www.opensource.org/licenses/mit-license
 */

#include "dom.bnd"

webidlfile "html.idl";

hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>";
hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
hdrcomment "Released under the terms of the MIT License,";
hdrcomment "        http://www.opensource.org/licenses/mit-license";

preamble %{

#include <dom/dom.h>

#include "utils/config.h"
#include "utils/log.h"
#include "utils/corestrings.h"

#include "javascript/js.h"
#include "javascript/jsapi.h"
#include "javascript/jsapi/binding.h"

%}

binding htmlelement {
    type js_libdom; /* the binding type */

    interface HTMLElement; /* Web IDL interface to generate */

    private "dom_element *" node;
    private "struct html_content *" htmlc;

    property unshared type EventHandler;
}

api finalise %{
	if (private != NULL) {
		dom_node_unref(private->node);
	}
%}

/* interface Element in dom idl */

/*
 * DOM 3 has these as the element traversal  extension
 *
 * http://dev.w3.org/2006/webapi/ElementTraversal/publish/ElementTraversal.html
 */

getter firstElementChild %{
	dom_node *element;
	dom_exception exc;
	dom_node_type node_type;
	dom_node *next_node;

	exc = dom_node_get_first_child(private->node, &element);
	if (exc != DOM_NO_ERR) {
		return JS_FALSE;
	}

	while (element != NULL) {
		exc = dom_node_get_node_type(element, &node_type);
		if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
			/* found it */
			jsret = jsapi_new_HTMLElement(cx,
						      NULL,
						      NULL,
						      (dom_element *)element,
						      private->htmlc);
			break;
		}

		exc = dom_node_get_next_sibling(element, &next_node);
		dom_node_unref(element);
		if (exc == DOM_NO_ERR) {
			element = next_node;
		} else {
			element = NULL;
		}

	}


	%}

getter lastElementChild %{
	dom_node *element;
	dom_exception exc;
	dom_node_type node_type;
	dom_node *sib_node;

	exc = dom_node_get_last_child(private->node, &element);
	if (exc != DOM_NO_ERR) {
		return JS_FALSE;
	}

	while (element != NULL) {
		exc = dom_node_get_node_type(element, &node_type);
		if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
			/* found it */
			jsret = jsapi_new_HTMLElement(cx,
						      NULL,
						      NULL,
						      (dom_element *)element,
						      private->htmlc);
			break;
		}

		exc = dom_node_get_previous_sibling(element, &sib_node);
		dom_node_unref(element);
		if (exc == DOM_NO_ERR) {
			element = sib_node;
		} else {
			element = NULL;
		}

	}
	%}

getter previousElementSibling %{
	dom_node *element;
	dom_exception exc;
	dom_node_type node_type;
	dom_node *sib_node;

	exc = dom_node_get_previous_sibling(private->node, &element);
	if (exc != DOM_NO_ERR) {
		return JS_FALSE;
	}

	while (element != NULL) {
		exc = dom_node_get_node_type(element, &node_type);
		if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
			/* found it */
			jsret = jsapi_new_HTMLElement(cx,
						      NULL,
						      NULL,
						      (dom_element *)element,
						      private->htmlc);
			break;
		}

		exc = dom_node_get_previous_sibling(element, &sib_node);
		dom_node_unref(element);
		if (exc == DOM_NO_ERR) {
			element = sib_node;
		} else {
			element = NULL;
		}
	}
%}

getter nextElementSibling %{
	dom_node *element;
	dom_exception exc;
	dom_node_type node_type;
	dom_node *sib_node;

	exc = dom_node_get_next_sibling(private->node, &element);
	if (exc != DOM_NO_ERR) {
		return JS_FALSE;
	}

	while (element != NULL) {
		exc = dom_node_get_node_type(element, &node_type);
		if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
			/* found it */
			jsret = jsapi_new_HTMLElement(cx,
						      NULL,
						      NULL,
						      (dom_element *)element,
						      private->htmlc);
			break;
		}

		exc = dom_node_get_next_sibling(element, &sib_node);
		dom_node_unref(element);
		if (exc == DOM_NO_ERR) {
			element = sib_node;
		} else {
			element = NULL;
		}
	}
%}

getter childElementCount %{
	dom_node *element;
	dom_exception exc;
	dom_node_type node_type;
	dom_node *next_node;

	exc = dom_node_get_first_child(private->node, &element);
	if (exc != DOM_NO_ERR) {
		return JS_FALSE;
	}

	while (element != NULL) {
		exc = dom_node_get_node_type(element, &node_type);
		if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
			jsret += 1;
		}

		exc = dom_node_get_next_sibling(element, &next_node);
		dom_node_unref(element);
		if (exc == DOM_NO_ERR) {
			element = next_node;
		} else {
			element = NULL;
		}
	}
%}

getter EventHandler %{
	JSLOG("propname[%d].name=\"%s\"",
	      tinyid,
	      jsclass_properties[tinyid].name);
%}


setter EventHandler %{
	dom_string *event_type_dom;

	JSLOG("propname[%d].name=\"%s\"",
	      tinyid,
	      jsclass_properties[tinyid].name);

	switch (tinyid) {
	case JSAPI_PROP_TINYID_onabort:
		event_type_dom = corestring_dom_abort;
		break;

	case JSAPI_PROP_TINYID_onblur:
		event_type_dom = corestring_dom_blur;
		break;

	case JSAPI_PROP_TINYID_oncancel:
		event_type_dom = corestring_dom_cancel;
		break;

	case JSAPI_PROP_TINYID_oncanplay:
		event_type_dom = corestring_dom_canplay;
		break;

	case JSAPI_PROP_TINYID_oncanplaythrough:
		event_type_dom = corestring_dom_canplaythrough;
		break;

	case JSAPI_PROP_TINYID_onchange:
		event_type_dom = corestring_dom_change;
		break;

	case JSAPI_PROP_TINYID_onclick:
		event_type_dom = corestring_dom_click;
		break;

	case JSAPI_PROP_TINYID_onclose:
		event_type_dom = corestring_dom_close;
		break;

	case JSAPI_PROP_TINYID_oncontextmenu:
		event_type_dom = corestring_dom_contextmenu;
		break;

	case JSAPI_PROP_TINYID_oncuechange:
		event_type_dom = corestring_dom_cuechange;
		break;

	case JSAPI_PROP_TINYID_ondblclick:
		event_type_dom = corestring_dom_dblclick;
		break;

	case JSAPI_PROP_TINYID_ondrag:
		event_type_dom = corestring_dom_drag;
		break;

	case JSAPI_PROP_TINYID_ondragend:
		event_type_dom = corestring_dom_dragend;
		break;

	case JSAPI_PROP_TINYID_ondragenter:
		event_type_dom = corestring_dom_dragenter;
		break;

	case JSAPI_PROP_TINYID_ondragleave:
		event_type_dom = corestring_dom_dragleave;
		break;

	case JSAPI_PROP_TINYID_ondragover:
		event_type_dom = corestring_dom_dragover;
		break;

	case JSAPI_PROP_TINYID_ondragstart:
		event_type_dom = corestring_dom_dragstart;
		break;

	case JSAPI_PROP_TINYID_ondrop:
		event_type_dom = corestring_dom_drop;
		break;

	case JSAPI_PROP_TINYID_ondurationchange:
		event_type_dom = corestring_dom_durationchange;
		break;

	case JSAPI_PROP_TINYID_onemptied:
		event_type_dom = corestring_dom_emptied;
		break;

	case JSAPI_PROP_TINYID_onended:
		event_type_dom = corestring_dom_ended;
		break;

	case JSAPI_PROP_TINYID_onerror:
		event_type_dom = corestring_dom_error;
		break;

	case JSAPI_PROP_TINYID_onfocus:
		event_type_dom = corestring_dom_focus;
		break;

	case JSAPI_PROP_TINYID_oninput:
		event_type_dom = corestring_dom_input;
		break;

	case JSAPI_PROP_TINYID_oninvalid:
		event_type_dom = corestring_dom_invalid;
		break;

	case JSAPI_PROP_TINYID_onkeydown:
		event_type_dom = corestring_dom_keydown;
		break;

	case JSAPI_PROP_TINYID_onkeypress:
		event_type_dom = corestring_dom_keypress;
		break;

	case JSAPI_PROP_TINYID_onkeyup:
		event_type_dom = corestring_dom_keyup;
		break;

	case JSAPI_PROP_TINYID_onload:
		event_type_dom = corestring_dom_load;
		break;

	case JSAPI_PROP_TINYID_onloadeddata:
		event_type_dom = corestring_dom_loadeddata;
		break;

	case JSAPI_PROP_TINYID_onloadedmetadata:
		event_type_dom = corestring_dom_loadedmetadata;
		break;

	case JSAPI_PROP_TINYID_onloadstart:
		event_type_dom = corestring_dom_loadstart;
		break;

	case JSAPI_PROP_TINYID_onmousedown:
		event_type_dom = corestring_dom_mousedown;
		break;

	case JSAPI_PROP_TINYID_onmousemove:
		event_type_dom = corestring_dom_mousemove;
		break;

	case JSAPI_PROP_TINYID_onmouseout:
		event_type_dom = corestring_dom_mouseout;
		break;

	case JSAPI_PROP_TINYID_onmouseover:
		event_type_dom = corestring_dom_mouseover;
		break;

	case JSAPI_PROP_TINYID_onmouseup:
		event_type_dom = corestring_dom_mouseup;
		break;

	case JSAPI_PROP_TINYID_onmousewheel:
		event_type_dom = corestring_dom_mousewheel;
		break;

	case JSAPI_PROP_TINYID_onpause:
		event_type_dom = corestring_dom_pause;
		break;

	case JSAPI_PROP_TINYID_onplay:
		event_type_dom = corestring_dom_play;
		break;

	case JSAPI_PROP_TINYID_onplaying:
		event_type_dom = corestring_dom_playing;
		break;

	case JSAPI_PROP_TINYID_onprogress:
		event_type_dom = corestring_dom_progress;
		break;

	case JSAPI_PROP_TINYID_onratechange:
		event_type_dom = corestring_dom_ratechange;
		break;

	case JSAPI_PROP_TINYID_onreset:
		event_type_dom = corestring_dom_reset;
		break;

	case JSAPI_PROP_TINYID_onscroll:
		event_type_dom = corestring_dom_scroll;
		break;

	case JSAPI_PROP_TINYID_onseeked:
		event_type_dom = corestring_dom_seeked;
		break;

	case JSAPI_PROP_TINYID_onseeking:
		event_type_dom = corestring_dom_seeking;
		break;

	case JSAPI_PROP_TINYID_onselect:
		event_type_dom = corestring_dom_select;
		break;

	case JSAPI_PROP_TINYID_onshow:
		event_type_dom = corestring_dom_show;
		break;

	case JSAPI_PROP_TINYID_onstalled:
		event_type_dom = corestring_dom_stalled;
		break;

	case JSAPI_PROP_TINYID_onsubmit:
		event_type_dom = corestring_dom_submit;
		break;

	case JSAPI_PROP_TINYID_onsuspend:
		event_type_dom = corestring_dom_suspend;
		break;

	case JSAPI_PROP_TINYID_ontimeupdate:
		event_type_dom = corestring_dom_timeupdate;
		break;

	case JSAPI_PROP_TINYID_onvolumechange:
		event_type_dom = corestring_dom_volumechange;
		break;

	case JSAPI_PROP_TINYID_onwaiting:
		event_type_dom = corestring_dom_waiting;
		break;

	default:
		JSLOG("called with unknown tinyid");
		return JS_TRUE;
	}

	js_dom_event_add_listener((struct jscontext *)cx,
				  private->htmlc->document,
				  (dom_node *)private->node,
				  event_type_dom,
				  vp);
%}