summaryrefslogtreecommitdiff
path: root/javascript/duktape/HTMLElement.bnd
blob: ce1a925627125eebe7cb7dc5c7b5bac9c2d83188 (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
/* HTML element binding using duktape and libdom
 *
 * Copyright 2015 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
 */

prologue HTMLElement ()
%{
#include <utils/corestrings.h>
#define HANDLER_MAGIC MAGIC(HANDLER_MAP)
%}

init HTMLElement(struct dom_html_element *html_element::element);

getter HTMLElement::dir();
setter HTMLElement::dir();

getter HTMLElement::lang();
setter HTMLElement::lang();

getter HTMLElement::title();
setter HTMLElement::title();

setter HTMLElement::onclick()
%{
	/* handlerfn */
	duk_push_this(ctx);
	/* handlerfn this */
	duk_get_prop_string(ctx, -1, HANDLER_MAGIC);
	/* handlerfn this handlers */
	duk_push_lstring(ctx, "click", 5);
	/* handlerfn this handlers click */
	duk_dup(ctx, -4);
	/* handlerfn this handlers click handlerfn */
	duk_put_prop(ctx, -3);
	/* handlerfn this handlers */
	dukky_register_event_listener_for(ctx,
			(dom_element *)((node_private_t *)priv)->node,
			corestring_dom_click);
	return 0;
%}

getter HTMLElement::onclick()
%{
	dom_event_target *et = (dom_event_target *)(((node_private_t *)priv)->node);
	dom_string *name;
	dom_exception exc;

	exc = dom_string_create((const uint8_t *)"click", 5, &name);
	if (exc != DOM_NO_ERR) return 0;

	duk_push_this(ctx);
	/* ... node */
	if (dukky_get_current_value_of_event_handler(ctx, name, et) == false) {
		dom_string_unref(name);
		return 0;
	}
	dom_string_unref(name);
	/* ... handler node */
	duk_pop(ctx);
	/* ... handler */
	return 1;
%}