mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
DOM ecmascript: register/unregister anchors, applets, forms, images and links.
This commit is contained in:
parent
6efff6f21d
commit
fc8c5fa024
@ -7,6 +7,7 @@
|
||||
#include "document/dom/ecmascript/spidermonkey.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLAnchorElement.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLDocument.h"
|
||||
#include "dom/node.h"
|
||||
|
||||
static JSBool
|
||||
@ -187,6 +188,10 @@ make_A_object(JSContext *ctx, struct dom_node *node)
|
||||
node->data.element.html_data = mem_calloc(1, sizeof(struct A_struct));
|
||||
if (node->data.element.html_data) {
|
||||
node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLAnchorElement_class, o->HTMLElement_object, NULL);
|
||||
/* It must be here, because ctx is used by register functions. */
|
||||
node->ecmascript_ctx = ctx;
|
||||
register_anchor(node);
|
||||
register_link(node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,6 +200,8 @@ done_A_object(struct dom_node *node)
|
||||
{
|
||||
struct A_struct *d = node->data.element.html_data;
|
||||
|
||||
unregister_anchor(node);
|
||||
unregister_link(node);
|
||||
mem_free_if(d->access_key);
|
||||
mem_free_if(d->charset);
|
||||
mem_free_if(d->coords);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "document/dom/ecmascript/spidermonkey.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLAppletElement.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLDocument.h"
|
||||
#include "dom/node.h"
|
||||
|
||||
static JSBool
|
||||
@ -160,6 +161,8 @@ make_APPLET_object(JSContext *ctx, struct dom_node *node)
|
||||
node->data.element.html_data = mem_calloc(1, sizeof(struct APPLET_struct));
|
||||
if (node->data.element.html_data) {
|
||||
node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLAppletElement_class, o->HTMLElement_object, NULL);
|
||||
node->ecmascript_ctx = ctx;
|
||||
register_applet(node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,6 +171,7 @@ done_APPLET_object(struct dom_node *node)
|
||||
{
|
||||
struct APPLET_struct *d = node->data.element.html_data;
|
||||
|
||||
unregister_applet(node);
|
||||
mem_free_if(d->align);
|
||||
mem_free_if(d->alt);
|
||||
mem_free_if(d->archive);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "document/dom/ecmascript/spidermonkey.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLAreaElement.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLDocument.h"
|
||||
#include "dom/node.h"
|
||||
|
||||
static JSBool
|
||||
@ -140,6 +141,8 @@ make_AREA_object(JSContext *ctx, struct dom_node *node)
|
||||
node->data.element.html_data = mem_calloc(1, sizeof(struct AREA_struct));
|
||||
if (node->data.element.html_data) {
|
||||
node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLAreaElement_class, o->HTMLElement_object, NULL);
|
||||
node->ecmascript_ctx = ctx;
|
||||
register_link(node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,6 +151,7 @@ done_AREA_object(struct dom_node *node)
|
||||
{
|
||||
struct AREA_struct *d = node->data.element.html_data;
|
||||
|
||||
unregister_link(node);
|
||||
mem_free_if(d->access_key);
|
||||
mem_free_if(d->alt);
|
||||
mem_free_if(d->coords);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "document/dom/ecmascript/spidermonkey/Document.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLCollection.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLDocument.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLElement.h"
|
||||
#include "dom/node.h"
|
||||
|
||||
static JSBool
|
||||
@ -266,3 +267,131 @@ const JSClass HTMLDocument_class = {
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Node_finalize
|
||||
};
|
||||
|
||||
static struct dom_node *
|
||||
get_document(struct dom_node *node)
|
||||
{
|
||||
JSContext *ctx = node->ecmascript_ctx;
|
||||
struct html_objects *o;
|
||||
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
o = JS_GetContextPrivate(ctx);
|
||||
if (!o)
|
||||
return NULL;
|
||||
return o->document;
|
||||
}
|
||||
|
||||
void
|
||||
register_image(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
add_to_dom_node_list(&d->images, node, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
unregister_image(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
|
||||
del_from_dom_node_list(d->images, node);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
register_applet(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
add_to_dom_node_list(&d->applets, node, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
unregister_applet(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
|
||||
del_from_dom_node_list(d->applets, node);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
register_link(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
add_to_dom_node_list(&d->links, node, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
unregister_link(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
|
||||
del_from_dom_node_list(d->links, node);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
register_form(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
add_to_dom_node_list(&d->forms, node, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
unregister_form(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
|
||||
del_from_dom_node_list(d->forms, node);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
register_anchor(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
add_to_dom_node_list(&d->anchors, node, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
unregister_anchor(struct dom_node *node)
|
||||
{
|
||||
struct dom_node *doc = get_document(node);
|
||||
|
||||
if (doc) {
|
||||
struct HTMLDocument_struct *d = doc->data.document.html_data;
|
||||
|
||||
del_from_dom_node_list(d->anchors, node);
|
||||
}
|
||||
}
|
||||
|
@ -24,4 +24,15 @@ struct HTMLDocument_struct {
|
||||
struct dom_node_list *anchors;
|
||||
};
|
||||
|
||||
void register_image(struct dom_node *node);
|
||||
void unregister_image(struct dom_node *node);
|
||||
void register_applet(struct dom_node *node);
|
||||
void unregister_applet(struct dom_node *node);
|
||||
void register_link(struct dom_node *node);
|
||||
void unregister_link(struct dom_node *node);
|
||||
void register_form(struct dom_node *node);
|
||||
void unregister_form(struct dom_node *node);
|
||||
void register_anchor(struct dom_node *node);
|
||||
void unregister_anchor(struct dom_node *node);
|
||||
|
||||
#endif
|
||||
|
@ -20,6 +20,7 @@ struct HTMLElement_struct {
|
||||
};
|
||||
|
||||
struct html_objects { /* FIXME: Better name for this type. */
|
||||
struct dom_node *document;
|
||||
JSObject *Node_object;
|
||||
JSObject *Element_object;
|
||||
JSObject *HTMLElement_object;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "document/dom/ecmascript/spidermonkey.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLCollection.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLDocument.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLFormElement.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLInputElement.h"
|
||||
#include "dom/node.h"
|
||||
@ -178,6 +179,8 @@ make_FORM_object(JSContext *ctx, struct dom_node *node)
|
||||
form = node->data.element.html_data;
|
||||
if (form) {
|
||||
node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLFormElement_class, o->HTMLElement_object, NULL);
|
||||
node->ecmascript_ctx = ctx;
|
||||
register_form(node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,6 +255,7 @@ done_FORM_object(struct dom_node *node)
|
||||
{
|
||||
struct FORM_struct *d = node->data.element.html_data;
|
||||
|
||||
unregister_form(node);
|
||||
if (d->elements)
|
||||
done_elements(d->elements);
|
||||
mem_free_if(d->name);
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "document/dom/ecmascript/spidermonkey.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLDocument.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLImageElement.h"
|
||||
#include "dom/node.h"
|
||||
|
||||
@ -165,6 +166,8 @@ make_IMG_object(JSContext *ctx, struct dom_node *node)
|
||||
node->data.element.html_data = mem_calloc(1, sizeof(struct IMG_struct));
|
||||
if (node->data.element.html_data) {
|
||||
node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLImageElement_class, o->HTMLElement_object, NULL);
|
||||
node->ecmascript_ctx = ctx;
|
||||
register_image(node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,6 +176,7 @@ done_IMG_object(struct dom_node *node)
|
||||
{
|
||||
struct IMG_struct *d = node->data.element.html_data;
|
||||
|
||||
unregister_image(node);
|
||||
mem_free_if(d->name);
|
||||
mem_free_if(d->align);
|
||||
mem_free_if(d->alt);
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "document/dom/ecmascript/spidermonkey.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/Node.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLDocument.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLFormElement.h"
|
||||
#include "document/dom/ecmascript/spidermonkey/html/HTMLObjectElement.h"
|
||||
#include "dom/node.h"
|
||||
@ -213,7 +214,9 @@ make_OBJECT_object(JSContext *ctx, struct dom_node *node)
|
||||
node->data.element.html_data = mem_calloc(1, sizeof(struct OBJECT_struct));
|
||||
if (node->data.element.html_data) {
|
||||
node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLObjectElement_class, o->HTMLElement_object, NULL);
|
||||
node->ecmascript_ctx = ctx;
|
||||
register_form_element(node);
|
||||
register_applet(node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,6 +225,7 @@ done_OBJECT_object(struct dom_node *node)
|
||||
{
|
||||
struct OBJECT_struct *d = node->data.element.html_data;
|
||||
|
||||
unregister_applet(node);
|
||||
unregister_form_element(d->form, node);
|
||||
mem_free_if(d->code);
|
||||
mem_free_if(d->align);
|
||||
|
Loading…
x
Reference in New Issue
Block a user