/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ #ifndef _Layout_h_ #define _Layout_h_ #define M12N /* XXXM12N include m12n changes, exclude old stuff. */ #include "xp_core.h" #include "net.h" #include "cl_types.h" #include "xp_obs.h" /* Observer/observables. */ #include "il_types.h" /* stylesheets stuff */ #include "stystruc.h" #include "stystack.h" #include "libmocha.h" #ifdef DOM struct DOM_Node; #endif #define MEMORY_ARENAS 1 #define NEXT_ELEMENT state->top_state->element_id++ #define MAX_INPUT_WRITE_LEVEL 10 #define LINE_BUF_INC 200 #define FONT_HASH_SIZE 127 #define DEFAULT_BASE_FONT_SIZE 3 #define PRE_TEXT_NO 0 /* not preformatted */ #define PRE_TEXT_YES 1 /* preformatted, no wrapping */ #define PRE_TEXT_WRAP 2 /* preformatted, but wrapped */ #define PRE_TEXT_COLS 3 /* preformatted, but set to wrap at a specific column */ #define QUOTE_NONE 0 /* no quote marker */ #define QUOTE_MQUOTE 1 /* use blue bars to mark the quoted area. */ #define QUOTE_JWZ 2 /* use '>'s to mark the quoted area. */ #define QUOTE_CITE 3 /* use extra leading space to indicate the quoted area */ #define SUBDOC_NOT 0 /* not really a subdoc. */ #define SUBDOC_IS 1 /* normal subdoc -- not used. */ #define SUBDOC_CELL 2 /* table cell */ #define SUBDOC_CAPTION 3 /* table caption */ #define LO_ALIGN_DEFAULT -1 #define LO_ALIGN_CENTER 0 #define LO_ALIGN_LEFT 1 #define LO_ALIGN_RIGHT 2 #define LO_ALIGN_TOP 3 #define LO_ALIGN_BOTTOM 4 #define LO_ALIGN_BASELINE 5 #define LO_ALIGN_NCSA_CENTER 6 #define LO_ALIGN_NCSA_BOTTOM 7 #define LO_ALIGN_NCSA_TOP 8 #define LO_ALIGN_JUSTIFY 9 #define ICON_X_OFFSET 4 #define ICON_Y_OFFSET 4 /* Moved from laytags.c so Composer can use them */ #define MIN_FONT_SIZE 1 #define MAX_FONT_SIZE 7 #define DEFAULT_BASE_POINT_SIZE 12 #define MIN_POINT_SIZE 1 #define MAX_POINT_SIZE 1600 #ifdef EDITOR extern char* lo_alignStrings[]; #endif #define S_FORM_TYPE_TEXT "text" #define S_FORM_TYPE_RADIO "radio" #define S_FORM_TYPE_CHECKBOX "checkbox" #define S_FORM_TYPE_HIDDEN "hidden" #define S_FORM_TYPE_SUBMIT "submit" #define S_FORM_TYPE_RESET "reset" #define S_FORM_TYPE_PASSWORD "password" #define S_FORM_TYPE_BUTTON "button" #define S_FORM_TYPE_IMAGE "image" #define S_FORM_TYPE_FILE "file" #define S_FORM_TYPE_JOT "jot" #define S_FORM_TYPE_READONLY "readonly" #define S_FORM_TYPE_OBJECT "object" #define S_AREA_SHAPE_DEFAULT "default" #define S_AREA_SHAPE_RECT "rect" #define S_AREA_SHAPE_CIRCLE "circle" #define S_AREA_SHAPE_POLY "poly" #define S_AREA_SHAPE_POLYGON "polygon" /* maps to AREA_SHAPE_POLY */ #define AREA_SHAPE_UNKNOWN 0 #define AREA_SHAPE_DEFAULT 1 #define AREA_SHAPE_RECT 2 #define AREA_SHAPE_CIRCLE 3 #define AREA_SHAPE_POLY 4 #define BODY_ATTR_BACKGROUND 0x01 #define BODY_ATTR_BGCOLOR 0x02 #define BODY_ATTR_TEXT 0x04 #define BODY_ATTR_LINK 0x08 #define BODY_ATTR_VLINK 0x10 #define BODY_ATTR_ALINK 0x20 #define BODY_ATTR_MARGINS 0x40 #define BODY_ATTR_JAVA 0x80 #define DEF_TAB_WIDTH 8 extern LO_Color lo_master_colors[]; typedef struct lo_NameList_struct { int32 x, y; LO_Element *element; PA_Block name; /* really a (char *) */ struct lo_NameList_struct *next; uint32 index; /* Needed because with nested tables, the list is not guaranteed to be ordered. */ struct JSObject *mocha_object; } lo_NameList; typedef struct lo_SavedFormListData_struct { XP_Bool valid; int32 data_index; int32 data_count; PA_Block data_list; /* really a (LO_FormElementData **) */ struct lo_SavedFormListData_struct *next; } lo_SavedFormListData; typedef void (*lo_FreeProc)(MWContext*, void*); typedef struct lo_EmbedDataElement { void *data; lo_FreeProc freeProc; } lo_EmbedDataElement; typedef struct lo_SavedEmbedListData_struct { int32 embed_count; PA_Block embed_data_list; /* really a (lo_EmbedDataElement **) */ } lo_SavedEmbedListData; typedef struct lo_SavedGridData_struct { int32 main_width; int32 main_height; struct lo_GridRec_struct *the_grid; } lo_SavedGridData; typedef struct lo_MarginStack_struct { int32 margin; int32 y_min, y_max; struct lo_MarginStack_struct *next; } lo_MarginStack; typedef struct lo_FontStack_struct { int32 tag_type; LO_TextAttr *text_attr; struct lo_FontStack_struct *next; } lo_FontStack; typedef struct lo_AlignStack_struct { intn type; int32 alignment; struct lo_AlignStack_struct *next; } lo_AlignStack; typedef struct lo_ListStack_struct { intn level; int type; int32 value; Bool compact; int bullet_type; int8 quote_type; int32 mquote_line_num; /* First line to put the mquote bullets on. */ int32 mquote_x; /* How far to indent the mquote. */ int32 old_left_margin; int32 old_right_margin; struct lo_ListStack_struct *next; } lo_ListStack; typedef struct lo_LayerDocState lo_LayerDocState; typedef struct lo_LayerStack lo_LayerStack; typedef struct lo_ObjectStack_struct { LO_ObjectStruct *object; struct lo_ObjectStack_struct *next; lo_NVList parameters; char* data_url; MWContext* context; struct lo_DocState_struct* state; PA_Tag* real_tag; PA_Tag* clone_tag; Bool read_params; Bool formatted_object; } lo_ObjectStack; typedef struct lo_LineHeightStack_struct { int32 height; struct lo_LineHeightStack_struct *next; } lo_LineHeightStack; typedef struct lo_FormData_struct { intn id; PA_Block action; PA_Block encoding; PA_Block window_target; int32 method; int32 form_ele_cnt; int32 form_ele_size; PA_Block form_elements; /* really a (LO_Element **) */ struct lo_FormData_struct *next; PA_Block name; struct JSObject *mocha_object; } lo_FormData; typedef struct lo_TableCell_struct { Bool start_in_form; intn form_id; int32 form_ele_cnt; int32 form_data_index; int32 embed_count_base; int32 url_count_base; int32 image_list_count_base; int32 applet_list_count_base; int32 embed_list_count_base; int32 current_layer_num_base; Bool must_relayout; intn is_a_subdoc; PA_Tag *subdoc_tags; PA_Tag *subdoc_tags_end; int32 max_y; int32 horiz_alignment; int32 vert_alignment; int32 cell_base_x; int32 cell_base_y; Bool cell_done; Bool nowrap; Bool is_a_header; int32 specified_width, specified_height; int32 percent_width, percent_height; int32 min_width, max_width; int32 height, baseline; int32 rowspan, colspan; LO_CellStruct *cell; struct lo_TableCell_struct *next; int32 beginning_tag_count; Bool in_nested_table; /* Can be removed once we remove subdoc tags. * Used to figure out whether we shoul free subdoc tags or not */ } lo_TableCell; 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 */ int32 cells; /* is a counter that gets updated as a new cell is seen for a row */ int32 cells_in_row; /* is the exact number of LO_CELLS in the line list for each row. Calculated in lo_fill_cell_array */ int32 vert_alignment; int32 horiz_alignment; lo_TableCell *cell_list; lo_TableCell *cell_ptr; struct lo_TableRow_struct *next; } lo_TableRow; typedef struct lo_TableCaption_struct { int32 vert_alignment; int32 horiz_alignment; int32 min_width, max_width; int32 height; int32 rowspan, colspan; LO_SubDocStruct *subdoc; LO_CellStruct *cell_ele; /* Kept around for relayout without reload */ } lo_TableCaption; typedef struct lo_table_span_struct { int32 dim, min_dim; int32 span; struct lo_table_span_struct *next; } lo_table_span; typedef struct lo_TableRec_struct { intn draw_borders; Bool has_percent_width_cells; Bool table_width_fixed; Bool has_percent_height_cells; int32 percent_width; int32 percent_height; lo_Backdrop backdrop; /* default for cells to inherit */ int32 rows, cols; int32 width, height; int32 inner_top_pad; int32 inner_bottom_pad; int32 inner_left_pad; int32 inner_right_pad; int32 inter_cell_pad; int32 default_cell_width; int32 fixed_cols; int32 fixed_width_remaining; lo_table_span *width_spans; lo_table_span *width_span_ptr; lo_table_span *height_spans; lo_table_span *height_span_ptr; lo_TableCaption *caption; LO_TableStruct *table_ele; LO_SubDocStruct *current_subdoc; lo_TableRow *row_list; lo_TableRow *row_ptr; int32 *fixed_col_widths; } lo_TableRec; /* * This structure contains all the element lists associated with a * document that are reflected into mocha. There's one per top-level * document (in the top_state), and one per layer. * XXX BUGBUG The things that are missing from this list include: * - The savedData stuff * - A document's map_list * Why? I don't feel comfortable moving these guys around at this point. */ typedef struct lo_DocLists_struct { LO_EmbedStruct *embed_list; /* embeds linked in reverse order */ int32 embed_list_count; /* The number of embeds in the list */ LO_BuiltinStruct *builtin_list; /* builtin/tree linked in reverse order */ int32 builtin_list_count; LO_JavaAppStruct *applet_list; /* applets linked in reverse order */ int32 applet_list_count; /* The number of applets in the list */ LO_ImageStruct *image_list; /* list of images in doc */ LO_ImageStruct *last_image; /* last image in image_list */ uint32 image_list_count; /* Number of images in the list */ lo_NameList *name_list; /* list of positions of named anchors */ uint32 anchor_count; /* Count of named anchors in this document */ lo_FormData *form_list; /* list of forms in doc */ intn current_form_num; /* The id of the next form to lay out */ #ifdef XP_WIN16 intn ulist_array_size; XP_Block ulist_array; /* really a (XP_Block *) */ #endif /* XP_WIN16 */ XP_Block url_list; /* really a (LO_AnchorData **) PA_Block */ intn url_list_len; /* Number of URLs in the list */ intn url_list_size; /* Size of the list buffer */ } lo_DocLists; typedef struct lo_MultiCol_struct { LO_Element *end_last_line; int32 start_ele; int32 start_line, end_line; int32 start_y, end_y; int32 start_x; int32 cols; int32 col_width; int32 orig_margin; int32 orig_min_width; int32 orig_display_blocking_element_y; int32 gutter; Bool orig_display_blocked; Bool close_table; int32 width; /* For relayout without reload */ Bool isPercentWidth; /* For relayout without reload */ struct lo_MultiCol_struct *next; } lo_MultiCol; #define LO_PERCENT_NORMAL 0 #define LO_PERCENT_FREE 1 #define LO_PERCENT_FIXED 2 typedef struct lo_GridPercent_struct { uint8 type; int32 value; int32 original_value; } lo_GridPercent; typedef struct lo_GridHistory_struct { void *hist; /* really a SHIST history pointer */ int32 position; } lo_GridHistory; typedef struct lo_GridCellRec_struct { int32 x, y; int32 width, height; int32 margin_width, margin_height; intn width_percent; intn height_percent; char *url; char *name; MWContext *context; void *hist_list; /* really a (XP_List *) */ lo_GridHistory *hist_array; int32 hist_indx; int8 scrolling; Bool resizable; Bool no_edges; int16 edge_size; int8 color_priority; LO_Color *border_color; struct lo_GridEdge_struct *side_edges[4]; /* top, bottom, left, right */ struct lo_GridCellRec_struct *next; struct lo_GridRec_struct *subgrid; Bool needs_restructuring; Bool has_percent_width, has_percent_height; } lo_GridCellRec; typedef struct lo_GridEdge_struct { int32 x, y; int32 width, height; Bool is_vertical; int32 left_top_bound; int32 right_bottom_bound; int32 cell_cnt; int32 cell_max; lo_GridCellRec **cell_array; LO_EdgeStruct *fe_edge; struct lo_GridEdge_struct *next; Bool dealt_with_in_relayout; } lo_GridEdge; typedef struct lo_GridRec_struct { int32 main_width, main_height; int32 current_hist, max_hist, hist_size; int32 grid_cell_border; int32 grid_cell_min_dim; int32 rows, cols; int32 current_cell_margin_width; int32 current_cell_margin_height; lo_GridPercent *row_percents; lo_GridPercent *col_percents; lo_GridCellRec *cell_list; lo_GridCellRec *cell_list_last; int32 cell_count; Bool no_edges; int16 edge_size; int8 color_priority; LO_Color *border_color; lo_GridEdge *edge_list; struct lo_GridRec_struct *subgrid; } lo_GridRec; extern lo_GridCellRec * lo_ContextToCell(MWContext *context, Bool reconnect, lo_GridRec **grid_ptr); typedef struct lo_MapRec_struct { char *name; struct lo_MapAreaRec_struct *areas; struct lo_MapAreaRec_struct *areas_last; struct lo_MapRec_struct *next; } lo_MapRec; typedef struct lo_MapAreaRec_struct { int16 type; int16 alt_len; PA_Block alt; int32 *coords; int32 coord_cnt; LO_AnchorData *anchor; struct lo_MapAreaRec_struct *next; } lo_MapAreaRec; #ifdef HTML_CERTIFICATE_SUPPORT typedef struct lo_Certificate_struct { PA_Block name; /* really a (char *) */ void *cert; /* really a (char *) */ struct lo_Certificate_struct *next; } lo_Certificate; #endif /* HTML_CERTIFICATE_SUPPORT */ typedef struct lo_TopState_struct lo_TopState; #ifdef TEST_16BIT #define XP_WIN16 #endif /* TEST_16BIT */ typedef struct lo_DocState_struct { lo_TopState *top_state; PA_Tag *subdoc_tags; /* tags that created this subdoc */ PA_Tag *subdoc_tags_end; /* End of subdoc tags list */ int32 base_x, base_y; /* upper left of document */ int32 x, y; /* upper left of element in progress */ int32 width; /* width of element in progress */ int32 win_width; /* Document or subdoc dimensions */ int32 win_height; int32 max_height; /* farthest down item so far. */ int32 max_width; /* width of widest line so far. */ int32 min_width; /* minimum possible line width */ int32 break_holder; /* holder for last break position width */ int32 line_num; /* line number of the next line to be placed */ int32 preformat_cols; /* Column to break special PRE_TEXT_COLS at */ intn linefeed_state; int8 preformatted; /* processing preformatted (maybe wrap) text */ Bool allow_amp_escapes; /* Let & entites be expanded */ Bool breakable; /* Working on a breakable element */ Bool delay_align; /* in subdoc, delay aligning lines */ Bool display_blocked; /* do not display during layout */ Bool in_paragraph; /* inside an HTML 3.0 paragraph container */ int32 display_blocking_element_id; int32 display_blocking_element_y; int32 win_top; int32 win_bottom; int32 win_left; int32 win_right; int32 left_margin; int32 right_margin; lo_MarginStack *left_margin_stack; lo_MarginStack *right_margin_stack; int32 text_divert; /* the tag type of a text diverter (like P_TITLE) */ #ifdef XP_WIN16 intn larray_array_size; XP_Block larray_array; /* really a (XP_Block *) */ #endif /* XP_WIN16 */ intn line_array_size; XP_Block line_array; /* really a (LO_Element **) */ LO_Element *line_list; /* Element list for the current line so far */ LO_Element *end_last_line; /* Element at end of last line */ LO_Element *float_list; /* Floating element list for the current doc */ intn base_font_size; /* size of font at bottom of font stack */ lo_FontStack *font_stack; lo_AlignStack *align_stack; lo_ListStack *list_stack; lo_LineHeightStack *line_height_stack; LO_TextInfo text_info; /* for text of last text element created */ /* this is a buffer for a single (currently processed) line of text */ PA_Block line_buf; /* lock to a (char *) */ int32 line_buf_len; int32 line_buf_size; int32 baseline; int32 line_height; int32 default_line_height; int32 break_pos; /* position in middle of current element */ int32 break_width; Bool last_char_CR; Bool trailing_space; Bool at_begin_line; Bool hide_content; /* set to not display text */ LO_TextStruct *old_break; LO_TextBlock *old_break_block; int32 old_break_pos; /* in middle of older element on this line */ int32 old_break_width; PA_Block current_named_anchor; /* lock to a (char *) */ LO_AnchorData *current_anchor; intn cur_ele_type; LO_Element *current_ele; /* element in process, no end tag yet */ LO_JavaAppStruct *current_java; /* java applet in process, no end tag yet */ lo_TableRec *current_table; lo_GridRec *current_grid; lo_MultiCol *current_multicol; intn layer_nest_level; /* Layer nesting level for this (sub)doc */ Bool start_in_form; /* Was in a form at start of (sub)doc */ intn form_id; /* first form entering this (sub)doc */ int32 form_ele_cnt; /* first form element entering this (sub)doc */ int32 form_data_index; /* first form data entering this (sub)doc */ int32 embed_count_base; /* number of embedded elements (applets and embeds) before beginning this (sub)doc */ /* * Just to clarify: the embed_count is the total of all applets and * embeds in the document. This is used for indexing into the saved * data structure. The applet_list_count and embed_list_count are * applets and embeds in the current container. This is used to index * into the applet and embed lists of the container. */ int32 url_count_base; /* number of anchors before beginning this (sub)doc */ int32 image_list_count_base; /* number of images before this (sub)doc */ int32 applet_list_count_base; /* number of applets before this (sub)doc */ int32 embed_list_count_base; /* number of embeds before this (sub)doc */ int32 current_layer_num_base; /* id of last layer before this (sub)doc */ int32 current_layer_num_max; /* id of the last layer in this (sub)doc */ Bool must_relayout_subdoc; Bool allow_percent_width; Bool allow_percent_height; intn is_a_subdoc; int32 current_subdoc; XP_Block sub_documents; /* really a lo_DocState ** array */ struct lo_DocState_struct *sub_state; LO_Element *current_cell; Bool extending_start; LO_Element *selection_start; int32 selection_start_pos; LO_Element *selection_end; int32 selection_end_pos; LO_Element *selection_new; int32 selection_new_pos; CL_Layer *selection_layer; LO_Color text_fg; LO_Color text_bg; LO_Color anchor_color; LO_Color visited_anchor_color; LO_Color active_anchor_color; ED_Element *edit_current_element; int edit_current_offset; Bool edit_force_offset; Bool edit_relayout_display_blocked; Bool in_relayout; /* true if we're in lo_RelayoutSubdoc */ int32 tab_stop; int32 beginning_tag_count; /* the tag count at the beginning of this state */ LO_TextBlock * cur_text_block; Bool need_min_width; uint32 src_text_offset; } lo_DocState; #ifdef TEST_16BIT #undef XP_WIN16 #endif /* TEST_16BIT */ #define STATE_DEFAULT_FG_RED(state) ((state)->text_fg.red) #define STATE_DEFAULT_FG_GREEN(state) ((state)->text_fg.green) #define STATE_DEFAULT_FG_BLUE(state) ((state)->text_fg.blue) #define STATE_DEFAULT_BG_RED(state) ((state)->text_bg.red) #define STATE_DEFAULT_BG_GREEN(state) ((state)->text_bg.green) #define STATE_DEFAULT_BG_BLUE(state) ((state)->text_bg.blue) #define STATE_UNVISITED_ANCHOR_RED(state) ((state)->anchor_color.red) #define STATE_UNVISITED_ANCHOR_GREEN(state) ((state)->anchor_color.green) #define STATE_UNVISITED_ANCHOR_BLUE(state) ((state)->anchor_color.blue) #define STATE_VISITED_ANCHOR_RED(state) ((state)->visited_anchor_color.red) #define STATE_VISITED_ANCHOR_GREEN(state) ((state)->visited_anchor_color.green) #define STATE_VISITED_ANCHOR_BLUE(state) ((state)->visited_anchor_color.blue) #define STATE_SELECTED_ANCHOR_RED(state) ((state)->active_anchor_color.red) #define STATE_SELECTED_ANCHOR_GREEN(state) ((state)->active_anchor_color.green) #define STATE_SELECTED_ANCHOR_BLUE(state) ((state)->active_anchor_color.blue) #ifdef MEMORY_ARENAS typedef struct lo_arena_struct { struct lo_arena_struct *next; char *limit; char *avail; } lo_arena; #endif /* MEMORY_ARENAS */ /* ** This is just like SHIST_SavedData except the fields are more strictly ** typed. */ typedef struct lo_SavedData { lo_SavedFormListData* FormList; /* Data for all form elements in doc */ lo_SavedEmbedListData* EmbedList; /* session data for all embeds and applets in doc */ lo_SavedGridData* Grid; /* saved for grid history. */ PA_Block OnLoad; /* JavaScript onload event handler source */ PA_Block OnUnload; /* JavaScript onunload event handler source */ PA_Block OnFocus; /* JavaScript onfocus event handler source */ PA_Block OnBlur; /* JavaScript onblur event handler source */ PA_Block OnHelp; /* JavaScript onhelp event handler source */ PA_Block OnMouseOver; /* JavaScript onmouseover event handler source */ PA_Block OnMouseOut; /* JavaScript onmouseout event handler source */ PA_Block OnDragDrop; /* JavaScript ondragdrop event handler source */ PA_Block OnMove; /* JavaScript onmove event handler source */ PA_Block OnResize; /* JavaScript onresize event handler source */ } lo_SavedData; /* * This is used when we have an input stream and we need to defer * the destruction of the main parser stream till we're done * processing all inline streams. */ typedef void lo_FreeStreamFunc(MWContext *, NET_StreamClass *); /* * Top level state */ struct lo_TopState_struct { #ifdef MEMORY_ARENAS lo_arena *first_arena; lo_arena *current_arena; #endif /* MEMORY_ARENAS */ PA_Tag *tags; /* Held tags while layout is blocked */ PA_Tag **tags_end; /* End of held tags list */ PRPackedBool doc_specified_bg; PRPackedBool nothing_displayed; PRPackedBool in_head; /* Still in the HEAD of the HTML doc. */ PRPackedBool in_body; /* In the BODY of the HTML doc. */ PRPackedBool scrolling_doc; /* Is this a special scrolling doc (hack) */ PRPackedBool have_title; /* set by first