summaryrefslogtreecommitdiff
path: root/content/handlers/javascript/duktape/HTMLCanvasElement.bnd
blob: da9f66dee163ef54651abd546da7bd4964194ecf (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
/* HTML canvas element binding using duktape and libdom
 *
 * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
 * Copyright 2020 Daniel Silverstone <dsilvers@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
 */

init HTMLCanvasElement(struct dom_html_element *html_canvas_element::html_element);

getter HTMLCanvasElement::width();
setter HTMLCanvasElement::width();

getter HTMLCanvasElement::height();
setter HTMLCanvasElement::height();

method HTMLCanvasElement::getContext()
%{
	/* modetype[, {options}] */
	const char *modetype = duk_to_string(ctx, 0);
	if (strcmp(modetype, "2d") != 0) {
		duk_push_null(ctx);
		return 1;
	}

	duk_push_this(ctx);
	duk_get_prop_string(ctx, -1, MAGIC(Context2D));
	if (duk_is_undefined(ctx, -1)) {
		duk_pop(ctx);

		duk_push_pointer(ctx, ((node_private_t*)priv)->node);
		if (dukky_create_object(ctx,
					PROTO_NAME(CANVASRENDERINGCONTEXT2D),
					1) != DUK_EXEC_SUCCESS) {
			return duk_error(ctx,
				  DUK_ERR_ERROR,
				  "Unable to create CanvasRenderingContext2D");
		}
		duk_dup(ctx, -1);
		duk_put_prop_string(ctx, -3, MAGIC(Context2D));
	}
	return 1;
%}