dtd.cpp Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# dtd.cpp

    00001
    00024 #include "html/dtd.h"
    00025 #include "misc/htmlhashes.h"
    00026
    00027 using namespace DOM;
    00028
    00029 #include <kdebug.h>
    00030
    00031 // priority of tags. Closing tags of higher priority close tags of lower
    00032 // priority.
    00033 // Update this list, whenever you change htmltags.*
    00034 //
    00035 // 0 elements with forbidden close tag and text. They don't get pushed
    00036 //   to the stack.
    00037 // 1 inline elements
    00038 // 2 form elements
    00039 // 3 regular block level elements
    00040 // 4 lists (OL UL DIR MENU)
    00041 // 5 TD TH SELECT
    00042 // 6 TR
    00043 // 7 tbody thead tfoot caption  object
    00044 // 8 table
    00045 // 9 body frameset
    00046 // 10 html
    00047 const unsigned short DOM::tagPriority[] = {
    00048     0, // 0
    00049     5, // ID_A == 1
    00050     1, // ID_ABBR
    00051     1, // ID_ACRONYM
    00052     3, // ID_ADDRESS
    00053     1, // ID_APPLET
    00054     0, // ID_AREA
    00055     1, // ID_B
    00056     0, // ID_BASE
    00057     0, // ID_BASEFONT
    00058     1, // ID_BDO
    00059     1, // ID_BIG
    00060     5, // ID_BLOCKQUOTE
    00061    10, // ID_BODY
    00062     0, // ID_BR
    00063     1, // ID_BUTTON
    00064     5, // ID_CAPTION
    00065     5, // ID_CENTER
    00066     1, // ID_CITE
    00067     1, // ID_CODE
    00068     0, // ID_COL
    00069     1, // ID_COLGROUP
    00070     3, // ID_DD
    00071     1, // ID_DEL
    00072     1, // ID_DFN
    00073     5, // ID_DIR
    00074     4, // ID_DIV
    00075     4, // ID_DL
    00076     3, // ID_DT
    00077     1, // ID_EM
    00078     0, // ID_EMBED
    00079     3, // ID_FIELDSET
    00080     5, // ID_FONT
    00081     3, // ID_FORM
    00082     0, // ID_FRAME
    00083    10,// ID_FRAMESET
    00084     5, // ID_H1
    00085     5, // ID_H2
    00086     5, // ID_H3
    00087     5, // ID_H4
    00088     5, // ID_H5
    00089     5, // ID_H6
    00090    10,// ID_HEAD
    00091     0, // ID_HR
    00092    11,// ID_HTML
    00093     1, // ID_I
    00094     1, // ID_IFRAME
    00095     0, // ID_IMG
    00096     0, // ID_INPUT
    00097     1, // ID_INS
    00098     0, // ID_ISINDEX
    00099     1, // ID_KBD
    00100     0, // ID_KEYGEN
    00101     5, // ID__KONQBLOCK
    00102     1, // ID_LABEL
    00103     1, // ID_LAYER
    00104     1, // ID_LEGEND
    00105     3, // ID_LI
    00106     0, // ID_LINK
    00107     1, // ID_MAP
    00108     3, // ID_MARQUEE
    00109     5, // ID_MENU
    00110     0, // ID_META
    00111     1, // ID_NOBR
    00112    10,// ID_NOEMBED
    00113    10,// ID_NOFRAMES
    00114     3, // ID_NOSCRIPT
    00115     1, // ID_NOLAYER
    00116     5, // ID_OBJECT
    00117     5, // ID_OL
    00118     1, // ID_OPTGROUP
    00119     2, // ID_OPTION
    00120     3, // ID_P
    00121     0, // ID_PARAM
    00122     5, // ID_PLAINTEXT
    00123     5, // ID_PRE
    00124     1, // ID_Q
    00125     1, // ID_S
    00126     1, // ID_SAMP
    00127     1, // ID_SCRIPT
    00128     6, // ID_SELECT
    00129     1, // ID_SMALL
    00130     1, // ID_SPAN
    00131     1, // ID_STRIKE
    00132     1, // ID_STRONG
    00133     1, // ID_STYLE
    00134     1, // ID_SUB
    00135     1, // ID_SUP
    00136     9,// ID_TABLE
    00137     8, // ID_TBODY
    00138     6, // ID_TD
    00139     1, // ID_TEXTAREA
    00140     8, // ID_TFOOT
    00141     6, // ID_TH
    00142     8, // ID_THEAD
    00143     1, // ID_TITLE
    00144     7, // ID_TR
    00145     1, // ID_TT
    00146     1, // ID_U
    00147     5, // ID_UL
    00148     1, // ID_VAR
    00149     1, // ID_WBR
    00150     5, // ID_XMP
    00151     0, // ID_TEXT
    00152 };
    00153
    00154 const tagStatus DOM::endTag[] = {
    00155     REQUIRED,  // 0
    00156     REQUIRED,  // ID_A == 1
    00157     REQUIRED,  // ID_ABBR
    00158     REQUIRED,  // ID_ACRONYM
    00159     REQUIRED,  // ID_ADDRESS
    00160     REQUIRED,  // ID_APPLET
    00161     FORBIDDEN, // ID_AREA
    00162     REQUIRED,  // ID_B
    00163     FORBIDDEN, // ID_BASE
    00164     FORBIDDEN, // ID_BASEFONT
    00165     REQUIRED,  // ID_BDO
    00166     REQUIRED,  // ID_BIG
    00167     REQUIRED,  // ID_BLOCKQUOTE
    00168     REQUIRED,  // ID_BODY
    00169     FORBIDDEN, // ID_BR
    00170     REQUIRED,  // ID_BUTTON
    00171     REQUIRED,  // ID_CAPTION
    00172     REQUIRED,  // ID_CENTER
    00173     REQUIRED,  // ID_CITE
    00174     REQUIRED,  // ID_CODE
    00175     FORBIDDEN, // ID_COL
    00176     OPTIONAL,  // ID_COLGROUP
    00177     OPTIONAL,  // ID_DD
    00178     REQUIRED,  // ID_DEL
    00179     REQUIRED,  // ID_DFN
    00180     REQUIRED,  // ID_DIR
    00181     REQUIRED,  // ID_DIV
    00182     REQUIRED,  // ID_DL
    00183     OPTIONAL,  // ID_DT
    00184     REQUIRED,  // ID_EM
    00185     REQUIRED,  // ID_EMBED
    00186     REQUIRED,  // ID_FIELDSET
    00187     REQUIRED,  // ID_FONT
    00188     REQUIRED,  // ID_FORM
    00189     FORBIDDEN, // ID_FRAME
    00190     REQUIRED,  // ID_FRAMESET
    00191     REQUIRED,  // ID_H1
    00192     REQUIRED,  // ID_H2
    00193     REQUIRED,  // ID_H3
    00194     REQUIRED,  // ID_H4
    00195     REQUIRED,  // ID_H5
    00196     REQUIRED,  // ID_H6
    00197     OPTIONAL,  // ID_HEAD
    00198     FORBIDDEN, // ID_HR
    00199     REQUIRED,  // ID_HTML
    00200     REQUIRED,  // ID_I
    00201     REQUIRED,  // ID_IFRAME
    00202     FORBIDDEN, // ID_IMG
    00203     FORBIDDEN, // ID_INPUT
    00204     REQUIRED,  // ID_INS
    00205     FORBIDDEN, // ID_ISINDEX
    00206     REQUIRED,  // ID_KBD
    00207     REQUIRED,  // ID_KEYGEN
    00208     REQUIRED,  // ID__KONQBLOCK
    00209     REQUIRED,  // ID_LABEL
    00210     REQUIRED,  // ID_LAYER
    00211     REQUIRED,  // ID_LEGEND
    00212     OPTIONAL,  // ID_LI
    00213     FORBIDDEN, // ID_LINK
    00214     REQUIRED,  // ID_MAP
    00215     REQUIRED,  // ID_MARQUEE
    00216     REQUIRED,  // ID_MENU
    00217     FORBIDDEN, // ID_META
    00218     REQUIRED,  // ID_NOBR
    00219     REQUIRED,  // ID_NOEMBED
    00220     REQUIRED,  // ID_NOFRAMES
    00221     REQUIRED,  // ID_NOSCRIPT
    00222     REQUIRED,  // ID_NOLAYER
    00223     REQUIRED,  // ID_OBJECT
    00224     REQUIRED,  // ID_OL
    00225     REQUIRED,  // ID_OPTGROUP
    00226     OPTIONAL,  // ID_OPTION
    00227     OPTIONAL,  // ID_P
    00228     FORBIDDEN, // ID_PARAM
    00229     REQUIRED,  // ID_PLAINTEXT
    00230     REQUIRED,  // ID_PRE
    00231     REQUIRED,  // ID_Q
    00232     REQUIRED,  // ID_S
    00233     REQUIRED,  // ID_SAMP
    00234     REQUIRED,  // ID_SCRIPT
    00235     REQUIRED,  // ID_SELECT
    00236     REQUIRED,  // ID_SMALL
    00237     REQUIRED,  // ID_SPAN
    00238     REQUIRED,  // ID_STRIKE
    00239     REQUIRED,  // ID_STRONG
    00240     REQUIRED,  // ID_STYLE
    00241     REQUIRED,  // ID_SUB
    00242     REQUIRED,  // ID_SUP
    00243     REQUIRED,  // ID_TABLE
    00244     OPTIONAL,  // ID_TBODY
    00245     OPTIONAL,  // ID_TD
    00246     REQUIRED,  // ID_TEXTAREA
    00247     OPTIONAL,  // ID_TFOOT
    00248     OPTIONAL,  // ID_TH
    00249     OPTIONAL,  // ID_THEAD
    00250     REQUIRED,  // ID_TITLE
    00251     OPTIONAL,  // ID_TR
    00252     REQUIRED,  // ID_TT
    00253     REQUIRED,  // ID_U
    00254     REQUIRED,  // ID_UL
    00255     REQUIRED,  // ID_VAR
    00256     REQUIRED,  // ID_WBR
    00257     REQUIRED,  // ID_XMP
    00258     REQUIRED   // ID_TEXT
    00259 };
    00260
    00261
    00262 static const ushort tag_list_0[] = {
    00263     ID_TEXT,
    00264     ID_TT,
    00265     ID_I,
    00266     ID_B,
    00267     ID_U,
    00268     ID_S,
    00269     ID_STRIKE,
    00270     ID_BIG,
    00271     ID_SMALL,
    00272     ID_EM,
    00273     ID_STRONG,
    00274     ID_DFN,
    00275     ID_CODE,
    00276     ID_SAMP,
    00277     ID_KBD,
    00278     ID_VAR,
    00279     ID_CITE,
    00280     ID_ABBR,
    00281     ID_ACRONYM,
    00282     ID_A,
    00283     ID_IMG,
    00284     ID_APPLET,
    00285     ID_OBJECT,
    00286     ID_EMBED,
    00287     ID_FONT,
    00288     ID_BASEFONT,
    00289     ID_BR,
    00290     ID_SCRIPT,
    00291     ID_MAP,
    00292     ID_Q,
    00293     ID_SUB,
    00294     ID_SUP,
    00295     ID_SPAN,
    00296     ID_BDO,
    00297     ID_IFRAME,
    00298     ID_INPUT,
    00299     ID_SELECT,
    00300     ID_TEXTAREA,
    00301     ID_LABEL,
    00302     ID_BUTTON,
    00303     ID_INS,
    00304     ID_DEL,
    00305     ID_COMMENT,
    00306     ID_NOBR,
    00307     ID_WBR,
    00308     0
    00309 };
    00310
    00311 static const ushort tag_list_1[] = {
    00312     ID_P,
    00313     ID_H1,
    00314     ID_H2,
    00315     ID_H3,
    00316     ID_H4,
    00317     ID_H5,
    00318     ID_H6,
    00319     ID_UL,
    00320     ID_OL,
    00321     ID_DIR,
    00322     ID_MENU,
    00323     ID_PRE,
    00324     ID_PLAINTEXT,
    00325     ID_DL,
    00326     ID_DIV,
    00327     ID_LAYER,
    00328     ID_CENTER,
    00329     ID_NOSCRIPT,
    00330     ID_NOFRAMES,
    00331     ID_BLOCKQUOTE,
    00332     ID_FORM,
    00333     ID_ISINDEX,
    00334     ID_HR,
    00335     ID_TABLE,
    00336     ID_FIELDSET,
    00337     ID_ADDRESS,
    00338     ID_TEXT,
    00339     ID_TT,
    00340     ID_I,
    00341     ID_B,
    00342     ID_U,
    00343     ID_S,
    00344     ID_STRIKE,
    00345     ID_BIG,
    00346     ID_SMALL,
    00347     ID_EM,
    00348     ID_STRONG,
    00349     ID_DFN,
    00350     ID_CODE,
    00351     ID_SAMP,
    00352     ID_KBD,
    00353     ID_VAR,
    00354     ID_CITE,
    00355     ID_ABBR,
    00356     ID_ACRONYM,
    00357     ID_A,
    00358     ID_IMG,
    00359     ID_APPLET,
    00360     ID_OBJECT,
    00361     ID_EMBED,
    00362     ID_FONT,
    00363     ID_BASEFONT,
    00364     ID_BR,
    00365     ID_SCRIPT,
    00366     ID_MAP,
    00367     ID_Q,
    00368     ID_SUB,
    00369     ID_SUP,
    00370     ID_SPAN,
    00371     ID_BDO,
    00372     ID_IFRAME,
    00373     ID_INPUT,
    00374     ID_KEYGEN,
    00375     ID_SELECT,
    00376     ID_TEXTAREA,
    00377     ID_LABEL,
    00378     ID_BUTTON,
    00379     ID_COMMENT,
    00380     ID_LI,
    00381     ID_XMP,
    00382     ID__KONQBLOCK,
    00383     ID_INS,
    00384     ID_DEL,
    00385     ID_NOBR,
    00386     ID_WBR,
    00387     ID_MARQUEE,
    00388     0
    00389 };
    00390
    00391 static const ushort tag_list_2[] = {
    00392     ID_COMMENT,
    00393     0
    00394 };
    00395
    00396 static const ushort tag_list_3[] = {
    00397     ID_P,
    00398     ID_H1,
    00399     ID_H2,
    00400     ID_H3,
    00401     ID_H4,
    00402     ID_H5,
    00403     ID_H6,
    00404     ID_UL,
    00405     ID_OL,
    00406     ID_DIR,
    00407     ID_MENU,
    00408     ID_PRE,
    00409     ID_PLAINTEXT,
    00410     ID_DL,
    00411     ID_DIV,
    00412     ID_LAYER,
    00413     ID_CENTER,
    00414     ID_NOSCRIPT,
    00415     ID_NOFRAMES,
    00416     ID_BLOCKQUOTE,
    00417     ID_FORM,
    00418     ID_ISINDEX,
    00419     ID_HR,
    00420     ID_TABLE,
    00421     ID_FIELDSET,
    00422     ID_ADDRESS,
    00423     ID_COMMENT,
    00424     ID_LI,
    00425     ID_XMP,
    00426     ID__KONQBLOCK,
    00427     ID_MARQUEE,
    00428     0
    00429 };
    00430
    00431 static const ushort tag_list_4[] = {
    00432     ID_PARAM,
    00433     ID_P,
    00434     ID_H1,
    00435     ID_H2,
    00436     ID_H3,
    00437     ID_H4,
    00438     ID_H5,
    00439     ID_H6,
    00440     ID_UL,
    00441     ID_OL,
    00442     ID_DIR,
    00443     ID_MENU,
    00444     ID_PRE,
    00445     ID_PLAINTEXT,
    00446     ID_DL,
    00447     ID_DIV,
    00448     ID_LAYER,
    00449     ID_CENTER,
    00450     ID_NOSCRIPT,
    00451     ID_NOFRAMES,
    00452     ID_BLOCKQUOTE,
    00453     ID_FORM,
    00454     ID_ISINDEX,
    00455     ID_HR,
    00456     ID_TABLE,
    00457     ID_FIELDSET,
    00458     ID_ADDRESS,
    00459     ID_TEXT,
    00460     ID_TT,
    00461     ID_I,
    00462     ID_B,
    00463     ID_U,
    00464     ID_S,
    00465     ID_STRIKE,
    00466     ID_BIG,
    00467     ID_SMALL,
    00468     ID_EM,
    00469     ID_STRONG,
    00470     ID_DFN,
    00471     ID_CODE,
    00472     ID_SAMP,
    00473     ID_KBD,
    00474     ID_VAR,
    00475     ID_CITE,
    00476     ID_ABBR,
    00477     ID_ACRONYM,
    00478     ID_A,
    00479     ID_IMG,
    00480     ID_APPLET,
    00481     ID_OBJECT,
    00482     ID_EMBED,
    00483     ID_FONT,
    00484     ID_BASEFONT,
    00485     ID_BR,
    00486     ID_SCRIPT,
    00487     ID_MAP,
    00488     ID_Q,
    00489     ID_SUB,
    00490     ID_SUP,
    00491     ID_SPAN,
    00492     ID_BDO,
    00493     ID_IFRAME,
    00494     ID_INPUT,
    00495     ID_SELECT,
    00496     ID_TEXTAREA,
    00497     ID_LABEL,
    00498     ID_BUTTON,
    00499     ID_COMMENT,
    00500     ID_LI,
    00501     ID_XMP,
    00502     ID_MARQUEE,
    00503     0
    00504 };
    00505
    00506 static const ushort tag_list_6[] = {
    00507     ID_DT,
    00508     ID_DD,
    00509     ID_COMMENT,
    00510     0
    00511 };
    00512
    00513 static const ushort tag_list_7[] = {
    00514     ID_OPTGROUP,
    00515     ID_OPTION,
    00516     ID_COMMENT,
    00517     ID_SCRIPT,
    00518     0
    00519 };
    00520
    00521 static const ushort tag_list_10[] = {
    00522     ID_FRAMESET,
    00523     ID_FRAME,
    00524     ID_NOFRAMES,
    00525     ID_COMMENT,
    00526     0
    00527 };
    00528
    00529 static const ushort tag_list_11[] = {
    00530     ID_SCRIPT,
    00531     ID_STYLE,
    00532     ID_META,
    00533     ID_LINK,
    00534     ID_TITLE,
    00535     ID_ISINDEX,
    00536     ID_BASE,
    00537     ID_COMMENT,
    00538     0
    00539 };
    00540
    00541 static bool check_array(ushort child, const ushort *tagList)
    00542 {
    00543     int i = 0;
    00544     while(tagList[i] != 0)
    00545     {
    00546         if(tagList[i] == child) return true;
    00547     i++;
    00548     }
    00549     return false;
    00550 }
    00551
    00552
    00553 bool DOM::checkChild(ushort tagID, ushort childID)
    00554 {
    00555     //kdDebug( 6030 ) << "checkChild: " << tagID << "/" << childID << endl;
    00556
    00557     // ### allow comments inside ANY node that can contain children
    00558
    00559     if (tagID >= 1000 || childID >= 1000)
    00560         return true; // one or both of the elements in an XML element; just allow for now
    00561
    00562     switch(tagID)
    00563     {
    00564     case ID_TT:
    00565     case ID_I:
    00566     case ID_B:
    00567     case ID_U:
    00568     case ID_S:
    00569     case ID_STRIKE:
    00570     case ID_BIG:
    00571     case ID_SMALL:
    00572     case ID_EM:
    00573     case ID_STRONG:
    00574     case ID_DFN:
    00575     case ID_CODE:
    00576     case ID_SAMP:
    00577     case ID_KBD:
    00578     case ID_VAR:
    00579     case ID_CITE:
    00580     case ID_ABBR:
    00581     case ID_ACRONYM:
    00582     case ID_SUB:
    00583     case ID_SUP:
    00584     case ID_BDO:
    00585     case ID_P:
    00586     case ID_H1:
    00587     case ID_H2:
    00588     case ID_H3:
    00589     case ID_H4:
    00590     case ID_H5:
    00591     case ID_H6:
    00592     case ID_Q:
    00593     case ID_LEGEND:
    00594         // _0 *
    00595         return check_array(childID, tag_list_0);
    00596     case ID_BASEFONT:
    00597     case ID_BR:
    00598     case ID_AREA:
    00599     case ID_LINK:
    00600     case ID_IMG:
    00601     case ID_PARAM:
    00602     case ID_HR:
    00603     case ID_INPUT:
    00604     case ID_COL:
    00605     case ID_FRAME:
    00606     case ID_ISINDEX:
    00607     case ID_BASE:
    00608     case ID_META:
    00609     case ID_COMMENT:
    00610         // BASEFONT: EMPTY
    00611         return false;
    00612     case ID_BODY:
    00613         // BODY: _1 * + _2
    00614         if( check_array(childID, tag_list_1) ) return true;
    00615         return check_array(childID, tag_list_2);
    00616     case ID_NOBR:
    00617     case ID_WBR:
    00618     case ID_ADDRESS:
    00619         // ADDRESS: ( _0 | P ) *
    00620         if( check_array(childID, tag_list_0) ) return true;
    00621         return (childID == ID_P);
    00622     case ID_FONT:
    00623         // special handling for FONT: (_0 | 3)
    00624         return check_array(childID, tag_list_3) || check_array(childID, tag_list_0);
    00625     case ID__KONQBLOCK:
    00626         if ( childID == ID__KONQBLOCK || childID == ID_TABLE ) return false;
    00627         // Fall through!
    00628     case ID_LI:
    00629     case ID_DT:
    00630     case ID_DIV:
    00631     case ID_SPAN:
    00632     case ID_LAYER:
    00633     case ID_CENTER:
    00634     case ID_BLOCKQUOTE:
    00635     case ID_INS:
    00636     case ID_DEL:
    00637     case ID_DD:
    00638     case ID_TH:
    00639     case ID_TD:
    00640     case ID_IFRAME:
    00641     case ID_NOFRAMES:
    00642     case ID_NOSCRIPT:
    00643     case ID_CAPTION:
    00644     case ID_MARQUEE:
    00645         // DIV: _1 *
    00646         return check_array(childID, tag_list_1);
    00647     case ID_A:
    00648         // A: _0 * - A
    00649         if( check_array(childID, tag_list_0) ) return true;
    00650         if ( childID == ID_TABLE ) return false; // no table in anchor
    00651         if( check_array(childID, tag_list_3) ) return true;
    00652         if( childID == ID_ADDRESS ) return true;
    00653         return false;
    00654     case ID_MAP:
    00655         // MAP: ( _3 + | AREA + )
    00656         if( check_array(childID, tag_list_3) ) return true;
    00657         return (childID == ID_AREA);
    00658     case ID_OBJECT:
    00659     case ID_EMBED:
    00660     case ID_APPLET:
    00661         // OBJECT: _4 *
    00662         return check_array(childID, tag_list_4);
    00663     case ID_PRE:
    00664     case ID_XMP:
    00665     case ID_PLAINTEXT:
    00666         // PRE: _0 * - _5
    00667         return check_array(childID, tag_list_1);
    00668     case ID_DL:
    00669         // DL: _6 +
    00670         return check_array(childID, tag_list_6);
    00671     case ID_OL:
    00672     case ID_UL:
    00673         // OL: LI +
    00674         if(childID == ID_LI) return true;
    00675         return check_array(childID, tag_list_1);
    00676     case ID_DIR:
    00677     case ID_MENU:
    00678         // (DIR|MENU): LI + - _3
    00679         if(childID == ID_LI) return true;
    00680         return false;
    00681     case ID_FORM:
    00682         // FORM: _1 * - FORM
    00683         return check_array(childID, tag_list_1);
    00684     case ID_LABEL:
    00685         // LABEL: _0 * - LABEL
    00686         return check_array(childID, tag_list_0);
    00687         // KEYGEN does not really allow any childs
    00688         // from outside, just need this to be able
    00689         // to add the keylengths ourself
    00690         // Yes, consider it a hack (Dirk)
    00691     case ID_KEYGEN:
    00692     case ID_SELECT:
    00693         // SELECT: _7 +
    00694         return check_array(childID, tag_list_7);
    00695     case ID_OPTGROUP:
    00696         // OPTGROUP: OPTION +
    00697         if(childID == ID_OPTION) return true;
    00698         return false;
    00699     case ID_OPTION:
    00700     case ID_TEXTAREA:
    00701     case ID_TITLE:
    00702     case ID_STYLE:
    00703     case ID_SCRIPT:
    00704         // OPTION: TEXT
    00705         if(childID == ID_TEXT) return true;
    00706         return false;
    00707     case ID_FIELDSET:
    00708         // FIELDSET: ( TEXT , LEGEND , _1 * )
    00709         if(childID == ID_TEXT) return true;
    00710         if(childID == ID_LEGEND) return true;
    00711         return check_array(childID, tag_list_1);
    00712     case ID_BUTTON:
    00713         // BUTTON: _1 * - _8
    00714         return check_array(childID, tag_list_1);
    00715     case ID_TABLE:
    00716         // TABLE: ( CAPTION ? , ( COL * | COLGROUP * ) , THEAD ? , TFOOT ? , TBODY + )
    00717         switch(childID)
    00718         {
    00719         case ID_CAPTION:
    00720         case ID_COL:
    00721         case ID_COLGROUP:
    00722         case ID_THEAD:
    00723         case ID_TFOOT:
    00724         case ID_TBODY:
    00725             return true;
    00726         default:
    00727             return false;
    00728         }
    00729     case ID_THEAD:
    00730     case ID_TFOOT:
    00731     case ID_TBODY:
    00732         // THEAD: TR +
    00733         if(childID == ID_TR) return true;
    00734         return false;
    00735     case ID_COLGROUP:
    00736         // COLGROUP: COL *
    00737         if(childID == ID_COL) return true;
    00738         return false;
    00739     case ID_TR:
    00740         // TR: (TD, TH)
    00741         return (childID == ID_TH || childID == ID_TD);
    00742     case ID_FRAMESET:
    00743         // FRAMESET: _10
    00744         return check_array(childID, tag_list_10);
    00745     case ID_HEAD:
    00746         // HEAD: _11
    00747         return check_array(childID, tag_list_11);
    00748     case ID_HTML:
    00749         // HTML: ( HEAD , COMMENT, ( BODY | ( FRAMESET & NOFRAMES ? ) ) )
    00750         switch(childID)
    00751         {
    00752         case ID_HEAD:
    00753         case ID_COMMENT:
    00754         case ID_BODY:
    00755         case ID_FRAMESET:
    00756         case ID_NOFRAMES:
    00757         case ID_SCRIPT:
    00758             return true;
    00759         default:
    00760             return false;
    00761         }
    00762     default:
    00763         kdDebug( 6030 ) << "unhandled tag in dtd.cpp:checkChild(): tagID=" << tagID << "!" << endl;
    00764         return false;
    00765     }
    00766 }
    00767
    00768 void DOM::addForbidden(int tagId, ushort *forbiddenTags)
    00769 {
    00770     switch(tagId)
    00771     {
    00772     case ID_A:
    00773         // we allow nested anchors. The innermost one wil be taken...
    00774         //forbiddenTags[ID_A]++;
    00775         break;
    00776     case ID_NOBR:
    00777         forbiddenTags[ID_PRE]++;
    00778         // fall through
    00779     case ID_PRE:
    00780     case ID_PLAINTEXT:
    00781     case ID_XMP:
    00782         //forbiddenTags[ID_IMG]++;
    00783         forbiddenTags[ID_OBJECT]++;
    00784         forbiddenTags[ID_EMBED]++;
    00785         forbiddenTags[ID_APPLET]++;
    00786         // why forbid them. We can deal with them in PRE
    00787         //forbiddenTags[ID_BIG]++;
    00788         //forbiddenTags[ID_SMALL]++;
    00789         //forbiddenTags[ID_SUB]++;
    00790         //forbiddenTags[ID_SUP]++;
    00791         forbiddenTags[ID_BASEFONT]++;
    00792         break;
    00793     case ID_DIR:
    00794     case ID_MENU:
    00795         forbiddenTags[ID_P]++;
    00796         forbiddenTags[ID_H1]++;
    00797         forbiddenTags[ID_H2]++;
    00798         forbiddenTags[ID_H3]++;
    00799         forbiddenTags[ID_H4]++;
    00800         forbiddenTags[ID_H5]++;
    00801         forbiddenTags[ID_H6]++;
    00802         forbiddenTags[ID_UL]++;
    00803         forbiddenTags[ID_OL]++;
    00804         forbiddenTags[ID_DIR]++;
    00805         forbiddenTags[ID_MENU]++;
    00806         forbiddenTags[ID_PRE]++;
    00807         forbiddenTags[ID_PLAINTEXT]++;
    00808         forbiddenTags[ID_XMP]++;
    00809         forbiddenTags[ID_DL]++;
    00810         forbiddenTags[ID_DIV]++;
    00811         forbiddenTags[ID_CENTER]++;
    00812         forbiddenTags[ID_NOSCRIPT]++;
    00813         forbiddenTags[ID_NOFRAMES]++;
    00814         forbiddenTags[ID_BLOCKQUOTE]++;
    00815         forbiddenTags[ID_FORM]++;
    00816         forbiddenTags[ID_ISINDEX]++;
    00817         forbiddenTags[ID_HR]++;
    00818         forbiddenTags[ID_TABLE]++;
    00819         forbiddenTags[ID_FIELDSET]++;
    00820         forbiddenTags[ID_ADDRESS]++;
    00821         break;
    00822     case ID_LABEL:
    00823         forbiddenTags[ID_LABEL]++;
    00824         break;
    00825     case ID_BUTTON:
    00826         forbiddenTags[ID_A]++;
    00827         forbiddenTags[ID_INPUT]++;
    00828         forbiddenTags[ID_SELECT]++;
    00829         forbiddenTags[ID_TEXTAREA]++;
    00830         forbiddenTags[ID_LABEL]++;
    00831         forbiddenTags[ID_BUTTON]++;
    00832         forbiddenTags[ID_FORM]++;
    00833         forbiddenTags[ID_ISINDEX]++;
    00834         forbiddenTags[ID_FIELDSET]++;
    00835         forbiddenTags[ID_IFRAME]++;
    00836         break;
    00837     default:
    00838         break;
    00839     }
    00840 }
    00841
    00842 void DOM::removeForbidden(int tagId, ushort *forbiddenTags)
    00843 {
    00844     switch(tagId)
    00845     {
    00846     case ID_A:
    00847         //forbiddenTags[ID_A]--;
    00848         break;
    00849     case ID_NOBR:
    00850         forbiddenTags[ID_PRE]--;
    00851         // fall through
    00852     case ID_PRE:
    00853     case ID_XMP:
    00854     case ID_PLAINTEXT:
    00855         //forbiddenTags[ID_IMG]--;
    00856         forbiddenTags[ID_OBJECT]--;
    00857         forbiddenTags[ID_EMBED]--;
    00858         forbiddenTags[ID_APPLET]--;
    00859         //forbiddenTags[ID_BIG]--;
    00860         //forbiddenTags[ID_SMALL]--;
    00861         //forbiddenTags[ID_SUB]--;
    00862         //forbiddenTags[ID_SUP]--;
    00863         forbiddenTags[ID_BASEFONT]--;
    00864         break;
    00865     case ID_DIR:
    00866     case ID_MENU:
    00867         forbiddenTags[ID_P]--;
    00868         forbiddenTags[ID_H1]--;
    00869         forbiddenTags[ID_H2]--;
    00870         forbiddenTags[ID_H3]--;
    00871         forbiddenTags[ID_H4]--;
    00872         forbiddenTags[ID_H5]--;
    00873         forbiddenTags[ID_H6]--;
    00874         forbiddenTags[ID_UL]--;
    00875         forbiddenTags[ID_OL]--;
    00876         forbiddenTags[ID_DIR]--;
    00877         forbiddenTags[ID_MENU]--;
    00878         forbiddenTags[ID_PRE]--;
    00879         forbiddenTags[ID_PLAINTEXT]--;
    00880         forbiddenTags[ID_XMP]--;
    00881         forbiddenTags[ID_DL]--;
    00882         forbiddenTags[ID_DIV]--;
    00883         forbiddenTags[ID_CENTER]--;
    00884         forbiddenTags[ID_NOSCRIPT]--;
    00885         forbiddenTags[ID_NOFRAMES]--;
    00886         forbiddenTags[ID_BLOCKQUOTE]--;
    00887         forbiddenTags[ID_FORM]--;
    00888         forbiddenTags[ID_ISINDEX]--;
    00889         forbiddenTags[ID_HR]--;
    00890         forbiddenTags[ID_TABLE]--;
    00891         forbiddenTags[ID_FIELDSET]--;
    00892         forbiddenTags[ID_ADDRESS]--;
    00893         break;
    00894     case ID_LABEL:
    00895         forbiddenTags[ID_LABEL]--;
    00896         break;
    00897     case ID_BUTTON:
    00898         forbiddenTags[ID_A]--;
    00899         forbiddenTags[ID_INPUT]--;
    00900         forbiddenTags[ID_SELECT]--;
    00901         forbiddenTags[ID_TEXTAREA]--;
    00902         forbiddenTags[ID_LABEL]--;
    00903         forbiddenTags[ID_BUTTON]--;
    00904         forbiddenTags[ID_FORM]--;
    00905         forbiddenTags[ID_ISINDEX]--;
    00906         forbiddenTags[ID_FIELDSET]--;
    00907         forbiddenTags[ID_IFRAME]--;
    00908         break;
    00909     default:
    00910         break;
    00911     }
    00912 }
    00913
    00914
    00915 #if 0
    00916
    00917
    00918 struct attr_priv {
    00919     attr_priv() { id = len = 0, val = 0; }
    00920     attr_priv(ushort i, const QChar *v, ushort l)
    00921     { id =i; len = l, val = v; }
    00922     ushort id;
    00923     const QChar *val;
    00924     ushort len;
    00925 };
    00926
    00927 DOMString find_attr(ushort id, const attr_priv *attrs)
    00928 {
    00929     int i = 0;
    00930     while(attrs[i].id != 0)
    00931     {
    00932         if(attrs[i].id == id)
    00933             return DOMString(attrs[i].val, attrs[i].len);
    00934         i++;
    00935     }
    00936     return DOMString();
    00937 }
    00938
    00939 static const QChar value_1_0 [] = { 'N','O','N','E' };
    00940
    00941 attr_priv attr_list_1[] = {
    00942     attr_priv(ATTR_CLEAR, value_1_0, 4)
    00943 };
    00944
    00945 static const QChar value_2_0 [] = { 'R','E','C','T' };
    00946
    00947 attr_priv attr_list_2[] = {
    00948     attr_priv(ATTR_SHAPE, value_2_0, 4)
    00949 };
    00950
    00951 static const QChar value_3_0 [] = { 'R','E','C','T' };
    00952
    00953 attr_priv attr_list_3[] = {
    00954     attr_priv(ATTR_SHAPE, value_3_0, 4)
    00955 };
    00956
    00957 static const QChar value_4_0 [] = { 'D','A','T','A' };
    00958
    00959 attr_priv attr_list_4[] = {
    00960     attr_priv(ATTR_VALUETYPE, value_4_0, 4)
    00961 };
    00962
    00963 static const QChar value_5_0 [] = { 'G','E','T' };
    00964 static const QChar value_5_1 [] = { 'A','P','P','L','I','C','A','T','I','O','N','/','X','-','W','W','W','-','F','O','R','M','-','U','R','L','E','N','C','O','D','E','D' };
    00965
    00966 attr_priv attr_list_5[] = {
    00967     attr_priv(ATTR_METHOD, value_5_0, 3),
    00968     attr_priv(ATTR_ENCTYPE, value_5_1, 33)
    00969 };
    00970
    00971 static const QChar value_6_0 [] = { 'T','E','X','T' };
    00972
    00973 attr_priv attr_list_6[] = {
    00974     attr_priv(ATTR_TYPE, value_6_0, 4)
    00975 };
    00976
    00977 static const QChar value_7_0 [] = { 'S','U','B','M','I','T' };
    00978
    00979 attr_priv attr_list_7[] = {
    00980     attr_priv(ATTR_TYPE, value_7_0, 6)
    00981 };
    00982
    00983 static const QChar value_8_0 [] = { '1' };
    00984
    00985 attr_priv attr_list_8[] = {
    00986     attr_priv(ATTR_SPAN, value_8_0, 1)
    00987 };
    00988
    00989 static const QChar value_9_0 [] = { '1' };
    00990
    00991 attr_priv attr_list_9[] = {
    00992     attr_priv(ATTR_SPAN, value_9_0, 1)
    00993 };
    00994
    00995 static const QChar value_10_0 [] = { '1' };
    00996 static const QChar value_10_1 [] = { '1' };
    00997
    00998 attr_priv attr_list_10[] = {
    00999     attr_priv(ATTR_ROWSPAN, value_10_0, 1),
    01000     attr_priv(ATTR_COLSPAN, value_10_1, 1)
    01001 };
    01002
    01003 static const QChar value_11_0 [] = { '1' };
    01004 static const QChar value_11_1 [] = { 'A','U','T','O' };
    01005
    01006 attr_priv attr_list_11[] = {
    01007     attr_priv(ATTR_FRAMEBORDER, value_11_0, 1),
    01008     attr_priv(ATTR_SCROLLING, value_11_1, 4)
    01009 };
    01010
    01011 static const QChar value_12_0 [] = { '1' };
    01012 static const QChar value_12_1 [] = { 'A','U','T','O' };
    01013
    01014 attr_priv attr_list_12[] = {
    01015     attr_priv(ATTR_FRAMEBORDER, value_12_0, 1),
    01016     attr_priv(ATTR_SCROLLING, value_12_1, 4)
    01017 };
    01018
    01019 static const QChar value_13_0 [] = { '-','/','/','W','3','C','/','/','D','T','D' };
    01020 static const QChar value_13_1 [] = { 'T','R','A','N','S','I','T','I','O','N','A','L','/','/','E','N' };
    01021
    01022 attr_priv attr_list_13[] = {
    01023     attr_priv(ATTR_VERSION, value_13_0, 11),
    01024     attr_priv(ATTR_HTML, value_13_1, 16)
    01025 };
    01026
    01027 DOMString DOM::findDefAttrNone(ushort)
    01028 {
    01029     return DOMString();
    01030 };
    01031 DOMString DOM::findDefAttrBR(ushort id)
    01032 {
    01033     return find_attr(id, attr_list_1);
    01034 }
    01035 DOMString DOM::findDefAttrA(ushort id)
    01036 {
    01037     return find_attr(id, attr_list_2);
    01038 }
    01039 DOMString DOM::findDefAttrAREA(ushort id)
    01040 {
    01041     return find_attr(id, attr_list_3);
    01042 }
    01043 DOMString DOM::findDefAttrPARAM(ushort id)
    01044 {
    01045     return find_attr(id, attr_list_4);
    01046 }
    01047 DOMString DOM::findDefAttrFORM(ushort id)
    01048 {
    01049     return find_attr(id, attr_list_5);
    01050 }
    01051 DOMString DOM::findDefAttrINPUT(ushort id)
    01052 {
    01053     return find_attr(id, attr_list_6);
    01054 }
    01055 DOMString DOM::findDefAttrBUTTON(ushort id)
    01056 {
    01057     return find_attr(id, attr_list_7);
    01058 }
    01059 DOMString DOM::findDefAttrCOLGROUP(ushort id)
    01060 {
    01061     return find_attr(id, attr_list_8);
    01062 }
    01063 DOMString DOM::findDefAttrCOL(ushort id)
    01064 {
    01065     return find_attr(id, attr_list_9);
    01066 }
    01067 DOMString DOM::findDefAttrTH(ushort id)
    01068 {
    01069     return find_attr(id, attr_list_10);
    01070 }
    01071 DOMString DOM::findDefAttrFRAME(ushort id)
    01072 {
    01073     return find_attr(id, attr_list_11);
    01074 }
    01075 DOMString DOM::findDefAttrIFRAME(ushort id)
    01076 {
    01077     return find_attr(id, attr_list_12);
    01078 }
    01079 DOMString DOM::findDefAttrHTML(ushort id)
    01080 {
    01081     return find_attr(id, attr_list_13);
    01082 }
    01083
    01084 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:49 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001