From 53fe498010a1b73b0b2d7e0e232e51f243e38933 Mon Sep 17 00:00:00 2001 From: "shaver%netscape.com" Date: Fri, 2 Oct 1998 20:20:31 +0000 Subject: [PATCH] DOM: move POP_LAYER handling into back end and start element->node wiring --- lib/layout/layout.c | 105 ------------------------------- lib/layout/layout.h | 7 +++ lib/layout/laytable.c | 19 ++---- lib/layout/laytags.c | 139 ++++++++++++++++++++++++++++++++++++++++-- lib/layout/layutil.c | 11 +++- 5 files changed, 154 insertions(+), 127 deletions(-) diff --git a/lib/layout/layout.c b/lib/layout/layout.c index 83fdbe9cb2d0..921993408787 100644 --- a/lib/layout/layout.c +++ b/lib/layout/layout.c @@ -4074,74 +4074,6 @@ static void *hooked_data_object = NULL; static intn hooked_status = 0; static PA_Tag *hooked_tag = NULL; -#ifdef DOM -char *element_names[] = { - "NONE", - "TEXT", - "LINEFEED", - "HRULE", - "IMAGE", - "BULLET", - "FORM_ELE", - "SUBDOC", - "TABLE", - "CELL", - "EMBED", - "EDGE", - "JAVA", - "SCRIPT", - "OBJECT", - "PARAGRAPH", - "CENTER", - "MULTICOL", - "FLOAT", - "TEXTBLOCK", - "LIST", - "DESCTITLE", - "DESCTEXT", - "BLOCKQUOTE", - "LAYER", - "HEADING", - "SPAN", - "BUILTIN", - "SPACER", - "SUPER", - "SUB" -}; - -#ifdef DEBUG_shaver_verbose -static void -DumpNodeElements(DOM_Node *node) -{ -#ifdef DEBUG_shaver - LO_Element *eptr; - if (node->type != NODE_TYPE_ELEMENT && - node->type != NODE_TYPE_TEXT) - return; - fprintf(stderr, "%s %s elements:", - PA_TagString(ELEMENT_PRIV(node)->tagtype), - node->name ? node->name : ""); - if (ELEMENT_PRIV(node)->tagtype == P_TABLE_ROW || - ELEMENT_PRIV(node)->tagtype == P_TABLE_DATA) { - fprintf(stderr, " \n"); - return; - } - eptr = ELEMENT_PRIV(node)->ele_start; - if (!eptr) { - fprintf(stderr, " (SHOULD REMOVE FROM TREE!)\n"); - return; - } - while (eptr && eptr != ELEMENT_PRIV(node)->ele_end) { - fprintf(stderr, " %s", element_names[eptr->type]); - eptr = eptr->lo_any.next; - } - if (eptr) - fprintf(stderr, " %s", element_names[eptr->type]); - fprintf(stderr, "\n"); -#endif -} -#endif -#endif /************************************* * Function: LO_ProcessTag @@ -4902,43 +4834,6 @@ XP_TRACE(("Initializing new doc %d\n", doc_id)); lo_LayoutTag(context, state, tag); -#ifdef DOM - /* - * If we're ending a tag, then we're also ending a node. - * In this case, LM_RefectTagNode will have returned the closing - * node, so we can fill it in. - * Otherwise, if it's a text tag, LM_ReflectTagNode will - * return the Text block and we want to mark it as done. (Text nodes - * will probably only ever have one LO_Element, but why take - * chances?) - */ - if (last_node && - ((tag->is_end && last_node->type == NODE_TYPE_ELEMENT) || - last_node->type == NODE_TYPE_TEXT)) { - /* mark the end LO_Element for the _last_ node */ - LO_Element *eptr; - if (ELEMENT_PRIV(last_node)->flags & STYLE_NODE_NEED_TO_POP_LAYER) - lo_EndLayer(context, state, PR_TRUE); - eptr = state->line_list; - if (eptr) { - while (eptr->lo_any.next != NULL) { - eptr = eptr->lo_any.next; - } - } else { - eptr = state->end_last_line; - } -#if 0 - /* there are Nodes (TITLE,HEAD) that don't generate LO_Elements */ - XP_ASSERT(eptr); - XP_ASSERT(ELEMENT_PRIV(last_node)->ele_start); -#endif - ELEMENT_PRIV(last_node)->ele_end = eptr; -#ifdef DEBUG_shaver_old - DumpNodeElements(last_node); -#endif - } -#endif - if (top_state->wedged_on_mocha) { top_state->wedged_on_mocha = FALSE; return(1); diff --git a/lib/layout/layout.h b/lib/layout/layout.h index 659e48a9f08e..65ee2e25d884 100644 --- a/lib/layout/layout.h +++ b/lib/layout/layout.h @@ -34,6 +34,9 @@ #include "stystack.h" #include "libmocha.h" +#ifdef DOM +struct DOM_Node; +#endif #define MEMORY_ARENAS 1 @@ -272,6 +275,10 @@ typedef struct lo_TableCell_struct { typedef struct lo_TableRow_struct { + int16 type; /* to match lo_Any */ +#ifdef DOM + struct DOM_Node *node; /* to match lo_Any */ +#endif Bool row_done; Bool has_percent_width_cells; lo_Backdrop backdrop; /* default for cells to inherit */ diff --git a/lib/layout/laytable.c b/lib/layout/laytable.c index 8be7b6a364b8..f8a8dea41b4c 100644 --- a/lib/layout/laytable.c +++ b/lib/layout/laytable.c @@ -3697,14 +3697,6 @@ lo_BeginTableCellAttributes(MWContext *context, return; } -#if DOM - /* - * Unsafe cast, but code that operates on the Nodes will - * know that elements need special care. - */ - lo_SetNodeElement(state, (LO_Element *)table_cell); -#endif - if (state->is_a_subdoc != SUBDOC_NOT) { table_cell->in_nested_table = TRUE; @@ -4409,7 +4401,7 @@ lo_BeginTableRowAttributes(MWContext *context, lo_table_span *span_rec; char *bgcolor_from_style=NULL; #ifdef LOCAL_DEBUG - fprintf(stderr, "lo_BeginTableRow called\n"); + fprintf(stderr, "lo_BeginTableRow called\n"); #endif /* LOCAL_DEBUG */ table_row = XP_NEW(lo_TableRow); @@ -4417,12 +4409,11 @@ lo_BeginTableRowAttributes(MWContext *context, { return; } + #if DOM - /* - * So this is a little unsafe, on the surface. - * The code that does the reordering of LO_Elements will have to - * think important, special-case thoughts about nodes, - * but that's OK. + /* + * need to make lo_TableRow have a DOM_Node at the same place as all + * the LO_Elements. */ lo_SetNodeElement(state, (LO_Element *)table_row); #endif diff --git a/lib/layout/laytags.c b/lib/layout/laytags.c index 928089427633..536287ac10e6 100644 --- a/lib/layout/laytags.c +++ b/lib/layout/laytags.c @@ -38,6 +38,7 @@ #include "stystruc.h" #ifdef DOM #include "domstyle.h" +#include "lm_dom.h" #endif #include "pics.h" @@ -629,11 +630,11 @@ lo_ProcessHeader(MWContext *context, lo_DocState *state, { if (header->is_end) { - Bool aligned_header; + Bool aligned_header = FALSE; if (state->align_stack && state->align_stack->type == P_HEADER_1) - aligned_header = TRUE; + aligned_header = TRUE; if (aligned_header != FALSE) { @@ -4324,6 +4325,75 @@ static void lo_ProcessFontTag( lo_DocState *state, MWContext *context, PA_Tag *t } } +#ifdef DOM +char *element_names[] = { + "NONE", + "TEXT", + "LINEFEED", + "HRULE", + "IMAGE", + "BULLET", + "FORM_ELE", + "SUBDOC", + "TABLE", + "CELL", + "EMBED", + "EDGE", + "JAVA", + "SCRIPT", + "OBJECT", + "PARAGRAPH", + "CENTER", + "MULTICOL", + "FLOAT", + "TEXTBLOCK", + "LIST", + "DESCTITLE", + "DESCTEXT", + "BLOCKQUOTE", + "LAYER", + "HEADING", + "SPAN", + "BUILTIN", + "SPACER", + "SUPER", + "SUB" +}; + +#ifdef DEBUG_shaver_verbose +static void +DumpNodeElements(DOM_Node *node) +{ +#ifdef DEBUG_shaver + LO_Element *eptr; + if (node->type != NODE_TYPE_ELEMENT && + node->type != NODE_TYPE_TEXT) + return; + fprintf(stderr, "%s %s elements:", + PA_TagString(ELEMENT_PRIV(node)->tagtype), + node->name ? node->name : ""); + if (ELEMENT_PRIV(node)->tagtype == P_TABLE_ROW || + ELEMENT_PRIV(node)->tagtype == P_TABLE_DATA) { + fprintf(stderr, " \n"); + return; + } + eptr = ELEMENT_PRIV(node)->ele_start; + if (!eptr) { + fprintf(stderr, " (SHOULD REMOVE FROM TREE!)\n"); + return; + } + while (eptr && eptr != ELEMENT_PRIV(node)->ele_end) { + fprintf(stderr, " %s", element_names[eptr->type]); + eptr = eptr->lo_any.next; + } + if (eptr) + fprintf(stderr, " %s", element_names[eptr->type]); + fprintf(stderr, "\n"); +#endif +} +#endif +#endif + /************************************* * Function: lo_LayoutTag * @@ -6537,8 +6607,8 @@ XP_TRACE(("lo_LayoutTag(%d)\n", tag->type)); */ case P_FORM: #if defined(SingleSignon) - /* Notify the signon module of the new form */ - SI_StartOfForm(); + /* Notify the signon module of the new form */ + SI_StartOfForm(); #endif /* * No forms in the scrolling document @@ -6903,7 +6973,7 @@ XP_TRACE(("lo_LayoutTag(%d)\n", tag->type)); lo_ProcessScriptTag(context, state, tag, NULL); break; - case P_STYLE: + case P_STYLE: if(!state->hide_content) lo_ProcessStyleTag(context, state, tag); break; @@ -7561,6 +7631,65 @@ XP_TRACE(("lo_LayoutTag(%d)\n", tag->type)); */ lo_PostLayoutTag( context, state, tag, started_in_head); +#ifdef DOM + /* + * Ending the processing of a tag. + * Here we pop all the style state we need to, and wire up the + * Node->LO_Element end-element links. + */ + if (tag->is_end) { + LO_Element *eptr; + DOM_Node *node; + + /* find the last element on the line list and its node */ +#define FIND_LAST_ELEMENT(eptr) \ + eptr = state->line_list; \ + if (eptr) { \ + while (eptr->lo_any.next != NULL) { \ + eptr = eptr->lo_any.next; \ + } \ + } else { \ + eptr = state->end_last_line; \ + } + FIND_LAST_ELEMENT(eptr); + if (!eptr) + return; + node = eptr->lo_any.node; + if (!node) + return; + + if (node->type == NODE_TYPE_ELEMENT || + node->type == NODE_TYPE_TEXT) { + PRBool resyncElements = PR_FALSE; + DOM_HTMLElementPrivate *priv = ELEMENT_PRIV(node); + XP_ASSERT(priv); + + if (priv->flags & STYLE_NODE_NEED_TO_POP_LAYER) { + resyncElements = PR_TRUE; + lo_EndLayer(context, state, PR_TRUE); + LM_ClearNodeFlags(node, STYLE_NODE_NEED_TO_POP_LAYER); + } + + /* if we popped stuff, resync the end pointer */ + if (resyncElements) { + FIND_LAST_ELEMENT(eptr); + XP_ASSERT(eptr->lo_any.node == node); + } + + priv->ele_end = eptr; + } else { +#ifdef DEBUG_shaver + fprintf(stderr, "node on LO_Element %d is type %d\n", + eptr->lo_any.type, node->type); +#endif + } + +#ifdef DEBUG_shaver_old + DumpNodeElements(last_node); +#endif + } +#endif /* DOM */ + LO_UnlockLayout(); } diff --git a/lib/layout/layutil.c b/lib/layout/layutil.c index e6e259dfc1f2..ca716550ac4a 100644 --- a/lib/layout/layutil.c +++ b/lib/layout/layutil.c @@ -2125,6 +2125,9 @@ lo_NewElement(MWContext *context, lo_DocState *state, intn type, } else { +#ifdef DOM + eptr->lo_any.node = NULL; +#endif eptr->lo_any.width = 0; eptr->lo_any.height = 0; eptr->lo_any.x_offset = 0; @@ -2605,10 +2608,12 @@ lo_SetNodeElement(lo_DocState *state, LO_Element *element) /* this the first element for this node, so mark it */ ELEMENT_PRIV(node)->ele_start = element; } -#if 0 /* XXX waiting on proper LO_Elements for tables and cells and stuff */ - if (!element->lo_any.node) - element->lo_any.node = node; +#ifdef DEBUG_shaver + if (element->lo_any.node) + fprintf(stderr, "element %p (type %d) already has node %x\n", + element, element->lo_any.type, element->lo_any.node); #endif + element->lo_any.node = node; } #endif