Exemple #1
0
JSObject *
LM_ReflectNamedAnchor(MWContext *context, lo_NameList *name_rec,
                      PA_Tag * tag, int32 layer_id, uint index)
{
    JSObject *obj, *array_obj, *document;
    MochaDecoder *decoder;
    JSContext *cx;
    JSObjectArray *array;
    JSAnchor *named_anchor;
    lo_TopState *top_state;
    PRHashTable *map;
    JSString *str;

    obj = name_rec->mocha_object;
    if (obj)
        return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
        return NULL;
    cx = decoder->js_context;

    top_state = lo_GetMochaTopState(context);
    if (top_state->resize_reload) {
        map = lm_GetIdToObjectMap(decoder);

        if (map)
            obj = (JSObject *)PR_HashTableLookup(map,
                                         LM_GET_MAPPING_KEY(LM_NAMEDANCHORS,
                                                            layer_id, index));
        if (obj) {
            name_rec->mocha_object = obj;
            LM_PutMochaDecoder(decoder);
            return obj;
        }
    }

    /* Get the document object that will hold this anchor */
    document = lm_GetDocumentFromLayerId(decoder, layer_id);
    if (!document) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }

    array_obj = lm_GetNameArray(decoder, document);
    if (!array_obj) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }
    array = JS_GetPrivate(cx, array_obj);
    if (!array) {
        LM_PutMochaDecoder(decoder);
	return NULL;
    }

    named_anchor = JS_malloc(cx, sizeof *named_anchor);
    if (!named_anchor) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }
    XP_BZERO(named_anchor, sizeof *named_anchor);

    obj = JS_NewObject(cx, &lm_anchor_class, decoder->anchor_prototype,
		       document);

    if (!obj || !JS_SetPrivate(cx, obj, named_anchor)) {
        JS_free(cx, named_anchor);
        LM_PutMochaDecoder(decoder);
        return NULL;
    }

    /* Put obj into the document.anchors array. */
    JS_DefineProperty(cx, array_obj, (char *) name_rec->name,
		      OBJECT_TO_JSVAL(obj), NULL, NULL,
		      JSPROP_ENUMERATE|JSPROP_READONLY);
    JS_AliasElement(cx, array_obj, (char *) name_rec->name, index);

    /* Put it in the index to object hash table */
    map = lm_GetIdToObjectMap(decoder);
    if (map) {
        PR_HashTableAdd(map,
                        LM_GET_MAPPING_KEY(LM_NAMEDANCHORS, layer_id, index),
                        obj);
    }
    if ((jsint) index >= array->length)
	array->length = index + 1;

    named_anchor->decoder = HOLD_BACK_COUNT(decoder);
    named_anchor->layer_id = layer_id;
    named_anchor->index = index;
    if (name_rec->element && name_rec->element->type == LO_TEXT) {
	str = lm_LocalEncodingToStr(context, 
				    (char *) name_rec->element->lo_text.text);
	if (!str || !JS_LockGCThing(cx, str)) {
	    LM_PutMochaDecoder(decoder);
	    return NULL;
	}
	named_anchor->text = str;
    }
    str = JS_NewStringCopyZ(cx, (char *) name_rec->name);
    if (!str || !JS_LockGCThing(cx, str)) {
        LM_PutMochaDecoder(decoder);
	return NULL;
    }
    named_anchor->name = str;

    name_rec->mocha_object = obj;

    /* see if there are any attributes for event handlers */
    if(tag) {
        PA_Block onlocate, id;

	/* don't hold the layout lock across compiles */
	LO_UnlockLayout();

        onlocate = lo_FetchParamValue(context, tag, PARAM_ONLOCATE);
        id = lo_FetchParamValue(context, tag, PARAM_ID);
        if (onlocate) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, obj,
					  PARAM_ONLOCATE, onlocate);
            PA_FREE(onlocate);
        }
	if (id)
	    PA_FREE(id);
	LO_LockLayout();
    }

    LM_PutMochaDecoder(decoder);
    return obj;
}
Exemple #2
0
JSObject *
LM_ReflectEmbed(MWContext *context, LO_EmbedStruct *lo_embed,
                PA_Tag * tag, int32 layer_id, uint index)
{
    JSObject *obj, *array_obj, *outer_obj, *document;
    MochaDecoder *decoder;
    JSContext *cx;
    char *name;
    int i;

    obj = lo_embed->mocha_object;
    if (obj)
        return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
        return NULL;

    cx = decoder->js_context;

    /* get the name */
    name = 0;
    for (i = 0; i < lo_embed->attribute_cnt; i++) {
        if (!XP_STRCASECMP(lo_embed->attribute_list[i], "name")) {
            name = strdup(lo_embed->value_list[i]);
            break;
        }
    }

    /* Get the document object that will hold this applet */
    document = lm_GetDocumentFromLayerId(decoder, layer_id);
    if (!document) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }
    
    array_obj = lm_GetEmbedArray(decoder, document);
    if (!array_obj) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }

    /* XXX should pass thru ReallyReflectApplet to whatever calls NewObject */
    outer_obj = lm_GetOuterObject(decoder);

    /* this function does the real work */
    obj = lm_ReallyReflectEmbed(context, lo_embed, layer_id, index);

    if (!obj)
        goto out;

    /* put it in the embed array */
    if (!lm_AddObjectToArray(cx, array_obj, name, index, obj)) {
	obj = NULL;
	goto out;
    }

    /* put it in the document scope */
    if (name && !JS_DefineProperty(cx, outer_obj, name, OBJECT_TO_JSVAL(obj),
				   NULL, NULL,
				   JSPROP_ENUMERATE | JSPROP_READONLY)) {
	PR_LOG(Moja, warn, ("failed to define embed 0x%x as %s\n",
			    lo_embed, name));
	/* XXX remove it altogether? */
    }

    /* cache it in layout data structure */
    lo_embed->mocha_object = obj;

out:
    LM_PutMochaDecoder(decoder);
    return obj;
}
Exemple #3
0
JSObject *
LM_ReflectLink(MWContext *context, LO_AnchorData *anchor_data, PA_Tag * tag,
               int32 layer_id, uint index)
{
    JSObject *obj, *array_obj, *document;
    MochaDecoder *decoder;
    JSContext *cx;
    JSURL *url;
    lo_TopState *top_state;
    PRHashTable *map;

    anchor_data = LO_GetLinkByIndex(context, layer_id, index);
    if (!anchor_data)
	return NULL;

    obj = anchor_data->mocha_object;
    if (obj)
	return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
	return NULL;
    cx = decoder->js_context;

    top_state = lo_GetMochaTopState(context);
    if (top_state->resize_reload) {
        map = lm_GetIdToObjectMap(decoder);

        if (map)
            obj = (JSObject *)PR_HashTableLookup(map,
                             LM_GET_MAPPING_KEY(LM_LINKS, layer_id, index));
        if (obj) {
            anchor_data->mocha_object = obj;
            LM_PutMochaDecoder(decoder);
            return obj;
        }
    }

    /* Get the document object that will hold this link */
    document = lm_GetDocumentFromLayerId(decoder, layer_id);
    if (!document) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }

    array_obj = lm_GetLinkArray(decoder, document);
    if (!array_obj) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }

    url = lm_NewURL(cx, decoder, anchor_data, document);

    if (!url) {
	LM_PutMochaDecoder(decoder);
	return NULL;
    }
    url->index = index;
    url->layer_id = layer_id;
    obj = url->url_object;

    /* XXX should find a name/id to pass in */
    /* put it in the links array */
    if (!lm_AddObjectToArray(cx, array_obj, NULL, index, obj)) {
	LM_PutMochaDecoder(decoder);
    	return NULL;
    }

    /* Put it in the index to object hash table */
    map = lm_GetIdToObjectMap(decoder);
    if (map)
        PR_HashTableAdd(map, LM_GET_MAPPING_KEY(LM_LINKS, layer_id, index),
                        obj);

    anchor_data->mocha_object = obj;
    LM_PutMochaDecoder(decoder);

    /* see if there are any event handlers we need to reflect */
    if(tag) {

	PA_Block onclick, onmouseover, onmouseout, onmousedown, onmouseup, ondblclick, id;

	/* don't hold the layout lock across compiles */
	LO_UnlockLayout();

	onclick = lo_FetchParamValue(context, tag, PARAM_ONCLICK);
	onmouseover = lo_FetchParamValue(context, tag, PARAM_ONMOUSEOVER);
	onmouseout  = lo_FetchParamValue(context, tag, PARAM_ONMOUSEOUT);
	onmousedown = lo_FetchParamValue(context, tag, PARAM_ONMOUSEDOWN);
	onmouseup   = lo_FetchParamValue(context, tag, PARAM_ONMOUSEUP);
	ondblclick  = lo_FetchParamValue(context, tag, PARAM_ONDBLCLICK);
        id = lo_FetchParamValue(context, tag, PARAM_ID);

	if (onclick) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
				          PARAM_ONCLICK, onclick);
	    PA_FREE(onclick);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmouseover) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEOVER, onmouseover);
	    PA_FREE(onmouseover);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmouseout) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEOUT, onmouseout);
	    PA_FREE(onmouseout);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmousedown) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEDOWN, onmousedown);
	    PA_FREE(onmousedown);
	    anchor_data->event_handler_present = TRUE;
	}
	if (onmouseup) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONMOUSEUP, onmouseup);
	    PA_FREE(onmouseup);
	    anchor_data->event_handler_present = TRUE;
	}
	if (ondblclick) {
	    (void) lm_CompileEventHandler(decoder, id, tag->data,
					  tag->newline_count, url->url_object,
					  PARAM_ONDBLCLICK, ondblclick);
	    PA_FREE(ondblclick);
	    anchor_data->event_handler_present = TRUE;
	}
	if (id)
	    PA_FREE(id);
        LO_LockLayout();
    }

    return obj;
}