summaryrefslogtreecommitdiff
path: root/src/events
diff options
context:
space:
mode:
Diffstat (limited to 'src/events')
-rw-r--r--src/events/dispatch.c12
-rw-r--r--src/events/event.c2
-rw-r--r--src/events/event.h2
-rw-r--r--src/events/keyboard_event.c228
-rw-r--r--src/events/keyboard_event.h18
-rw-r--r--src/events/mouse_event.c2
-rw-r--r--src/events/mouse_multi_wheel_event.c2
-rw-r--r--src/events/mouse_wheel_event.c2
-rw-r--r--src/events/mutation_event.c2
-rw-r--r--src/events/mutation_name_event.c2
-rw-r--r--src/events/text_event.c2
-rw-r--r--src/events/ui_event.c5
12 files changed, 188 insertions, 91 deletions
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/event.c b/src/events/event.c
index 3fe9978..26b245e 100644
--- a/src/events/event.c
+++ b/src/events/event.c
@@ -18,7 +18,7 @@
static void _virtual_dom_event_destroy(dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_event_destroy
};
diff --git a/src/events/event.h b/src/events/event.h
index 857f20a..7cada7b 100644
--- a/src/events/event.h
+++ b/src/events/event.h
@@ -45,7 +45,7 @@ struct dom_event {
uint32_t refcnt; /**< The reference count of this object */
- struct dom_event_private_vtable *vtable;
+ const struct dom_event_private_vtable *vtable;
/**< The private virtual function table of Event */
bool in_dispatch; /**< Whether this event is in dispatch */
bool is_initialised; /**< Whether this event is initialised */
diff --git a/src/events/keyboard_event.c b/src/events/keyboard_event.c
index fb29c18..d1fa1ca 100644
--- a/src/events/keyboard_event.c
+++ b/src/events/keyboard_event.c
@@ -15,14 +15,14 @@
static void _virtual_dom_keyboard_event_destroy(struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_keyboard_event_destroy
};
/* 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/mouse_event.c b/src/events/mouse_event.c
index b3b2154..ac1d142 100644
--- a/src/events/mouse_event.c
+++ b/src/events/mouse_event.c
@@ -15,7 +15,7 @@
static void _virtual_dom_mouse_event_destroy(struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_mouse_event_destroy
};
diff --git a/src/events/mouse_multi_wheel_event.c b/src/events/mouse_multi_wheel_event.c
index bcbe8d5..a42085a 100644
--- a/src/events/mouse_multi_wheel_event.c
+++ b/src/events/mouse_multi_wheel_event.c
@@ -16,7 +16,7 @@
static void _virtual_dom_mouse_multi_wheel_event_destroy(
struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_mouse_multi_wheel_event_destroy
};
diff --git a/src/events/mouse_wheel_event.c b/src/events/mouse_wheel_event.c
index d59eab1..5d6bdd6 100644
--- a/src/events/mouse_wheel_event.c
+++ b/src/events/mouse_wheel_event.c
@@ -15,7 +15,7 @@
static void _virtual_dom_mouse_wheel_event_destroy(struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_mouse_wheel_event_destroy
};
diff --git a/src/events/mutation_event.c b/src/events/mutation_event.c
index df92c5f..2c5ffdc 100644
--- a/src/events/mutation_event.c
+++ b/src/events/mutation_event.c
@@ -11,7 +11,7 @@
static void _virtual_dom_mutation_event_destroy(struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_mutation_event_destroy
};
diff --git a/src/events/mutation_name_event.c b/src/events/mutation_name_event.c
index e0ba82e..13a51b5 100644
--- a/src/events/mutation_name_event.c
+++ b/src/events/mutation_name_event.c
@@ -14,7 +14,7 @@
static void _virtual_dom_mutation_name_event_destroy(struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_mutation_name_event_destroy
};
diff --git a/src/events/text_event.c b/src/events/text_event.c
index 3437716..d0d2706 100644
--- a/src/events/text_event.c
+++ b/src/events/text_event.c
@@ -12,7 +12,7 @@
static void _virtual_dom_text_event_destroy(struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_text_event_destroy
};
diff --git a/src/events/ui_event.c b/src/events/ui_event.c
index 4fac3b6..672f999 100644
--- a/src/events/ui_event.c
+++ b/src/events/ui_event.c
@@ -11,14 +11,14 @@
static void _virtual_dom_ui_event_destroy(struct dom_event *evt);
-static struct dom_event_private_vtable _event_vtable = {
+static const struct dom_event_private_vtable _event_vtable = {
_virtual_dom_ui_event_destroy
};
/* 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);
}