image->border_width = IMAGE_DEF_BORDER; } if (!DOM_StyleGetProperty(cx, db, (DOM_Node *)element, PADDING_STYLE, &entry)) return; if (entry) {  if (!DOM_GetCleanEntryData(cx, entry, lo_SSUnitsToData, &image->border_vert_space, context)) return; image->border_horiz_space = image->border_vert_space; } else {  image->border_vert_space = IMAGE_DEF_VERTICAL_SPACE; image->border_horiz_space = IMAGE_DEF_HORIZONTAL_SPACE; } #else
image->border_width = IMAGE_DEF_BORDER; } if (!DOM_StyleGetProperty(cx, db, (DOM_Node *)element, PADDING_STYLE, &entry)) goto error; if (entry) {  if (!DOM_GetCleanEntryData(cx, entry, lo_SSUnitsToData, &image->border_vert_space, context)) goto error; image->border_horiz_space = image->border_vert_space; } else {  image->border_vert_space = IMAGE_DEF_VERTICAL_SPACE; image->border_horiz_space = IMAGE_DEF_HORIZONTAL_SPACE; }  #else
lo_FormatImage(MWContext *context, lo_DocState *state, PA_Tag *tag){    LO_ImageStruct *image;    LO_TextAttr *tptr = NULL;    PA_Block buff;    char *str;    int32 val;    /* int32 doc_width; */    Bool is_a_form;    XP_ObserverList image_obs_list;   /* List of observers for an image request. */    lo_DocLists *doc_lists;    int32 layer_id;#ifdef DOM    JSContext *cx = context->mocha_context;    DOM_StyleDatabase *db = state->top_state->style_db;    DOM_Element *element = (DOM_Element *)ACTIVE_NODE(state);    DOM_AttributeEntry *entry;#endif    doc_lists = lo_GetCurrentDocLists(state);    #ifdef DOM    tptr = lo_GetCurrentTextAttr(state, context);#else    if (state->font_stack)        tptr = state->font_stack->text_attr;#endif	/*	 * Fill in the image structure with default data	 */    image = lo_new_image_element(context, state, tag->edit_element, tptr);    if (!image)        return;		/*	image->ele_id = NEXT_ELEMENT;	image->x = state->x;	image->y = state->y;	*/	image->anchor_href = state->current_anchor;#ifdef DOM#ifdef DEBUG_shaver        fprintf(stderr, "----GETTING IMAGE DATA----\n");#endif        if (!DOM_StyleGetProperty(cx, db, (DOM_Node *)element,                                  BORDERWIDTH_STYLE, &entry))            return;        if (entry) {            /* XXX handle borderTop/borderBottom/borderLeft/borderRight */            if (!DOM_GetCleanEntryData(cx, entry, lo_SSUnitsToData,                                       &image->border_width, context))                return;        } else {            /* no style value for image border */#ifdef DEBUG_shaver            fprintf(stderr, "no style value for IMG.border\n");#endif            image->border_width = IMAGE_DEF_BORDER;        }        if (!DOM_StyleGetProperty(cx, db, (DOM_Node *)element,                                  PADDING_STYLE, &entry))            return;        if (entry) {            /* XXX handle paddingTop/paddingBottom/paddingLeft/paddingRight */            if (!DOM_GetCleanEntryData(cx, entry, lo_SSUnitsToData,                                       &image->border_vert_space, context))                return;            image->border_horiz_space = image->border_vert_space;        } else {            /* no style value for image padding */            image->border_vert_space = IMAGE_DEF_VERTICAL_SPACE;            image->border_horiz_space = IMAGE_DEF_HORIZONTAL_SPACE;        }#else            	if (image->anchor_href != NULL)	{		image->border_width = IMAGE_DEF_ANCHOR_BORDER;	}	else	{		image->border_width = IMAGE_DEF_BORDER;	}	image->border_vert_space = IMAGE_DEF_VERTICAL_SPACE;	image->border_horiz_space = IMAGE_DEF_HORIZONTAL_SPACE;#endif	if ((image->text_attr != NULL)&&		(image->text_attr->attrmask & LO_ATTR_ANCHOR))	{		image->image_attr->attrmask |= LO_ATTR_ANCHOR;	}	if (tag->type == P_INPUT)	{		is_a_form = TRUE;	}	else	{		is_a_form = FALSE;	}	if (is_a_form != FALSE)	{		LO_TextAttr tmp_attr;                image->image_attr->layer_id = lo_CurrentLayerId(state);		image->image_attr->form_id = doc_lists->current_form_num;		image->image_attr->attrmask |= LO_ATTR_ISFORM;		image->border_width = IMAGE_DEF_ANCHOR_BORDER;		lo_CopyTextAttr(image->text_attr, &tmp_attr);		tmp_attr.fg.red =   STATE_UNVISITED_ANCHOR_RED(state);		tmp_attr.fg.green = STATE_UNVISITED_ANCHOR_GREEN(state);		tmp_attr.fg.blue =  STATE_UNVISITED_ANCHOR_BLUE(state);		image->text_attr = lo_FetchTextAttr(state, &tmp_attr);	}	image->image_attr->usemap_name = NULL;	image->image_attr->usemap_ptr = NULL;	image->ele_attrmask = 0;	image->sel_start = -1;	image->sel_end = -1;	/*	 * Check for the ISMAP parameter	 */	buff = lo_FetchParamValue(context, tag, PARAM_ISMAP);	if (buff != NULL)	{		image->image_attr->attrmask |= LO_ATTR_ISMAP;		PA_FREE(buff);	}	/*	 * Check for the USEMAP parameter.  The name is stored in the	 * image attributes immediately, the map pointer will be	 * stored in later.	 */	buff = lo_FetchParamValue(context, tag, PARAM_USEMAP);	if (buff != NULL)	{		char *new_str;		char *map_name;		char *tptr;		map_name = NULL;		PA_LOCK(str, char *, buff);		/*		 * Make this an absolute URL		 */		if (str != NULL)		{			int32 len;			len = lo_StripTextWhitespace(str, XP_STRLEN(str));		}		/*		 * The IETF draft says evaluate #name relative to real,		 * and not the base url.		 */		if ((str != NULL)&&(*str == '#'))		{			new_str = NET_MakeAbsoluteURL(				state->top_state->url, str);		}		else		{			new_str = NET_MakeAbsoluteURL(				state->top_state->base_url, str);		}		/*		 * If we have a local URL, we can use the USEMAP.		 */		if ((new_str != NULL)&&			(lo_IsAnchorInDoc(state, new_str) != FALSE))		{			tptr = strrchr(new_str, '#');			if (tptr == NULL)			{				tptr = new_str;			}			else			{				tptr++;			}			map_name = XP_STRDUP(tptr);			XP_FREE(new_str);		}		/*		 * Else a non-local URL, right now we don't support this.		 */		else if (new_str != NULL)		{			XP_FREE(new_str);		}		PA_UNLOCK(buff);		PA_FREE(buff);		image->image_attr->usemap_name = map_name;		if (image->image_attr->usemap_name != NULL)		{			LO_TextAttr tmp_attr;			image->border_width = IMAGE_DEF_ANCHOR_BORDER;			lo_CopyTextAttr(image->text_attr, &tmp_attr);			tmp_attr.fg.red =   STATE_UNVISITED_ANCHOR_RED(state);			tmp_attr.fg.green = STATE_UNVISITED_ANCHOR_GREEN(state);			tmp_attr.fg.blue =  STATE_UNVISITED_ANCHOR_BLUE(state);			image->text_attr = lo_FetchTextAttr(state, &tmp_attr);		}	}	/*	 * Check for an align parameter	 */	buff = lo_FetchParamValue(context, tag, PARAM_ALIGN);	if (buff != NULL)	{		Bool floating;		floating = FALSE;		PA_LOCK(str, char *, buff);		image->image_attr->alignment = lo_EvalAlignParam(str,			&floating);		if (floating != FALSE)		{			image->ele_attrmask |= LO_ELE_FLOATING;		}		PA_UNLOCK(buff);		PA_FREE(buff);	}		if(state->top_state->style_stack)	{		Bool floating = FALSE;		lo_EvalStyleSheetAlignment(				STYLESTACK_GetStyleByIndex(state->top_state->style_stack, 0), 				&(image->image_attr->alignment),				&floating);	 				if (floating != FALSE)		{			image->ele_attrmask |= LO_ELE_FLOATING;		}	}	/*	 * Get the required src parameter, and make the resulting	 * url and absolute url.	 */	buff = lo_FetchParamValue(context, tag, PARAM_SRC);	if (buff != NULL)	{		PA_Block new_buff;		char *new_str;		PA_LOCK(str, char *, buff);		if (str != NULL)		{			int32 len;			len = lo_StripTextWhitespace(str, XP_STRLEN(str));		}		new_str = NET_MakeAbsoluteURL(state->top_state->base_url, str);		if (new_str == NULL)		{			new_buff = NULL;		}		else		{			char *url;			new_buff = PA_ALLOC(XP_STRLEN(new_str) + 1);			if (new_buff != NULL)			{				PA_LOCK(url, char *, new_buff);				XP_STRCPY(url, new_str);				PA_UNLOCK(new_buff);			}			else			{				state->top_state->out_of_memory = TRUE;			}			/* Complete kludge: if this image has the magic SRC,			 * then also parse an HREF from it (the IMG tag doesn't			 * normally have an HREF parameter.)			 *			 * The front ends know that when the user clicks on an			 * image with the magic SRC, that they may find the			 * "real" URL in the HREF... Gag me.			 */			if (!XP_STRCMP(new_str, "internal-external-reconnect"))			{				PA_Block hbuf;				hbuf = lo_FetchParamValue(context, tag, PARAM_HREF);				if (hbuf != NULL)				{					image->anchor_href =					    lo_NewAnchor(state, hbuf, NULL);				}			}			XP_FREE(new_str);		}		PA_UNLOCK(buff);		PA_FREE(buff);		buff = new_buff;	}	image->image_url = buff;	/*	 * Get the optional lowsrc parameter, and make the resulting	 * url and absolute url.	 */	buff = lo_FetchParamValue(context, tag, PARAM_LOWSRC);	if (buff != NULL)	{	    PA_Block new_buff;	    char *new_str;	    PA_LOCK(str, char *, buff);	    if (str != NULL)	    {		int32 len;		len = lo_StripTextWhitespace(str, XP_STRLEN(str));	    }	    new_str = NET_MakeAbsoluteURL(state->top_state->base_url, str);	    if (new_str == NULL)	    {		    new_buff = NULL;	    }	    else	    {		    char *url;		    new_buff = PA_ALLOC(XP_STRLEN(new_str) + 1);		    if (new_buff != NULL)		    {			    PA_LOCK(url, char *, new_buff);			    XP_STRCPY(url, new_str);			    PA_UNLOCK(new_buff);		    }		    else		    {			    state->top_state->out_of_memory = TRUE;		    }		    XP_FREE(new_str);	    }	    PA_UNLOCK(buff);	    PA_FREE(buff);	    buff = new_buff;	}	image->lowres_image_url = buff;	/*	 * Get the alt parameter, and store the resulting	 * text, and its length.  Form the special image form	 * element, store the name in alt.	 */	if (is_a_form != FALSE)	{		buff = lo_FetchParamValue(context, tag, PARAM_NAME);	}	else	{		buff = lo_FetchParamValue(context, tag, PARAM_ALT);	}	if (buff != NULL)	{		PA_LOCK(str, char *, buff);		image->alt_len = XP_STRLEN(str);		image->alt_len = (int16)lo_StripTextNewlines(str,						(int32)image->alt_len);		PA_UNLOCK(buff);	}	image->alt = buff;	/*	doc_width = state->right_margin - state->left_margin;	*/	/*	 * Get the width parameter, in absolute or percentage.	 * If percentage, make it absolute.	 */	/*	buff = lo_FetchParamValue(context, tag, PARAM_WIDTH);	if (buff != NULL)	{		Bool is_percent;		PA_LOCK(str, char *, buff);		val = lo_ValueOrPercent(str, &is_percent);		if (is_percent != FALSE)		{			if (state->allow_percent_width == FALSE)			{				val = 0;			}			else			{				val = doc_width * val / 100;			}		}		else		{			val = FEUNITS_X(val, context);		}		image->width = val;		PA_UNLOCK(buff);		PA_FREE(buff);	}	*/	buff = lo_FetchParamValue(context, tag, PARAM_WIDTH);	if (buff != NULL)	{		Bool is_percent;		PA_LOCK(str, char *, buff);		val = lo_ValueOrPercent(str, &is_percent);		if (is_percent != FALSE)		{			image->percent_width = val;		}		else		{			image->percent_width = 0;			val = FEUNITS_X(val, context);					}			if (val < 0)			val = 0;			image->width = val;		PA_UNLOCK(buff);		PA_FREE(buff);	}	/* disabled because it is broken by JS threading 	 *	 * val = LO_GetWidthFromStyleSheet(context, state);	 * if(val)	 *	image->width = val;	 */	/*	 * Get the height parameter, in absolute or percentage.	 * If percentage, make it absolute.	 */	/*	buff = lo_FetchParamValue(context, tag, PARAM_HEIGHT);	if (buff != NULL)	{		Bool is_percent;		PA_LOCK(str, char *, buff);		val = lo_ValueOrPercent(str, &is_percent);		if (is_percent != FALSE)		{			if (state->allow_percent_height == FALSE)			{				val = 0;			}			else			{				val = state->win_height * val / 100;			}		}		else		{			val = FEUNITS_Y(val, context);		}		image->height = val;		PA_UNLOCK(buff);		PA_FREE(buff);	}	*/	buff = lo_FetchParamValue(context, tag, PARAM_HEIGHT);	if (buff != NULL)	{		Bool is_percent;		PA_LOCK(str, char *, buff);		val = lo_ValueOrPercent(str, &is_percent);		if (is_percent != FALSE)		{			image->percent_height = val;		}		else		{			image->percent_height = 0;			val = FEUNITS_Y(val, context);		}		if (val < 0)			val = 0;		image->height = val;		PA_UNLOCK(buff);		PA_FREE(buff);	}	/* disabled because it is broken by JS threading 	 *	 * val = LO_GetHeightFromStyleSheet(context, state);	 * if(val)	 *	image->height = val;	 */	/*	 * Get the border parameter.	 */	buff = lo_FetchParamValue(context, tag, PARAM_BORDER);	if (buff != NULL)	{		PA_LOCK(str, char *, buff);		val = XP_ATOI(str);		if (val < 0)		{			val = 0;		}		image->border_width = val;		PA_UNLOCK(buff);		PA_FREE(buff);	}	image->border_width = FEUNITS_X(image->border_width, context);	/*	 * Get the extra vertical space parameter.	 */	buff = lo_FetchParamValue(context, tag, PARAM_VSPACE);	if (buff != NULL)	{		PA_LOCK(str, char *, buff);		val = XP_ATOI(str);		if (val < 0)		{			val = 0;		}		image->border_vert_space = val;		PA_UNLOCK(buff);		PA_FREE(buff);	}	image->border_vert_space = FEUNITS_Y(image->border_vert_space, context);	/*	 * Get the extra horizontal space parameter.	 */	if (image->ele_attrmask & LO_ELE_FLOATING)	{		image->border_horiz_space = IMAGE_DEF_FLOAT_HORIZONTAL_SPACE;	}	else	{		image->border_horiz_space = IMAGE_DEF_HORIZONTAL_SPACE;	}	buff = lo_FetchParamValue(context, tag, PARAM_HSPACE);	if (buff != NULL)	{		PA_LOCK(str, char *, buff);		val = XP_ATOI(str);		if (val < 0)		{			val = 0;		}		image->border_horiz_space = val;		PA_UNLOCK(buff);		PA_FREE(buff);	}	image->border_horiz_space = FEUNITS_X(image->border_horiz_space,						context);	lo_FillInImageGeometry( state, image );	/*	 * Make sure we don't load insecure images inside	 * a secure document.	 */	if (state->top_state->security_level > 0)	{		if (image->image_url != NULL)		{			PA_LOCK(str, char *, image->image_url);			if (NET_IsURLSecure(str) == FALSE)			{				PA_UNLOCK(image->image_url);				PA_FREE(image->image_url);				image->image_url = PA_ALLOC(				    XP_STRLEN("internal-icon-insecure") + 1);				if (image->image_url != NULL)				{				    PA_LOCK(str, char *, image->image_url);				    XP_STRCPY(str, "internal-icon-insecure");				    PA_UNLOCK(image->image_url);				}				else				{				    state->top_state->out_of_memory = TRUE;				}				if (state->top_state->insecure_images == FALSE)				{					state->top_state->insecure_images = TRUE;					SECNAV_SecurityDialog(context, SD_INSECURE_DOCS_WITHIN_SECURE_DOCS_NOT_SHOWN);				}			}			else			{				PA_UNLOCK(image->image_url);			}		}	}    layer_id = lo_CurrentLayerId(state);    image->layer_id = layer_id;        /* Reflect the image into Javascript */    lo_ReflectImage(context, state, tag, image, FALSE, layer_id);    if (context->compositor) {        image->layer = lo_CreateImageLayer(context, image, NULL);    }	/* Initiate the loading of this image. */    image_obs_list = lo_NewImageObserverList(context, image);    if (!image_obs_list)        return;    /* If a lowres image has been specified, we'll actually be loading       that, not the real (hires) url */	lo_GetImage(context, context->img_cx, image, image_obs_list,                    state->top_state->force_reload);    /* During relayout the editor is not allowed to block. */    if ( (image->width == 0)||(image->height == 0))    {        if ( EDT_IN_RELAYOUT( context ) ){            lo_edt_AvoidImageBlock(image);        }    }    /*	 * We may have to block on this image until later	 * when the front end can give us the width and height.	 */	if (((image->width == 0)||(image->height == 0))        && (EDT_IS_EDITOR(context)))	{        /* If a lowres image has been specified, we'll actually be           blocking on that, not the real (hires) url */        TIMING_STARTCLOCK_NAME("lo:blk-img", image->image_url);		state->top_state->layout_blocking_element = (LO_Element *)image;	}	else	{		lo_FinishImage(context, state, image);        if ((image->width == 0) || (image->height == 0))            context->requires_reflow = PR_TRUE;	}}