XP_List* pList = GetCallbackFuncList((int32)FRAME_DOCUMENT_COMPLETE);
XP_List* pList = LAPIGetCallbackFuncList((int32)FRAME_DOCUMENT_COMPLETE);
lo_FinishLayout(MWContext *context, lo_DocState *state, int32 mocha_event){	lo_TopState *top_state;	lo_DocState *main_state;	lo_DocState *sub_state;    /* Close any layers (blocks) that were opened in this document, in	   case the document author forgot to. */    if (state != NULL ) {        if (state->layer_nest_level) {            while (state->layer_nest_level > 0)                lo_EndLayer(context, state, PR_TRUE);            /*              * This call ensures that we flush the line list (which still might             * have something on it if we had unclosed ILAYERs).             */            lo_CloseOutLayout(context, state);         }    }	if ((state != NULL) &&		(state->top_state != NULL))	{		lo_TopState * top_state = state->top_state;		/* only finish once, please */		XP_ASSERT(!top_state->finished);		if (top_state->finished)			return;		top_state->finished = TRUE;		lo_CloseMochaWriteStream(top_state, mocha_event);		/* Could be left over if someone forgets to close a tag */		if (top_state->scriptData)			lo_DestroyScriptData(top_state->scriptData);        /* Handle the page background for the case of a document that contains            no displayed layout elements. */        if (top_state->nothing_displayed != FALSE)            lo_use_default_doc_background(context, state);	}#ifdef LAYPROBE_API	{		/* Send a notification when a frame has finished loading */		XP_List* pList = GetCallbackFuncList((int32)FRAME_DOCUMENT_COMPLETE);				if (pList)		{			while (pList = pList->next)			{				if (pList->object)					(*((ID_NOTIFY_PT)(pList->object)))((void*)context);			}		}	}#endif /* LAYPROBE_API */	ET_SendLoadEvent(context, mocha_event, NULL, NULL, 			 LO_DOCUMENT_LAYER_ID, 			 (state && state->top_state)			 ? state->top_state->resize_reload			 : FALSE);	/* Reset state for force loading images. */	LO_SetForceLoadImage(NULL, FALSE);	/*	 * Short circuit out if the state was freed out from	 * under us.	 */	if (state == NULL)	{#if !defined(SMOOTH_PROGRESS)		FE_SetProgressBarPercent(context, 100);#endif /* !defined(SMOOTH_PROGRESS) */#ifdef OLD_MSGS		FE_Progress(context, "Layout Phase Complete");#endif /* OLD_MSGS */        /* Flush out layer callbacks so that document dimensions are correct. */        if (context->compositor)            CL_CompositeNow(context->compositor);		FE_FinishedLayout(context);		return;	}	/*	 * Check for dangling sub-states, and clean them up if they exist.	 */	top_state = state->top_state;	main_state = top_state->doc_state;	sub_state = lo_TopSubState(top_state);	while ((sub_state != NULL)&&(sub_state != main_state))	{		state = main_state;		while ((state != NULL)&&(state->sub_state != sub_state))		{			state = state->sub_state;		}		if (state != NULL)		{			lo_free_layout_state_data(context, sub_state);			XP_DELETE(sub_state);			state->sub_state = NULL;		}		sub_state = lo_TopSubState(top_state);	}	state = lo_TopSubState(top_state);	/*	 * Short circuit out if the state was freed out from	 * under us.	 */	if (state == NULL)	{#if !defined(SMOOTH_PROGRESS)		FE_SetProgressBarPercent(context, 100);#endif /* !defined(SMOOTH_PROGRESS) */#ifdef OLD_MSGS		FE_Progress(context, "Layout Phase Complete");#endif /* OLD_MSGS */        /* Flush out layer callbacks so that document dimensions are correct. */        if (context->compositor)            CL_CompositeNow(context->compositor);		FE_FinishedLayout(context);		return;	}    lo_FreeLayoutData(context, state);	if (state->display_blocked != FALSE)	{		int32 y;		if (state->top_state->name_target != NULL)		{			XP_FREE(state->top_state->name_target);			state->top_state->name_target = NULL;		}		state->display_blocking_element_id = 0;		state->display_blocked = FALSE;		y = state->display_blocking_element_y;		state->display_blocking_element_y = 0;		state->y += state->win_bottom;		LO_SetDocumentDimensions(context, state->max_width, state->y);		if (y != state->win_top)		{			y = state->y - state->win_height;			if (y < 0)			{				y = 0;			}		}		FE_SetDocPosition(context, FE_VIEW, 0, y);        if (context->compositor)        {            XP_Rect rect;                        rect.left = 0;            rect.top = y;            rect.right = state->win_width;            rect.bottom = y + state->win_height;            CL_UpdateDocumentRect(context->compositor,                                  &rect, (PRBool)FALSE);        }	}	else	{		state->y += state->win_bottom;		LO_SetDocumentDimensions(context, state->max_width, state->y);	}	/* get rid of the style stack data since it wont	 * be needed any more	 */	if(top_state->style_stack)	{		/* LJM: Need to purge stack to free memory		 */		STYLESTACK_Purge(top_state->style_stack);	}#if !defined(SMOOTH_PROGRESS)	if(!state->top_state->is_binary)		FE_SetProgressBarPercent(context, 100);#endif /* !defined(SMOOTH_PROGRESS) */#ifdef OLD_MSGS	FE_Progress(context, "Layout Phase Complete");#endif /* OLD_MSGS */    /* Flush out layer callbacks so that document dimensions are correct. */    if (context->compositor)        CL_CompositeNow(context->compositor);	if (state->is_a_subdoc == SUBDOC_NOT && state->top_state && !state->top_state->have_title)	{		/* We never got a title. We better notify the FE that the title is blank */				FE_SetDocTitle(context, "");	}			FE_FinishedLayout(context);#ifdef EDITOR	if (EDT_IS_EDITOR (context))		EDT_FinishedLayout(context);#endif    /*     * Update the blink layers to reflect the current positions of their     * associated text elements.     */    if (context->compositor)        lo_UpdateBlinkLayers(context);		if (top_state && top_state->metaTags)	{				/* Tell RDF HT code that layout of the current document is complete */		HT_LayoutComplete( context, top_state->metaTags, top_state->url );		/* Free the meta tag list */		lo_FreeTagList( top_state->metaTags );		top_state->metaTags = NULL;	}    /* Prefetch links of this context */    PRE_Fetch(context);}