From 5f49f22fb7a88557946b1ec84af2076c1b30431d Mon Sep 17 00:00:00 2001 From: "shaver%netscape.com" Date: Sat, 29 Aug 1998 02:52:27 +0000 Subject: [PATCH] Move current_node and top_node to top_state, to protect them from tables. Handle table and row and cell data. (We do nested-table text now.) git-svn-id: svn://10.0.0.236/trunk@8788 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/lib/layout/layout.c | 7 ++++- mozilla/lib/layout/layout.h | 9 ++++-- mozilla/lib/layout/laytable.c | 21 +++++++++++++ mozilla/lib/layout/laytext.c | 2 +- mozilla/lib/layout/layutil.c | 56 ++++++++++++++++++++++++++++------- 5 files changed, 81 insertions(+), 14 deletions(-) diff --git a/mozilla/lib/layout/layout.c b/mozilla/lib/layout/layout.c index 92f9d6dfcf8..e44310e6297 100644 --- a/mozilla/lib/layout/layout.c +++ b/mozilla/lib/layout/layout.c @@ -4012,7 +4012,7 @@ static intn hooked_status = 0; static PA_Tag *hooked_tag = NULL; #ifdef DOM -static char *element_names[] = { +char *element_names[] = { "NONE", "TEXT", "LINEFEED", @@ -4057,6 +4057,11 @@ DumpNodeElements(DOM_Node *node) 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"); diff --git a/mozilla/lib/layout/layout.h b/mozilla/lib/layout/layout.h index 58775c56f37..71979155a8c 100644 --- a/mozilla/lib/layout/layout.h +++ b/mozilla/lib/layout/layout.h @@ -658,8 +658,6 @@ typedef struct lo_DocState_struct { #ifdef DOM Bool in_span; PA_Block current_span; - void /*DOM_Node*/ *top_node; /* top of the DOM_Node tree */ - void /*DOM_Node*/ *current_node; /* active node (only during tree gen) */ #endif } lo_DocState; @@ -852,6 +850,10 @@ struct lo_TopState_struct { #ifdef DEBUG_ScriptPlugin char * mimetype; #endif +#ifdef DOM + void /*DOM_Node*/ *top_node; /* top of the DOM_Node tree */ + void /*DOM_Node*/ *current_node; /* active node (only during tree gen) */ +#endif }; /* Script type codes, stored in top_state->in_script. */ @@ -1158,6 +1160,9 @@ extern void lo_relayout_recycle(MWContext *context, lo_DocState *state, LO_Element *elist); extern LO_Element *lo_NewElement(MWContext *, lo_DocState *, intn, ED_Element *, intn edit_offset); +#if DOM +extern void lo_SetNodeElement(lo_DocState *, LO_Element *); +#endif extern void lo_AppendToLineList(MWContext *, lo_DocState *, LO_Element *,int32); extern void lo_SetLineArrayEntry(lo_DocState *, LO_Element *, int32); extern LO_Element *lo_FirstElementOfLine(MWContext *, lo_DocState *, int32); diff --git a/mozilla/lib/layout/laytable.c b/mozilla/lib/layout/laytable.c index 1196f590ea3..9880bffd99c 100644 --- a/mozilla/lib/layout/laytable.c +++ b/mozilla/lib/layout/laytable.c @@ -3628,6 +3628,14 @@ 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; @@ -4340,6 +4348,15 @@ 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. + */ + lo_SetNodeElement(state, (LO_Element *)table_row); +#endif /* copied to lo_UpdateTableStateForBeginRow() table_row->row_done = FALSE; @@ -4657,6 +4674,10 @@ lo_BeginTableAttributes(MWContext *context, table_ele->FE_Data = NULL; table_ele->anchor_href = state->current_anchor; +#if DOM + lo_SetNodeElement(state, (LO_Element *)table_ele); +#endif + /* * Default to the current alignment */ diff --git a/mozilla/lib/layout/laytext.c b/mozilla/lib/layout/laytext.c index ddf7d5d37bd..3c215e87409 100644 --- a/mozilla/lib/layout/laytext.c +++ b/mozilla/lib/layout/laytext.c @@ -5478,7 +5478,7 @@ void lo_AppendTextToBlock ( MWContext *context, lo_DocState *state, LO_TextBlock block = lo_CurrentTextBlock ( context, state ); } } - + /* OPTIMIZATION: If the parser could tell us if we have a split * buffer then we could intelligently set parseAllText here and * not buffer words that we think may be split across a buffer but diff --git a/mozilla/lib/layout/layutil.c b/mozilla/lib/layout/layutil.c index 02bb89a09be..9082f6fe191 100644 --- a/mozilla/lib/layout/layutil.c +++ b/mozilla/lib/layout/layutil.c @@ -2561,6 +2561,51 @@ lo_CheckNameList(MWContext *context, lo_DocState *state, int32 min_id) } } +#if DOM +extern char *element_names[]; + +/* Wire the element to the DOM Node data for DOM-driven feedback. */ +void +lo_SetNodeElement(lo_DocState *state, LO_Element *element) +{ + LO_Element *eptr; + DOM_Node *node = CURRENT_NODE(state); + +#ifdef DEBUG_shaver + fprintf(stderr, "lo_SetNodeElement: state %x: ", state); + if (!node) + fprintf(stderr, "NULL node\n"); + else if (node->type == NODE_TYPE_DOCUMENT) + fprintf(stderr, "NODE_TYPE_DOCUMENT node\n"); +#endif + if (node && node->type != NODE_TYPE_DOCUMENT) { + XP_ASSERT(!ELEMENT_PRIV(node)->ele_end); + eptr = ELEMENT_PRIV(node)->ele_start; + if (!eptr) { + /* this the first element for this node, so mark it */ + ELEMENT_PRIV(node)->ele_start = element; +#ifdef DEBUG_shaver + fprintf(stderr, "giving node %s element %s\n", + ELEMENT_PRIV(node)->tagtype ? + PA_TagString(ELEMENT_PRIV(node)->tagtype) : "TEXT", + element->type > 0 && + element->type <= 31 ? element_names[element->type] + : "UNKNOWN", state); +#endif + } else { +#ifdef DEBUG_shaver + fprintf(stderr, "node %s %s already has element %s\n", + ELEMENT_PRIV(node)->tagtype ? + PA_TagString(ELEMENT_PRIV(node)->tagtype) : "TEXT", + node->name ? node->name : "NULL", + element->type > 0 && + element->type <= 31 ? element_names[element->type] + : "UNKNOWN"); +#endif + } + } +} +#endif void lo_AppendToLineList(MWContext *context, lo_DocState *state, @@ -2584,16 +2629,7 @@ lo_AppendToLineList(MWContext *context, lo_DocState *state, state->current_span = NULL; } - /* Wire the element to the DOM Node data for DOM-driven feedback. */ - - if (CURRENT_NODE(state) && - CURRENT_NODE(state)->type != NODE_TYPE_DOCUMENT) { - XP_ASSERT(!ELEMENT_PRIV(CURRENT_NODE(state))->ele_end); - eptr = ELEMENT_PRIV(CURRENT_NODE(state))->ele_start; - if (!eptr) - /* this the first element for this node, so mark it */ - ELEMENT_PRIV(CURRENT_NODE(state))->ele_start = element; - } + lo_SetNodeElement(state, element); #endif if (state->current_named_anchor != NULL) {