summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-11-03 22:10:17 (GMT)
committer Daniel Silverstone <dsilvers@digital-scurf.org>2012-11-03 22:10:17 (GMT)
commitc27dd9093614b9df998f994ee2fe530782e1d890 (patch)
treefaa6ebabb6a11b53778a859d593110ab7ea00618
parent45048d167c9f1e9ca31317ce19a3e9ca23968d07 (diff)
downloadlibdom-c27dd9093614b9df998f994ee2fe530782e1d890.tar.gz
libdom-c27dd9093614b9df998f994ee2fe530782e1d890.tar.bz2
Remove ability to dispatch a generic event as a ptr+len, and memoise all previous callsites
-rw-r--r--src/events/dispatch.c9
-rw-r--r--src/events/dispatch.h2
-rw-r--r--src/html/html_document_strings.h7
-rw-r--r--src/html/html_form_element.c20
-rw-r--r--src/html/html_input_element.c40
-rw-r--r--src/html/html_select_element.c20
-rw-r--r--src/html/html_text_area_element.c30
7 files changed, 76 insertions, 52 deletions
diff --git a/src/events/dispatch.c b/src/events/dispatch.c
index 8f97614..64664c7 100644
--- a/src/events/dispatch.c
+++ b/src/events/dispatch.c
@@ -242,23 +242,18 @@ cleanup:
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_dispatch_generic_event(dom_document *doc,
- dom_event_target *et, const uint8_t *name, size_t len,
+ dom_event_target *et, dom_string *event_name,
bool bubble, bool cancelable, bool *success)
{
struct dom_event *evt;
- dom_string *type = NULL;
dom_exception err;
err = _dom_event_create(doc, &evt);
if (err != DOM_NO_ERR)
return err;
- err = dom_string_create(name, len, &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ err = dom_event_init(evt, event_name, bubble, cancelable);
- err = dom_event_init(evt, type, bubble, cancelable);
- dom_string_unref(type);
if (err != DOM_NO_ERR) {
goto cleanup;
}
diff --git a/src/events/dispatch.h b/src/events/dispatch.h
index 632fc98..56f6930 100644
--- a/src/events/dispatch.h
+++ b/src/events/dispatch.h
@@ -71,7 +71,7 @@ dom_exception __dom_dispatch_subtree_modified_event(dom_document *doc,
/* Dispatch a generic event */
dom_exception _dom_dispatch_generic_event(dom_document *doc,
- dom_event_target *et, const uint8_t *name, size_t len,
+ dom_event_target *et, dom_string *event_name,
bool bubble, bool cancelable, bool *success);
#endif
diff --git a/src/html/html_document_strings.h b/src/html/html_document_strings.h
index fa9c4e4..f2d6fa2 100644
--- a/src/html/html_document_strings.h
+++ b/src/html/html_document_strings.h
@@ -95,6 +95,13 @@ HTML_DOCUMENT_STRINGS_ACTION1(selected)
/* HTMLSelectElement strings */
HTML_DOCUMENT_STRINGS_ACTION(select_multiple,select-multiple)
HTML_DOCUMENT_STRINGS_ACTION(select_one,select-one)
+/* Some event strings for later */
+HTML_DOCUMENT_STRINGS_ACTION1(blur)
+HTML_DOCUMENT_STRINGS_ACTION1(focus)
+HTML_DOCUMENT_STRINGS_ACTION1(select)
+HTML_DOCUMENT_STRINGS_ACTION1(click)
+HTML_DOCUMENT_STRINGS_ACTION1(submit)
+HTML_DOCUMENT_STRINGS_ACTION1(reset)
/* Names for elements which get specialised. */
HTML_DOCUMENT_STRINGS_ACTION1(HTML)
HTML_DOCUMENT_STRINGS_ACTION1(HEAD)
diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c
index 55ec0e9..808383d 100644
--- a/src/html/html_form_element.c
+++ b/src/html/html_form_element.c
@@ -235,16 +235,18 @@ SIMPLE_GET_SET(target)
*/
dom_exception dom_html_form_element_submit(dom_html_form_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/* Dispatch an event and let the default action handler to deal with
* the submit action, and a 'submit' event is bubbling and cancelable
*/
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "submit", SLEN("submit"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *)doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_submit], true,
+ true, &success);
}
/**
@@ -255,16 +257,18 @@ dom_exception dom_html_form_element_submit(dom_html_form_element *ele)
*/
dom_exception dom_html_form_element_reset(dom_html_form_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/* Dispatch an event and let the default action handler to deal with
* the reset action, and a 'reset' event is bubbling and cancelable
*/
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "reset", SLEN("reset"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *) doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_reset], true,
+ true, &success);
}
/*-----------------------------------------------------------------------*/
diff --git a/src/html/html_input_element.c b/src/html/html_input_element.c
index 9586abb..bab79f2 100644
--- a/src/html/html_input_element.c
+++ b/src/html/html_input_element.c
@@ -410,14 +410,16 @@ dom_exception _dom_html_input_element_set_form(
*/
dom_exception dom_html_input_element_blur(dom_html_input_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "blur", SLEN("blur"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *) doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_blur], true,
+ true, &success);
}
/**
@@ -428,14 +430,16 @@ dom_exception dom_html_input_element_blur(dom_html_input_element *ele)
*/
dom_exception dom_html_input_element_focus(dom_html_input_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "focus", SLEN("focus"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *)doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_focus], true,
+ true, &success);
}
/**
@@ -446,14 +450,16 @@ dom_exception dom_html_input_element_focus(dom_html_input_element *ele)
*/
dom_exception dom_html_input_element_select(dom_html_input_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "select", SLEN("select"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *)doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_select], true,
+ true, &success);
}
/**
@@ -464,14 +470,16 @@ dom_exception dom_html_input_element_select(dom_html_input_element *ele)
*/
dom_exception dom_html_input_element_click(dom_html_input_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this is meant to check/uncheck boxes, radios etc */
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "click", SLEN("click"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *)doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_click], true,
+ true, &success);
}
diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c
index 12ea6ba..8de5dff 100644
--- a/src/html/html_select_element.c
+++ b/src/html/html_select_element.c
@@ -566,14 +566,16 @@ dom_exception dom_html_select_element_remove(dom_html_select_element *ele,
*/
dom_exception dom_html_select_element_blur(struct dom_html_select_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "blur", SLEN("blur"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *) doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_blur], true,
+ true, &success);
}
/**
@@ -584,14 +586,16 @@ dom_exception dom_html_select_element_blur(struct dom_html_select_element *ele)
*/
dom_exception dom_html_select_element_focus(struct dom_html_select_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "focus", SLEN("focus"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *) doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_focus], true,
+ true, &success);
}
diff --git a/src/html/html_text_area_element.c b/src/html/html_text_area_element.c
index 1c7534c..eea5b4e 100644
--- a/src/html/html_text_area_element.c
+++ b/src/html/html_text_area_element.c
@@ -433,14 +433,16 @@ dom_exception _dom_html_text_area_element_set_form(
*/
dom_exception dom_html_text_area_element_blur(dom_html_text_area_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "blur", SLEN("blur"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *) doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_blur], true,
+ true, &success);
}
/**
@@ -451,14 +453,16 @@ dom_exception dom_html_text_area_element_blur(dom_html_text_area_element *ele)
*/
dom_exception dom_html_text_area_element_focus(dom_html_text_area_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "focus", SLEN("focus"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *)doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_focus], true,
+ true, &success);
}
/**
@@ -469,12 +473,14 @@ dom_exception dom_html_text_area_element_focus(dom_html_text_area_element *ele)
*/
dom_exception dom_html_text_area_element_select(dom_html_text_area_element *ele)
{
- struct dom_document *doc = dom_node_get_owner(ele);
+ struct dom_html_document *doc =
+ (dom_html_document *) dom_node_get_owner(ele);
bool success = false;
assert(doc != NULL);
/** \todo Is this event (a) default (b) bubbling and (c) cancelable? */
- return _dom_dispatch_generic_event(doc, (dom_event_target *) ele,
- (const uint8_t *) "select", SLEN("select"), true,
- true, &success);
+ return _dom_dispatch_generic_event((dom_document *)doc,
+ (dom_event_target *) ele,
+ doc->memoised[hds_select], true,
+ true, &success);
}