📄 htmlparser.cpp
字号:
break; case ID_BUTTON: n = new HTMLButtonElementImpl(document, form); break; case ID_FIELDSET: n = new HTMLFieldSetElementImpl(document, form); break; case ID_INPUT: n = new HTMLInputElementImpl(document, form); break; case ID_ISINDEX: n = handleIsindex(t); if( !inBody ) { isindex = n; n = 0; } else t->flat = true; break; case ID_KEYGEN: n = new HTMLKeygenElementImpl(document, form); break; case ID_LABEL: n = new HTMLLabelElementImpl(document); break; case ID_LEGEND: n = new HTMLLegendElementImpl(document, form); break; case ID_OPTGROUP: n = new HTMLOptGroupElementImpl(document, form); break; case ID_OPTION: n = new HTMLOptionElementImpl(document, form); break; case ID_SELECT: inSelect = true; n = new HTMLSelectElementImpl(document, form); break; case ID_TEXTAREA: n = new HTMLTextAreaElementImpl(document, form); break;// lists case ID_DL: n = new HTMLDListElementImpl(document); break; case ID_DD: n = new HTMLGenericElementImpl(document, t->id); popBlock(ID_DT); popBlock(ID_DD); break; case ID_DT: n = new HTMLGenericElementImpl(document, t->id); popBlock(ID_DD); popBlock(ID_DT); break; case ID_UL: { n = new HTMLUListElementImpl(document); break; } case ID_OL: { n = new HTMLOListElementImpl(document); break; } case ID_DIR: n = new HTMLDirectoryElementImpl(document); break; case ID_MENU: n = new HTMLMenuElementImpl(document); break; case ID_LI: { popBlock(ID_LI); n = new HTMLLIElementImpl(document); break; }// formatting elements (block) case ID_BLOCKQUOTE: n = new HTMLBlockquoteElementImpl(document); break; case ID_DIV: n = new HTMLDivElementImpl(document); break; case ID_LAYER: n = new HTMLLayerElementImpl(document); break; case ID_H1: case ID_H2: case ID_H3: case ID_H4: case ID_H5: case ID_H6: n = new HTMLHeadingElementImpl(document, t->id); break; case ID_HR: n = new HTMLHRElementImpl(document); break; case ID_P: n = new HTMLParagraphElementImpl(document); break; case ID_XMP: case ID_PRE: case ID_PLAINTEXT: n = new HTMLPreElementImpl(document, t->id); break;// font stuff case ID_BASEFONT: n = new HTMLBaseFontElementImpl(document); break; case ID_FONT: n = new HTMLFontElementImpl(document); break;// ins/del case ID_DEL: case ID_INS: n = new HTMLGenericElementImpl(document, t->id); break;// anchor case ID_A: // Never allow nested <a>s. popBlock(ID_A); n = new HTMLAnchorElementImpl(document); break;// canvas#if APPLE_CHANGES && !KWIQ case ID_CANVAS: n = new HTMLCanvasElementImpl(document); break;#endif // images case ID_IMG: n = new HTMLImageElementImpl(document); break; case ID_MAP: map = new HTMLMapElementImpl(document); n = map; break; case ID_AREA: n = new HTMLAreaElementImpl(document); break;// objects, applets and scripts case ID_APPLET: n = new HTMLAppletElementImpl(document); break; case ID_EMBED: n = new HTMLEmbedElementImpl(document); break; case ID_OBJECT: n = new HTMLObjectElementImpl(document); break; case ID_PARAM: n = new HTMLParamElementImpl(document); break; case ID_SCRIPT: n = new HTMLScriptElementImpl(document); break;// tables case ID_TABLE: n = new HTMLTableElementImpl(document); break; case ID_CAPTION: n = new HTMLTableCaptionElementImpl(document); break; case ID_COLGROUP: case ID_COL: n = new HTMLTableColElementImpl(document, t->id); break; case ID_TR: popBlock(ID_TR); n = new HTMLTableRowElementImpl(document); break; case ID_TD: case ID_TH: popBlock(ID_TH); popBlock(ID_TD); n = new HTMLTableCellElementImpl(document, t->id); break; case ID_TBODY: case ID_THEAD: case ID_TFOOT: popBlock( ID_THEAD ); popBlock( ID_TBODY ); popBlock( ID_TFOOT ); n = new HTMLTableSectionElementImpl(document, t->id, false); break;// inline elements case ID_BR: n = new HTMLBRElementImpl(document); break; case ID_Q: n = new HTMLGenericElementImpl(document, t->id); break;// elements with no special representation in the DOM// block: case ID_ADDRESS: case ID_CENTER: n = new HTMLGenericElementImpl(document, t->id); break;// inline // %fontstyle case ID_TT: case ID_U: case ID_B: case ID_I: case ID_S: case ID_STRIKE: case ID_BIG: case ID_SMALL: if (!allowNestedRedundantTag(t->id)) return 0; // Fall through and get handled with the rest of the tags // %phrase case ID_EM: case ID_STRONG: case ID_DFN: case ID_CODE: case ID_SAMP: case ID_KBD: case ID_VAR: case ID_CITE: case ID_ABBR: case ID_ACRONYM: // %special case ID_SUB: case ID_SUP: case ID_SPAN: case ID_NOBR: case ID_WBR: if (t->id == ID_NOBR || t->id == ID_WBR) popBlock(t->id); // Don't allow nested <nobr> or <wbr> n = new HTMLGenericElementImpl(document, t->id); break; case ID_BDO: break; // these are special, and normally not rendered case ID_NOEMBED: discard_until = ID_NOEMBED + ID_CLOSE_TAG; return 0; case ID_NOFRAMES: discard_until = ID_NOFRAMES + ID_CLOSE_TAG; return 0; case ID_NOSCRIPT: if(HTMLWidget && HTMLWidget->part()->jScriptEnabled()) discard_until = ID_NOSCRIPT + ID_CLOSE_TAG; return 0; case ID_NOLAYER:// discard_until = ID_NOLAYER + ID_CLOSE_TAG; return 0; break; case ID_MARQUEE: n = new HTMLMarqueeElementImpl(document); break;// text case ID_TEXT: n = new TextImpl(document, t->text); break; case ID_COMMENT:#ifdef COMMENTS_IN_DOM n = new CommentImpl(document, t->text);#endif break; default: kdDebug( 6035 ) << "Unknown tag " << t->id << "!" << endl; } return n;}#define MAX_REDUNDANT 20bool KHTMLParser::allowNestedRedundantTag(int _id){ // www.liceo.edu.mx is an example of a site that achieves a level of nesting of // about 1500 tags, all from a bunch of <b>s. We will only allow at most 20 // nested tags of the same type before just ignoring them all together. int i = 0; for (HTMLStackElem* curr = blockStack; i < MAX_REDUNDANT && curr && curr->id == _id; curr = curr->next, i++); return i != MAX_REDUNDANT;}void KHTMLParser::processCloseTag(Token *t){ // support for really broken html. Can't believe I'm supporting such crap (lars) switch(t->id) { case ID_HTML+ID_CLOSE_TAG: case ID_BODY+ID_CLOSE_TAG: // we never close the body tag, since some stupid web pages close it before the actual end of the doc. // let's rely on the end() call to close things. return; case ID_FORM+ID_CLOSE_TAG: form = 0; // this one is to get the right style on the body element break; case ID_MAP+ID_CLOSE_TAG: map = 0; break; case ID_SELECT+ID_CLOSE_TAG: inSelect = false; break; default: break; }#ifdef PARSER_DEBUG kdDebug( 6035 ) << "added the following childs to " << current->nodeName().string() << endl; NodeImpl *child = current->firstChild(); while(child != 0) { kdDebug( 6035 ) << " " << child->nodeName().string() << endl; child = child->nextSibling(); }#endif HTMLStackElem* oldElem = blockStack; popBlock(t->id-ID_CLOSE_TAG); if (oldElem == blockStack && t->id == ID_P+ID_CLOSE_TAG) { // We encountered a stray </p>. Amazingly Gecko, WinIE, and MacIE all treat // this as a valid break, i.e., <p></p>. So go ahead and make the empty // paragraph. t->id-=ID_CLOSE_TAG; parseToken(t); popBlock(ID_P); }#ifdef PARSER_DEBUG kdDebug( 6035 ) << "closeTag --> current = " << current->nodeName().string() << endl;#endif}bool KHTMLParser::isResidualStyleTag(int _id){ switch (_id) { case ID_A: case ID_FONT: case ID_TT: case ID_U: case ID_B: case ID_I: case ID_S: case ID_STRIKE: case ID_BIG: case ID_SMALL: case ID_EM: case ID_STRONG: case ID_DFN: case ID_CODE: case ID_SAMP: case ID_KBD: case ID_VAR: return true; default: return false; }}bool KHTMLParser::isAffectedByResidualStyle(int _id){ if (isResidualStyleTag(_id)) return true; switch (_id) { case ID_P: case ID_DIV: case ID_BLOCKQUOTE: case ID_ADDRESS: case ID_H1: case ID_H2: case ID_H3: case ID_H4: case ID_H5: case ID_H6: case ID_CENTER: case ID_UL: case ID_OL: case ID_LI: case ID_DL: case ID_DT: case ID_DD: case ID_PRE: return true; default: return false; }}void KHTMLParser::handleResidualStyleCloseTagAcrossBlocks(HTMLStackElem* elem){ // Find the element that crosses over to a higher level. For now, if there is more than // one, we will just give up and not attempt any sort of correction. It's highly unlikely that // there will be more than one, since <p> tags aren't allowed to be nested. int exceptionCode = 0; HTMLStackElem* curr = blockStack; HTMLStackElem* maxElem = 0; HTMLStackElem* prev = 0; HTMLStackElem* prevMaxElem = 0; while (curr && curr != elem) { if (curr->level > elem->level) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -