private ElementBox normalizeBox ( ElementBox root ) { //anonymous inline and block elements if necessary if ( root . mayContainBlocks ( ) && ( ( BlockBox ) root ) . containsBlocks ( ) ) createAnonymousBlocks ( ( BlockBox ) root ) ; else if ( root . containsMixedContent ( ) ) createAnonymousInline ( root ) ; //generate missing child wrappers // https://www.w3.org/TR/CSS22/tables.html#anonymous-boxes if ( root . getDisplay ( ) == ElementBox . DISPLAY_TABLE || root . getDisplay ( ) == ElementBox . DISPLAY_INLINE_TABLE ) createAnonymousWrappers ( root , "tr" , "table-row" , properTableChild ) ; else if ( root . getDisplay ( ) == ElementBox . DISPLAY_TABLE_ROW_GROUP ) createAnonymousWrappers ( root , "tr" , "table-row" , properTableRowGroupChild ) ; else if ( root . getDisplay ( ) == ElementBox . DISPLAY_TABLE_ROW ) createAnonymousWrappers ( root , "td" , "table-cell" , properTableRowChild ) ; //table cells require a row parent createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_CELL , ElementBox . DISPLAY_TABLE_ROW , ElementBox . DISPLAY_ANY , ElementBox . DISPLAY_ANY , "tr" , "table-row" ) ; //table rows require a group parent createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_ROW , ElementBox . DISPLAY_TABLE_ROW_GROUP , ElementBox . DISPLAY_TABLE_HEADER_GROUP , ElementBox . DISPLAY_TABLE_FOOTER_GROUP , "tbody" , "table-row-group" ) ; //table columns require a table parent createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_COLUMN , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_TABLE_COLUMN_GROUP , "table" , "table" ) ; //table row groups require a table parent createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_ROW_GROUP , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_HEADER_GROUP , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_FOOTER_GROUP , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_CAPTION , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; return root ; }
Checks the newly created box and creates anonymous block boxes above the children if necessary .