/* HTML canvas element rendering context binding using duktape and libdom
*
* Copyright 2020 Daniel Silverstone
*
* 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
*/
class CanvasRenderingContext2D {
private struct dom_html_canvas_element *canvas;
private struct bitmap *bitmap;
private int width;
private int height;
private size_t stride;
private dom_event_listener *listener;
prologue %{
/* prologue */
#include "desktop/gui_internal.h"
#include "desktop/gui_table.h"
#include "netsurf/bitmap.h"
#include "utils/corestrings.h"
/* It's a smidge naughty of us to read
* this particular header, but we're needing
* to redraw the node we represent
*/
#include "content/handlers/html/private.h"
static void redraw_node(dom_node *node)
{
struct box *box = NULL;
html_content *htmlc = NULL;
dom_exception exc;
dom_document *doc;
exc = dom_node_get_user_data(node,
corestring_dom___ns_key_box_node_data,
&box);
if (exc != DOM_NO_ERR || box == NULL) {
return;
}
exc = dom_node_get_owner_document(node, &doc);
if (exc != DOM_NO_ERR || doc == NULL) {
return;
}
exc = dom_node_get_user_data(doc,
corestring_dom___ns_key_html_content_data,
&htmlc);
if (exc != DOM_NO_ERR || htmlc == NULL) {
dom_node_unref(doc);
return;
}
html__redraw_a_box(htmlc, box);
dom_node_unref(doc);
}
/**
* deal with events from the DOM for canvas node user data
*
* \param operation The DOM operation happening
* \param key The user data key
* \param data The user data (our bitmap)
* \param src The DOM node emitting the event (our