summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--bindings/hubbub/parser.c117
-rw-r--r--bindings/hubbub/parser.h6
-rw-r--r--include/dom/dom.h7
-rw-r--r--include/dom/events/keyboard_event.h53
-rw-r--r--include/dom/html/html_canvas_element.h31
-rw-r--r--src/core/node.c19
-rw-r--r--src/events/dispatch.c12
-rw-r--r--src/events/keyboard_event.c226
-rw-r--r--src/events/keyboard_event.h18
-rw-r--r--src/events/ui_event.c3
-rw-r--r--src/html/Makefile76
-rw-r--r--src/html/html_canvas_element.c190
-rw-r--r--src/html/html_canvas_element.h62
-rw-r--r--src/html/html_document.c6
-rw-r--r--src/html/html_element.c4
-rw-r--r--src/html/html_select_element.c6
-rw-r--r--src/html/html_title_element.c20
-rw-r--r--src/utils/namespace.c4
19 files changed, 717 insertions, 148 deletions
diff --git a/Makefile b/Makefile
index fe1656b..1c6d9ff 100644
--- a/Makefile
+++ b/Makefile
@@ -2,11 +2,11 @@
#
# Makefile for libdom
#
-# Copyright 2009-2015 John-Mark Bell <jmb@netsurf-browser.org>
+# Copyright 2009-2020 John-Mark Bell <jmb@netsurf-browser.org>
# Component settings
COMPONENT := dom
-COMPONENT_VERSION := 0.4.0
+COMPONENT_VERSION := 0.4.1
# Default to a static library
COMPONENT_TYPE ?= lib-static
@@ -99,6 +99,7 @@ INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_body_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_meta_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_form_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_button_element.h
+INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_canvas_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_input_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_select_element.h
INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):$(Is)/html_text_area_element.h
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 1c0e03f..a84a951 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -39,7 +39,7 @@ struct dom_hubbub_parser {
hubbub_tree_handler tree_handler;
/**< Hubbub parser tree handler */
- struct dom_document *doc; /**< DOM Document we're building */
+ struct dom_document *doc; /**< DOM Document we're building within */
dom_hubbub_encoding_source encoding_source;
/**< The document's encoding source */
@@ -642,7 +642,7 @@ static hubbub_error set_quirks_mode(void *parser, hubbub_quirks_mode mode)
static hubbub_error change_encoding(void *parser, const char *charset)
{
dom_hubbub_parser *dom_parser = (dom_hubbub_parser *) parser;
- uint32_t source;
+ hubbub_charset_source source;
const char *name;
/* If we have an encoding here, it means we are *certain* */
@@ -865,6 +865,119 @@ dom_hubbub_parser_create(dom_hubbub_parser_params *params,
}
+/**
+ * Create a Hubbub parser instance
+ *
+ * \param params The binding creation parameters
+ * \param parser Pointer to location to recive instance.
+ * \param document Pointer to location to receive document.
+ * \return Error code
+ */
+dom_hubbub_error
+dom_hubbub_fragment_parser_create(dom_hubbub_parser_params *params,
+ dom_document *document,
+ dom_hubbub_parser **parser,
+ dom_document_fragment **fragment)
+{
+ dom_hubbub_parser *binding;
+ hubbub_parser_optparams optparams;
+ hubbub_error error;
+ dom_exception err;
+
+ if (document == NULL) {
+ return DOM_HUBBUB_BADPARM;
+ }
+
+ /* check result parameters */
+ if (fragment == NULL) {
+ return DOM_HUBBUB_BADPARM;
+ }
+
+ if (parser == NULL) {
+ return DOM_HUBBUB_BADPARM;
+ }
+
+ /* setup binding parser context */
+ binding = malloc(sizeof(dom_hubbub_parser));
+ if (binding == NULL) {
+ return DOM_HUBBUB_NOMEM;
+ }
+
+ binding->parser = NULL;
+ binding->doc = (struct dom_document *)dom_node_ref(document);
+ binding->encoding = params->enc;
+
+ if (params->enc != NULL) {
+ binding->encoding_source = DOM_HUBBUB_ENCODING_SOURCE_HEADER;
+ } else {
+ binding->encoding_source = DOM_HUBBUB_ENCODING_SOURCE_DETECTED;
+ }
+
+ binding->complete = false;
+
+ if (params->msg == NULL) {
+ binding->msg = dom_hubbub_parser_default_msg;
+ } else {
+ binding->msg = params->msg;
+ }
+ binding->mctx = params->ctx;
+
+ /* ensure script function is valid or use the default */
+ if (params->script == NULL) {
+ binding->script = dom_hubbub_parser_default_script;
+ } else {
+ binding->script = params->script;
+ }
+
+ /* create hubbub parser */
+ error = hubbub_parser_create(binding->encoding,
+ params->fix_enc,
+ &binding->parser);
+ if (error != HUBBUB_OK) {
+ dom_node_unref(binding->doc);
+ free(binding);
+ return (DOM_HUBBUB_HUBBUB_ERR | error);
+ }
+
+ /* create DOM document fragment */
+ err = dom_document_create_document_fragment(binding->doc,
+ fragment);
+ if (err != DOM_NO_ERR) {
+ hubbub_parser_destroy(binding->parser);
+ dom_node_unref(binding->doc);
+ free(binding);
+ return DOM_HUBBUB_DOM;
+ }
+
+ binding->tree_handler = tree_handler;
+ binding->tree_handler.ctx = (void *)binding;
+
+ /* set tree handler on parser */
+ optparams.tree_handler = &binding->tree_handler;
+ hubbub_parser_setopt(binding->parser,
+ HUBBUB_PARSER_TREE_HANDLER,
+ &optparams);
+
+ /* set document node*/
+ optparams.document_node = dom_node_ref((struct dom_node *)*fragment);
+ hubbub_parser_setopt(binding->parser,
+ HUBBUB_PARSER_DOCUMENT_NODE,
+ &optparams);
+
+ /* set scripting state */
+ optparams.enable_scripting = params->enable_script;
+ hubbub_parser_setopt(binding->parser,
+ HUBBUB_PARSER_ENABLE_SCRIPTING,
+ &optparams);
+
+ /* set return parameters */
+ *parser = binding;
+ /* fragment is already set up */
+
+ return DOM_HUBBUB_OK;
+}
+
+
dom_hubbub_error
dom_hubbub_parser_insert_chunk(dom_hubbub_parser *parser,
const uint8_t *data,
diff --git a/bindings/hubbub/parser.h b/bindings/hubbub/parser.h
index 54ad0c8..5a95a91 100644
--- a/bindings/hubbub/parser.h
+++ b/bindings/hubbub/parser.h
@@ -70,6 +70,12 @@ dom_hubbub_error dom_hubbub_parser_create(dom_hubbub_parser_params *params,
dom_hubbub_parser **parser,
dom_document **document);
+/* Create a Hubbub parser instance for a document fragment */
+dom_hubbub_error dom_hubbub_fragment_parser_create(dom_hubbub_parser_params *params,
+ dom_document *document,
+ dom_hubbub_parser **parser,
+ dom_document_fragment **fragment);
+
/* Destroy a Hubbub parser instance */
void dom_hubbub_parser_destroy(dom_hubbub_parser *parser);
diff --git a/include/dom/dom.h b/include/dom/dom.h
index 0740fe9..c10e5a6 100644
--- a/include/dom/dom.h
+++ b/include/dom/dom.h
@@ -51,6 +51,7 @@
#include <dom/html/html_form_element.h>
#include <dom/html/html_input_element.h>
#include <dom/html/html_button_element.h>
+#include <dom/html/html_canvas_element.h>
#include <dom/html/html_text_area_element.h>
#include <dom/html/html_opt_group_element.h>
#include <dom/html/html_option_element.h>
@@ -111,6 +112,12 @@ typedef enum dom_namespace {
DOM_NAMESPACE_COUNT = 7
} dom_namespace;
+/* Note, these are not valid until at least one function related to DOM
+ * namespaces has been called such as the creation of a Document.
+ */
extern dom_string *dom_namespaces[DOM_NAMESPACE_COUNT];
+/* Optional client-callable namespace cleanup function */
+extern dom_exception dom_namespace_finalise(void);
+
#endif
diff --git a/include/dom/events/keyboard_event.h b/include/dom/events/keyboard_event.h
index 132049e..e3b7d50 100644
--- a/include/dom/events/keyboard_event.h
+++ b/include/dom/events/keyboard_event.h
@@ -23,16 +23,26 @@ typedef enum {
DOM_KEY_LOCATION_NUMPAD = 3
} dom_key_location;
-dom_exception _dom_keyboard_event_get_key_identifier(dom_keyboard_event *evt,
- dom_string **ident);
-#define dom_keyboard_event_get_key_identifier(e, i) \
- _dom_keyboard_event_get_key_identifier( \
+dom_exception _dom_keyboard_event_create(dom_keyboard_event **evt);
+#define dom_keyboard_event_create(n) \
+ _dom_keyboard_event_create((dom_keyboard_event **) (n))
+
+dom_exception _dom_keyboard_event_get_key(dom_keyboard_event *evt,
+ dom_string **key);
+#define dom_keyboard_event_get_key(e, i) \
+ _dom_keyboard_event_get_key( \
(dom_keyboard_event *) (e), (dom_string **) (i))
-dom_exception _dom_keyboard_event_get_key_location(dom_keyboard_event *evt,
- dom_key_location *loc);
-#define dom_keyboard_event_get_key_location(e, l) \
- _dom_keyboard_event_get_key_location( \
+dom_exception _dom_keyboard_event_get_code(dom_keyboard_event *evt,
+ dom_string **code);
+#define dom_keyboard_event_get_code(e, i) \
+ _dom_keyboard_event_get_code( \
+ (dom_keyboard_event *) (e), (dom_string **) (i))
+
+dom_exception _dom_keyboard_event_get_location(dom_keyboard_event *evt,
+ dom_key_location *location);
+#define dom_keyboard_event_get_location(e, l) \
+ _dom_keyboard_event_get_location( \
(dom_keyboard_event *) (e), (dom_key_location *) (l))
dom_exception _dom_keyboard_event_get_ctrl_key(dom_keyboard_event *evt,
@@ -65,25 +75,32 @@ dom_exception _dom_keyboard_event_get_modifier_state(dom_keyboard_event *evt,
dom_exception _dom_keyboard_event_init(dom_keyboard_event *evt,
dom_string *type, bool bubble, bool cancelable,
- struct dom_abstract_view *view, dom_string *key_ident,
- dom_key_location key_loc, dom_string *modifier_list);
-#define dom_keyboard_event_init(e, t, b, c, v, ki, kl, m) \
+ struct dom_abstract_view *view, dom_string *key,
+ dom_string *code, dom_key_location location,
+ bool ctrl_key, bool shift_key, bool alt_key, bool meta_key,
+ bool repeat, bool is_composing);
+#define dom_keyboard_event_init(e, t, b, c, v, kk, kc, kl, ck, sk, ak, mk, r, ic) \
_dom_keyboard_event_init((dom_keyboard_event *) (e), \
(dom_string *) (t), (bool) (b), (bool) (c), \
- (struct dom_abstract_view *) (v), (dom_string *) (ki), \
- (dom_key_location) (kl), (dom_string *) (m))
+ (struct dom_abstract_view *) (v), (dom_string *) (kk), \
+ (dom_string *) (kc), (dom_key_location) (kl), \
+ (bool) (ck), (bool) (sk), (bool) (ak), (bool) (mk), \
+ (bool) (r), (bool) (ic))
dom_exception _dom_keyboard_event_init_ns(dom_keyboard_event *evt,
dom_string *namespace, dom_string *type,
bool bubble, bool cancelable, struct dom_abstract_view *view,
- dom_string *key_ident, dom_key_location key_loc,
- dom_string *modifier_list);
+ dom_string *key, dom_string *code, dom_key_location location,
+ bool ctrl_key, bool shift_key, bool alt_key, bool meta_key,
+ bool repeat, bool is_composing);
#define dom_keyboard_event_init_ns(e, n, t, b, c, v, ki, kl, m) \
_dom_keyboard_event_init_ns((dom_keyboard_event *) (e), \
(dom_string *) (n), (dom_string *) (t), \
- (bool) (b), (bool) (c), (struct dom_abstract_view *) (v), \
- (dom_string *) (ki), (dom_key_location) (kl), \
- (dom_string *) (m))
+ (bool) (b), (bool) (c), \
+ (struct dom_abstract_view *) (v), (dom_string *) (kk), \
+ (dom_string *) (kc), (dom_key_location) (kl), \
+ (bool) (ck), (bool) (sk), (bool) (ak), (bool) (mk), \
+ (bool) (r), (bool) (ic))
#endif
diff --git a/include/dom/html/html_canvas_element.h b/include/dom/html/html_canvas_element.h
new file mode 100644
index 0000000..29c7668
--- /dev/null
+++ b/include/dom/html/html_canvas_element.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
+ */
+
+#ifndef dom_html_canvas_element_h_
+#define dom_html_canvas_element_h_
+
+#include <dom/inttypes.h>
+#include <dom/core/exceptions.h>
+
+#include <dom/html/html_document.h>
+
+typedef struct dom_html_canvas_element dom_html_canvas_element;
+
+dom_exception dom_html_canvas_element_get_width(
+ dom_html_canvas_element *object, dom_ulong *width);
+
+dom_exception dom_html_canvas_element_set_width(
+ dom_html_canvas_element *object, dom_ulong width);
+
+dom_exception dom_html_canvas_element_get_height(
+ dom_html_canvas_element *object, dom_ulong *height);
+
+dom_exception dom_html_canvas_element_set_height(
+ dom_html_canvas_element *object, dom_ulong height);
+
+
+#endif
diff --git a/src/core/node.c b/src/core/node.c
index 87ad837..b471725 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -2172,7 +2172,9 @@ dom_exception _dom_node_detach_range(dom_node_internal *first,
*
* This is not implemented in terms of attach/detach in case
* we want to perform any special replacement-related behaviour
- * at a later date.
+ * at a later date. If the replacement is essentially empty (either NULL
+ * or an empty document fragment node) then this essentially just removes
+ * the old node from its parent. It is up to the caller to deal with that.
*/
void _dom_node_replace(dom_node_internal *old,
dom_node_internal *replacement)
@@ -2190,6 +2192,19 @@ void _dom_node_replace(dom_node_internal *old,
last = replacement;
}
+ if (first == NULL) {
+ /* All we're doing is removing old */
+ if (old->previous == NULL) {
+ old->parent->first_child = old->next;
+ }
+ if (old->next == NULL) {
+ old->parent->last_child = old->previous;
+ }
+ old->previous = old->next = old->parent = NULL;
+ return;
+ }
+
+ /* We're replacing old with first-to-last */
first->previous = old->previous;
last->next = old->next;
@@ -2203,7 +2218,7 @@ void _dom_node_replace(dom_node_internal *old,
else
old->parent->last_child = last;
- for (n = first; n != last->next; n = n->next) {
+ for (n = first; n != NULL && n != last->next; n = n->next) {
n->parent = old->parent;
}
diff --git a/src/events/dispatch.c b/src/events/dispatch.c
index 0e0048d..a8b8ad7 100644
--- a/src/events/dispatch.c
+++ b/src/events/dispatch.c
@@ -56,7 +56,7 @@ dom_exception __dom_dispatch_node_change_event(dom_document *doc,
goto cleanup;
cleanup:
- _dom_mutation_event_destroy(evt);
+ dom_event_unref(evt);
return err;
}
@@ -101,7 +101,7 @@ dom_exception __dom_dispatch_node_change_document_event(dom_document *doc,
goto cleanup;
cleanup:
- _dom_mutation_event_destroy(evt);
+ dom_event_unref(evt);
return err;
}
@@ -145,7 +145,7 @@ dom_exception __dom_dispatch_attr_modified_event(dom_document *doc,
err = dom_event_target_dispatch_event(et, evt, success);
cleanup:
- _dom_mutation_event_destroy(evt);
+ dom_event_unref(evt);
return err;
}
@@ -188,7 +188,7 @@ dom_exception __dom_dispatch_characterdata_modified_event(
err = dom_event_target_dispatch_event(et, evt, success);
cleanup:
- _dom_mutation_event_destroy(evt);
+ dom_event_unref(evt);
return err;
}
@@ -224,7 +224,7 @@ dom_exception __dom_dispatch_subtree_modified_event(dom_document *doc,
err = dom_event_target_dispatch_event(et, evt, success);
cleanup:
- _dom_mutation_event_destroy(evt);
+ dom_event_unref(evt);
return err;
}
@@ -263,7 +263,7 @@ dom_exception _dom_dispatch_generic_event(dom_document *doc,
err = dom_event_target_dispatch_event(et, evt, success);
cleanup:
- _dom_event_destroy(evt);
+ dom_event_unref(evt);
return err;
}
diff --git a/src/events/keyboard_event.c b/src/events/keyboard_event.c
index fb29c18..d349355 100644
--- a/src/events/keyboard_event.c
+++ b/src/events/keyboard_event.c
@@ -22,7 +22,7 @@ static struct dom_event_private_vtable _event_vtable = {
/* Constructor */
dom_exception _dom_keyboard_event_create(struct dom_keyboard_event **evt)
{
- *evt = malloc(sizeof(dom_keyboard_event));
+ *evt = calloc(1, sizeof(dom_keyboard_event));
if (*evt == NULL)
return DOM_NO_MEM_ERR;
@@ -42,8 +42,16 @@ void _dom_keyboard_event_destroy(struct dom_keyboard_event *evt)
/* Initialise function */
dom_exception _dom_keyboard_event_initialise(struct dom_keyboard_event *evt)
{
- evt->key_ident = NULL;
- evt->modifier_state = 0;
+ dom_exception err;
+ dom_string *empty_string;
+
+ err = dom_string_create((const uint8_t *)"", 0, &empty_string);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ evt->key = empty_string;
+ evt->code = dom_string_ref(empty_string);
return _dom_ui_event_initialise(&evt->base);
}
@@ -51,6 +59,11 @@ dom_exception _dom_keyboard_event_initialise(struct dom_keyboard_event *evt)
/* Finalise function */
void _dom_keyboard_event_finalise(struct dom_keyboard_event *evt)
{
+ if (evt->key != NULL)
+ dom_string_unref(evt->key);
+ if (evt->code != NULL)
+ dom_string_unref(evt->code);
+
_dom_ui_event_finalise(&evt->base);
}
@@ -64,17 +77,31 @@ void _virtual_dom_keyboard_event_destroy(struct dom_event *evt)
/* The public API */
/**
- * Get the key identifier
+ * Get the key
*
* \param evt The Event object
- * \param ident The returned key identifier
+ * \param key The returned key
+ * \return DOM_NO_ERR.
+ */
+dom_exception _dom_keyboard_event_get_key(dom_keyboard_event *evt,
+ dom_string **key)
+{
+ *key = dom_string_ref(evt->key);
+
+ return DOM_NO_ERR;
+}
+
+/**
+ * Get the code
+ *
+ * \param evt The Event object
+ * \param code The returned code
* \return DOM_NO_ERR.
*/
-dom_exception _dom_keyboard_event_get_key_identifier(dom_keyboard_event *evt,
- dom_string **ident)
+dom_exception _dom_keyboard_event_get_code(dom_keyboard_event *evt,
+ dom_string **code)
{
- *ident = evt->key_ident;
- dom_string_ref(*ident);
+ *code = dom_string_ref(evt->code);
return DOM_NO_ERR;
}
@@ -83,13 +110,13 @@ dom_exception _dom_keyboard_event_get_key_identifier(dom_keyboard_event *evt,
* Get the key location
*
* \param evt The Event object
- * \param loc The returned key location
+ * \param location The returned key location
* \return DOM_NO_ERR.
*/
-dom_exception _dom_keyboard_event_get_key_location(dom_keyboard_event *evt,
- dom_key_location *loc)
+dom_exception _dom_keyboard_event_get_location(dom_keyboard_event *evt,
+ dom_key_location *location)
{
- *loc = evt->key_loc;
+ *location = evt->location;
return DOM_NO_ERR;
}
@@ -123,7 +150,7 @@ dom_exception _dom_keyboard_event_get_shift_key(dom_keyboard_event *evt,
return DOM_NO_ERR;
}
-
+
/**
* Get the alt key state
*
@@ -207,70 +234,147 @@ dom_exception _dom_keyboard_event_get_modifier_state(dom_keyboard_event *evt,
}
/**
- * Initialise the keyboard event
+ * Helper to initialise the keyboard event
*
- * \param evt The Event object
- * \param type The event's type
- * \param bubble Whether this is a bubbling event
- * \param cancelable Whether this is a cancelable event
- * \param view The AbstractView associated with this event
- * \param key_indent The key identifier of pressed key
- * \param key_loc The key location of the preesed key
- * \param modifier_list A string of modifier key identifiers, separated with
- * space
- * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ * \param evt The Event object
+ * \param view The AbstractView associated with this event
+ * \param key The key identifier of pressed key
+ * \param code The code identifier of pressed key
+ * \param location The key location of the preesed key
+ * \param ctrl_key Whether the ctrl_key is pressed
+ * \param shift_key Whether the shift_key is pressed
+ * \param alt_key Whether the alt_key is pressed
+ * \param meta_key Whether the ctrl_key is pressed
+ * \param repeat Whether this is a repeat press from a held key
+ * \param is_composing Whether the input is being composed
*/
-dom_exception _dom_keyboard_event_init(dom_keyboard_event *evt,
- dom_string *type, bool bubble, bool cancelable,
- struct dom_abstract_view *view, dom_string *key_ident,
- dom_key_location key_loc, dom_string *modifier_list)
+static void _dom_keyboard_event_init_helper(
+ dom_keyboard_event *evt,
+ dom_string *key,
+ dom_string *code,
+ dom_key_location location,
+ bool ctrl_key,
+ bool shift_key,
+ bool alt_key,
+ bool meta_key,
+ bool repeat,
+ bool is_composing)
{
- dom_exception err;
+ if (key != NULL) {
+ dom_string_unref(evt->key);
+ evt->key = dom_string_ref(key);
+ }
+ if (code != NULL) {
+ dom_string_unref(evt->code);
+ evt->code = dom_string_ref(code);
+ }
- evt->key_ident = key_ident;
- dom_string_ref(evt->key_ident);
- evt->key_loc = key_loc;
+ evt->location = location;
- err = _dom_parse_modifier_list(modifier_list, &evt->modifier_state);
- if (err != DOM_NO_ERR)
- return err;
+ if (ctrl_key) {
+ evt->modifier_state |= DOM_MOD_CTRL;
+ }
+ if (shift_key) {
+ evt->modifier_state |= DOM_MOD_CTRL;
+ }
+ if (alt_key) {
+ evt->modifier_state |= DOM_MOD_SHIFT;
+ }
+ if (meta_key) {
+ evt->modifier_state |= DOM_MOD_META;
+ }
- return _dom_ui_event_init(&evt->base, type, bubble, cancelable,
- view, 0);
+ evt->repeat = repeat;
+ evt->is_composing = is_composing;
}
+
+
/**
* Initialise the keyboard event with namespace
*
- * \param evt The Event object
- * \param namespace The namespace of this event
- * \param type The event's type
- * \param bubble Whether this is a bubbling event
- * \param cancelable Whether this is a cancelable event
- * \param view The AbstractView associated with this event
- * \param key_indent The key identifier of pressed key
- * \param key_loc The key location of the preesed key
- * \param modifier_list A string of modifier key identifiers, separated with
- * space
+ * \param evt The Event object
+ * \param type The event's type
+ * \param bubble Whether this is a bubbling event
+ * \param cancelable Whether this is a cancelable event
+ * \param view The AbstractView associated with this event
+ * \param key The key identifier of pressed key
+ * \param code The code identifier of pressed key
+ * \param location The key location of the preesed key
+ * \param ctrl_key Whether the ctrl_key is pressed
+ * \param shift_key Whether the shift_key is pressed
+ * \param alt_key Whether the alt_key is pressed
+ * \param meta_key Whether the ctrl_key is pressed
+ * \param repeat Whether this is a repeat press from a held key
+ * \param is_composing Whether the input is being composed
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
-dom_exception _dom_keyboard_event_init_ns(dom_keyboard_event *evt,
- dom_string *namespace, dom_string *type,
- bool bubble, bool cancelable, struct dom_abstract_view *view,
- dom_string *key_ident, dom_key_location key_loc,
- dom_string *modifier_list)
+dom_exception _dom_keyboard_event_init(
+ dom_keyboard_event *evt,
+ dom_string *type,
+ bool bubble,
+ bool cancelable,
+ struct dom_abstract_view *view,
+ dom_string *key,
+ dom_string *code,
+ dom_key_location location,
+ bool ctrl_key,
+ bool shift_key,
+ bool alt_key,
+ bool meta_key,
+ bool repeat,
+ bool is_composing)
{
- dom_exception err;
+ _dom_keyboard_event_init_helper(evt, key, code, location,
+ ctrl_key, shift_key, alt_key, meta_key,
+ repeat, is_composing);
- evt->key_ident = key_ident;
- dom_string_ref(evt->key_ident);
- evt->key_loc = key_loc;
+ return _dom_ui_event_init(&evt->base, type, bubble, cancelable,
+ view, 0);
+}
- err = _dom_parse_modifier_list(modifier_list, &evt->modifier_state);
- if (err != DOM_NO_ERR)
- return err;
+/**
+ * Initialise the keyboard event with namespace
+ *
+ * \param evt The Event object
+ * \param namespace The namespace of this event
+ * \param type The event's type
+ * \param bubble Whether this is a bubbling event
+ * \param cancelable Whether this is a cancelable event
+ * \param view The AbstractView associated with this event
+ * \param key The key identifier of pressed key
+ * \param code The code identifier of pressed key
+ * \param location The key location of the preesed key
+ * \param ctrl_key Whether the ctrl_key is pressed
+ * \param shift_key Whether the shift_key is pressed
+ * \param alt_key Whether the alt_key is pressed
+ * \param meta_key Whether the ctrl_key is pressed
+ * \param repeat Whether this is a repeat press from a held key
+ * \param is_composing Whether the input is being composed
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_keyboard_event_init_ns(
+ dom_keyboard_event *evt,
+ dom_string *namespace,
+ dom_string *type,
+ bool bubble,
+ bool cancelable,
+ struct dom_abstract_view *view,
+ dom_string *key,
+ dom_string *code,
+ dom_key_location location,
+ bool ctrl_key,
+ bool shift_key,
+ bool alt_key,
+ bool meta_key,
+ bool repeat,
+ bool is_composing)
+{
+ _dom_keyboard_event_init_helper(evt, key, code, location,
+ ctrl_key, shift_key, alt_key, meta_key,
+ repeat, is_composing);
- return _dom_ui_event_init_ns(&evt->base, namespace, type, bubble,
+ return _dom_ui_event_init_ns(&evt->base, namespace, type, bubble,
cancelable, view, 0);
}
diff --git a/src/events/keyboard_event.h b/src/events/keyboard_event.h
index d640bbb..81b702f 100644
--- a/src/events/keyboard_event.h
+++ b/src/events/keyboard_event.h
@@ -18,21 +18,15 @@
struct dom_keyboard_event {
struct dom_ui_event base; /**< The base class */
- dom_string *key_ident; /**< The identifier of the key in this
- * event, please refer:
- * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set
- * for detail
- */
-
- dom_key_location key_loc; /**< Indicate the location of the key on
- * the keyboard
- */
+ dom_string *key;
+ dom_string *code;
+ dom_key_location location;
uint32_t modifier_state; /**< The modifier keys state */
-};
-/* Constructor */
-dom_exception _dom_keyboard_event_create(struct dom_keyboard_event **evt);
+ bool repeat;
+ bool is_composing;
+};
/* Destructor */
void _dom_keyboard_event_destroy(struct dom_keyboard_event *evt);
diff --git a/src/events/ui_event.c b/src/events/ui_event.c
index 4fac3b6..34ec84d 100644
--- a/src/events/ui_event.c
+++ b/src/events/ui_event.c
@@ -18,7 +18,7 @@ static struct dom_event_private_vtable _event_vtable = {
/* Constructor */
dom_exception _dom_ui_event_create(struct dom_ui_event **evt)
{
- *evt = malloc(sizeof(dom_ui_event));
+ *evt = calloc(1, sizeof(dom_ui_event));
if (*evt == NULL)
return DOM_NO_MEM_ERR;
@@ -38,7 +38,6 @@ void _dom_ui_event_destroy(struct dom_ui_event *evt)
/* Initialise function */
dom_exception _dom_ui_event_initialise(struct dom_ui_event *evt)
{
- evt->view = NULL;
return _dom_event_initialise(&evt->base);
}
diff --git a/src/html/Makefile b/src/html/Makefile
index c98ce9a..db765ad 100644
--- a/src/html/Makefile
+++ b/src/html/Makefile
@@ -1,24 +1,62 @@
# Sources
DIR_SOURCES := \
- html_document.c html_collection.c html_options_collection.c \
- html_element.c html_html_element.c html_head_element.c \
- html_link_element.c html_title_element.c html_meta_element.c \
- html_base_element.c html_style_element.c \
- html_body_element.c html_form_element.c html_select_element.c \
- html_button_element.c html_input_element.c html_text_area_element.c \
- html_opt_group_element.c html_option_element.c html_hr_element.c \
- html_dlist_element.c html_directory_element.c html_menu_element.c \
- html_fieldset_element.c html_legend_element.c html_div_element.c \
- html_paragraph_element.c html_heading_element.c html_quote_element.c \
- html_pre_element.c html_br_element.c html_label_element.c \
- html_ulist_element.c html_olist_element.c html_li_element.c \
- html_font_element.c html_mod_element.c html_anchor_element.c \
- html_basefont_element.c html_image_element.c html_object_element.c \
- html_param_element.c html_applet_element.c html_area_element.c \
- html_map_element.c html_script_element.c html_tablecaption_element.c \
- html_tablecell_element.c html_tablecol_element.c html_tablesection_element.c \
- html_table_element.c html_tablerow_element.c html_frameset_element.c \
- html_frame_element.c html_iframe_element.c html_isindex_element.c \
+ html_applet_element.c \
+ html_area_element.c \
+ html_anchor_element.c \
+ html_basefont_element.c \
+ html_base_element.c \
+ html_body_element.c \
+ html_button_element.c \
+ html_canvas_element.c \
+ html_collection.c \
+ html_document.c \
+ html_element.c \
+ html_dlist_element.c \
+ html_directory_element.c \
+ html_options_collection.c \
+ html_html_element.c \
+ html_head_element.c \
+ html_link_element.c \
+ html_title_element.c \
+ html_meta_element.c \
+ html_style_element.c \
+ html_form_element.c \
+ html_select_element.c \
+ html_input_element.c \
+ html_text_area_element.c \
+ html_opt_group_element.c \
+ html_option_element.c \
+ html_hr_element.c \
+ html_menu_element.c \
+ html_fieldset_element.c \
+ html_legend_element.c \
+ html_div_element.c \
+ html_paragraph_element.c \
+ html_heading_element.c \
+ html_quote_element.c \
+ html_pre_element.c \
+ html_br_element.c \
+ html_label_element.c \
+ html_ulist_element.c \
+ html_olist_element.c \
+ html_li_element.c \
+ html_font_element.c \
+ html_mod_element.c \
+ html_image_element.c \
+ html_object_element.c \
+ html_param_element.c \
+ html_map_element.c \
+ html_script_element.c \
+ html_tablecaption_element.c \
+ html_tablecell_element.c \
+ html_tablecol_element.c \
+ html_tablesection_element.c \
+ html_table_element.c \
+ html_tablerow_element.c \
+ html_frameset_element.c \
+ html_frame_element.c \
+ html_iframe_element.c \
+ html_isindex_element.c \
UNINMPLEMENTED_SOURCES := \
diff --git a/src/html/html_canvas_element.c b/src/html/html_canvas_element.c
new file mode 100644
index 0000000..2543e5b
--- /dev/null
+++ b/src/html/html_canvas_element.c
@@ -0,0 +1,190 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <dom/html/html_canvas_element.h>
+
+#include "html/html_document.h"
+#include "html/html_canvas_element.h"
+
+#include "core/node.h"
+#include "core/attr.h"
+#include "utils/utils.h"
+
+static struct dom_element_protected_vtable _protect_vtable = {
+ {
+ DOM_NODE_PROTECT_VTABLE_HTML_CANVAS_ELEMENT
+ },
+ DOM_HTML_CANVAS_ELEMENT_PROTECT_VTABLE
+};
+
+/**
+ * Create a dom_html_canvas_element object
+ *
+ * \param params The html element creation parameters
+ * \param ele The returned element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_canvas_element_create(
+ struct dom_html_element_create_params *params,
+ struct dom_html_canvas_element **ele)
+{
+ struct dom_node_internal *node;
+
+ *ele = malloc(sizeof(dom_html_canvas_element));
+ if (*ele == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* Set up vtables */
+ node = (struct dom_node_internal *) *ele;
+ node->base.vtable = &_dom_html_element_vtable;
+ node->vtable = &_protect_vtable;
+
+ return _dom_html_canvas_element_initialise(params, *ele);
+}
+
+/**
+ * Initialise a dom_html_canvas_element object
+ *
+ * \param params The html element creation parameters
+ * \param ele The dom_html_canvas_element object
+ * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
+ */
+dom_exception _dom_html_canvas_element_initialise(
+ struct dom_html_element_create_params *params,
+ struct dom_html_canvas_element *ele)
+{
+ return _dom_html_element_initialise(params, &ele->base);
+}
+
+/**
+ * Finalise a dom_html_canvas_element object
+ *
+ * \param ele The dom_html_canvas_element object
+ */
+void _dom_html_canvas_element_finalise(struct dom_html_canvas_element *ele)
+{
+ _dom_html_element_finalise(&ele->base);
+}
+
+/**
+ * Destroy a dom_html_canvas_element object
+ *
+ * \param ele The dom_html_canvas_element object
+ */
+void _dom_html_canvas_element_destroy(struct dom_html_canvas_element *ele)
+{
+ _dom_html_canvas_element_finalise(ele);
+ free(ele);
+}
+
+/*------------------------------------------------------------------------*/
+/* The protected virtual functions */
+
+/* The virtual function used to parse attribute value, see src/core/element.c
+ * for detail */
+dom_exception _dom_html_canvas_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed)
+{
+ UNUSED(ele);
+ UNUSED(name);
+
+ dom_string_ref(value);
+ *parsed = value;
+
+ return DOM_NO_ERR;
+}
+
+/* The virtual destroy function, see src/core/node.c for detail */
+void _dom_virtual_html_canvas_element_destroy(dom_node_internal *node)
+{
+ _dom_html_canvas_element_destroy((struct dom_html_canvas_element *) node);
+}
+
+/* The virtual copy function, see src/core/node.c for detail */
+dom_exception _dom_html_canvas_element_copy(
+ dom_node_internal *old, dom_node_internal **copy)
+{
+ dom_html_canvas_element *new_node;
+ dom_exception err;
+
+ new_node = malloc(sizeof(dom_html_canvas_element));
+ if (new_node == NULL)
+ return DOM_NO_MEM_ERR;
+
+ err = dom_html_canvas_element_copy_internal(old, new_node);
+ if (err != DOM_NO_ERR) {
+ free(new_node);
+ return err;
+ }
+
+ *copy = (dom_node_internal *) new_node;
+
+ return DOM_NO_ERR;
+}
+
+dom_exception _dom_html_canvas_element_copy_internal(
+ dom_html_canvas_element *old,
+ dom_html_canvas_element *new)
+{
+ dom_exception err;
+
+ err = dom_html_element_copy_internal(old, new);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
+
+ return DOM_NO_ERR;
+}
+
+/*-----------------------------------------------------------------------*/
+/* API functions */
+
+
+dom_exception
+dom_html_canvas_element_get_width(dom_html_canvas_element *canvas,
+ dom_ulong *width)
+{
+ return dom_html_element_get_dom_ulong_property(&canvas->base,
+ "width",
+ SLEN("width"),
+ width);
+}
+
+dom_exception
+dom_html_canvas_element_set_width(dom_html_canvas_element *canvas,
+ dom_ulong width)
+{
+ return dom_html_element_set_dom_ulong_property(&canvas->base,
+ "width",
+ SLEN("width"),
+ width);
+}
+
+dom_exception
+dom_html_canvas_element_get_height(dom_html_canvas_element *canvas,
+ dom_ulong *height)
+{
+ return dom_html_element_get_dom_ulong_property(&canvas->base,
+ "height",
+ SLEN("height"),
+ height);
+}
+
+dom_exception
+dom_html_canvas_element_set_height(dom_html_canvas_element *canvas,
+ dom_ulong height)
+{
+ return dom_html_element_set_dom_ulong_property(&canvas->base,
+ "height",
+ SLEN("height"),
+ height);
+}
+
diff --git a/src/html/html_canvas_element.h b/src/html/html_canvas_element.h
new file mode 100644
index 0000000..4cf3042
--- /dev/null
+++ b/src/html/html_canvas_element.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
+ */
+
+#ifndef dom_internal_html_canvas_element_h_
+#define dom_internal_html_canvas_element_h_
+
+#include <dom/html/html_canvas_element.h>
+
+#include "html/html_element.h"
+
+struct dom_html_canvas_element {
+ struct dom_html_element base;
+ /**< The base class */
+};
+
+/* Create a dom_html_canvas_element object */
+dom_exception _dom_html_canvas_element_create(
+ struct dom_html_element_create_params *params,
+ struct dom_html_canvas_element **ele);
+
+/* Initialise a dom_html_canvas_element object */
+dom_exception _dom_html_canvas_element_initialise(
+ struct dom_html_element_create_params *params,
+ struct dom_html_canvas_element *ele);
+
+/* Finalise a dom_html_canvas_element object */
+void _dom_html_canvas_element_finalise(struct dom_html_canvas_element *ele);
+
+/* Destroy a dom_html_canvas_element object */
+void _dom_html_canvas_element_destroy(struct dom_html_canvas_element *ele);
+
+/* The protected virtual functions */
+dom_exception _dom_html_canvas_element_parse_attribute(dom_element *ele,
+ dom_string *name, dom_string *value,
+ dom_string **parsed);
+
+void _dom_virtual_html_canvas_element_destroy(dom_node_internal *node);
+dom_exception _dom_html_canvas_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
+
+#define DOM_HTML_CANVAS_ELEMENT_PROTECT_VTABLE \
+ _dom_html_canvas_element_parse_attribute
+
+#define DOM_NODE_PROTECT_VTABLE_HTML_CANVAS_ELEMENT \
+ _dom_virtual_html_canvas_element_destroy, \
+ _dom_html_canvas_element_copy
+
+/* Helper functions*/
+dom_exception _dom_html_canvas_element_copy_internal(
+ dom_html_canvas_element *old,
+ dom_html_canvas_element *new);
+#define dom_html_canvas_element_copy_internal(o, n) \
+ _dom_html_canvas_element_copy_internal( \
+ (dom_html_canvas_element *) (o), \
+ (dom_html_canvas_element *) (n))
+
+
+#endif
diff --git a/src/html/html_document.c b/src/html/html_document.c
index 50a15a7..d978327 100644
--- a/src/html/html_document.c
+++ b/src/html/html_document.c
@@ -17,6 +17,7 @@
#include "html/html_head_element.h"
#include "html/html_body_element.h"
#include "html/html_base_element.h"
+#include "html/html_canvas_element.h"
#include "html/html_div_element.h"
#include "html/html_link_element.h"
#include "html/html_title_element.h"
@@ -771,6 +772,10 @@ _dom_html_document_create_element_internal(
exc = _dom_html_isindex_element_create(&params,
(dom_html_isindex_element **) result);
break;
+ case DOM_HTML_ELEMENT_TYPE_CANVAS:
+ exc = _dom_html_canvas_element_create(&params,
+ (dom_html_canvas_element **) result);
+ break;
case DOM_HTML_ELEMENT_TYPE_DATA:
case DOM_HTML_ELEMENT_TYPE_SPAN:
case DOM_HTML_ELEMENT_TYPE_TIME:
@@ -779,7 +784,6 @@ _dom_html_document_create_element_internal(
case DOM_HTML_ELEMENT_TYPE_METER:
case DOM_HTML_ELEMENT_TYPE_TRACK:
case DOM_HTML_ELEMENT_TYPE_VIDEO:
- case DOM_HTML_ELEMENT_TYPE_CANVAS:
case DOM_HTML_ELEMENT_TYPE_DIALOG:
case DOM_HTML_ELEMENT_TYPE_KEYGEN:
case DOM_HTML_ELEMENT_TYPE_OUTPUT:
diff --git a/src/html/html_element.c b/src/html/html_element.c
index 65a75ca..5d3df37 100644
--- a/src/html/html_element.c
+++ b/src/html/html_element.c
@@ -526,7 +526,7 @@ dom_exception dom_html_element_set_int32_t_property(dom_html_element *ele,
if (err != DOM_NO_ERR)
goto cleanup;
- err = dom_element_set_attribute(ele, svalue, str);
+ err = dom_element_set_attribute(ele, str, svalue);
dom_string_unref(svalue);
cleanup:
@@ -615,7 +615,7 @@ dom_exception dom_html_element_set_dom_ulong_property(dom_html_element *ele,
if (err != DOM_NO_ERR)
goto cleanup;
- err = dom_element_set_attribute(ele, svalue, str);
+ err = dom_element_set_attribute(ele, str, svalue);
dom_string_unref(svalue);
cleanup:
diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c
index ff549b2..0801d0a 100644
--- a/src/html/html_select_element.c
+++ b/src/html/html_select_element.c
@@ -213,6 +213,9 @@ dom_exception dom_html_select_element_get_selected_index(
dom_html_options_collection *col;
err = _dom_html_select_element_make_collection(ele, &col);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
err = dom_html_options_collection_get_length(col, &len);
if (err != DOM_NO_ERR) {
@@ -266,6 +269,9 @@ dom_exception dom_html_select_element_set_selected_index(
dom_html_options_collection *col;
err = _dom_html_select_element_make_collection(ele, &col);
+ if (err != DOM_NO_ERR) {
+ return err;
+ }
err = dom_html_options_collection_item(col,
index, &option);
diff --git a/src/html/html_title_element.c b/src/html/html_title_element.c
index 39e898a..440b9d5 100644
--- a/src/html/html_title_element.c
+++ b/src/html/html_title_element.c
@@ -157,15 +157,7 @@ dom_exception _dom_html_title_element_copy_internal(
dom_exception dom_html_title_element_get_text(dom_html_title_element *ele,
dom_string **text)
{
- dom_node_internal *node = (dom_node_internal *) ele;
- dom_node_internal *n = node->first_child;
-
- /* There should be only one child of title element */
- assert(node->first_child == node->last_child);
- /* And it should be a text node */
- assert(n->type == DOM_TEXT_NODE);
-
- return dom_characterdata_get_data(n, text);
+ return dom_node_get_text_content(ele, text);
}
/**
@@ -178,14 +170,6 @@ dom_exception dom_html_title_element_get_text(dom_html_title_element *ele,
dom_exception dom_html_title_element_set_text(dom_html_title_element *ele,
dom_string *text)
{
- dom_node_internal *node = (dom_node_internal *) ele;
- dom_node_internal *n = node->first_child;
-
- /* There should be only one child of title element */
- assert(node->first_child == node->last_child);
- /* And it should be a text node */
- assert(n->type == DOM_TEXT_NODE);
-
- return dom_characterdata_set_data(n, text);
+ return dom_node_set_text_content(ele, text);
}
diff --git a/src/utils/namespace.c b/src/utils/namespace.c
index c18e24b..e2d249f 100644
--- a/src/utils/namespace.c
+++ b/src/utils/namespace.c
@@ -77,13 +77,12 @@ static dom_exception _dom_namespace_initialise(void)
return DOM_NO_ERR;
}
-#ifdef FINALISE_NAMESPACE
/**
* Finalise the namespace component
*
* \return DOM_NO_ERR on success.
*/
-dom_exception _dom_namespace_finalise(void)
+dom_exception dom_namespace_finalise(void)
{
int i;
@@ -106,7 +105,6 @@ dom_exception _dom_namespace_finalise(void)
return DOM_NO_ERR;
}
-#endif
/**
* Ensure a QName is valid