📄 htmlparser.cpp
字号:
break; n = new HTMLFrameSetElementImpl(document); haveFrameSet = true; inBody = true; break; // a bit a special case, since the frame is inlined... case ID_IFRAME: n = new HTMLIFrameElementImpl(document); break; // form elements case ID_FORM: // close all open forms... popBlock(ID_FORM); form = new HTMLFormElementImpl(document); n = form; 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_OPTION: n = new HTMLOptionElementImpl(document, form); break; case ID_SELECT: n = new HTMLSelectElementImpl(document, form); break; case ID_TEXTAREA: n = new HTMLTextAreaElementImpl(document, form); break; case ID_LABEL: n = new HTMLLabelElementImpl(document, form); break; case ID_LEGEND: n = new HTMLLegendElementImpl(document, form); break; case ID_OPTGROUP: n = new HTMLOptGroupElementImpl(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); HTMLElementImpl *e = new HTMLLIElementImpl(document); n = e; if( current->id() != ID_UL && current->id() != ID_OL ) e->addCSSProperty(CSS_PROP_LIST_STYLE_POSITION, DOMString("inside"), false); break; }// formatting elements (block) case ID_BLOCKQUOTE: n = new HTMLBlockquoteElementImpl(document); break; case ID_DIV: n = new HTMLDivElementImpl(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_PRE: n = new HTMLPreElementImpl(document); 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 HTMLModElementImpl(document, t->id); break;// anchor case ID_A: n = new HTMLAnchorElementImpl(document); break;// 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// TODO /* 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; */// tables case ID_SCRIPT: n = new HTMLScriptElementImpl(document); break; 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_THEAD: case ID_TBODY: case ID_TFOOT: n = new HTMLTableSectionElementImpl(document, t->id); break;// inline elements case ID_BR: n = new HTMLBRElementImpl(document); break; case ID_Q: n = new HTMLQuoteElementImpl(document); 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: // %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: 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->part()->jScriptEnabled()) discard_until = ID_NOSCRIPT + ID_CLOSE_TAG; return 0; // Waldo's plaintext stuff case ID_PLAIN: return 0; break;// text case ID_TEXT: n = new TextImpl(document, t->text); if (t->complexText ) n->setComplexText(true); break; case ID_COMMENT:#ifdef COMMENTS_IN_DOM n = new CommentImpl(document, t->text);#endif break; default: //kdDebug( 6035 ) << "Unknown tag " << t->id << "!" << endl; break; } return n;}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_HEAD+ID_CLOSE_TAG: //inBody = true; // don't close head neither. the creation of body will do it for us. // fixes some sites, that define stylesheets after </head> return; case ID_TITLE+ID_CLOSE_TAG: if ( current->id() == ID_TITLE ) static_cast<HTMLTitleElementImpl *>(current)->setTitle(); 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 popBlock(t->id-ID_CLOSE_TAG);#ifdef PARSER_DEBUG //kdDebug( 6035 ) << "closeTag --> current = " << current->nodeName().string() << endl;#endif}void KHTMLParser::pushBlock(int _id, int _level){ HTMLStackElem *Elem = new HTMLStackElem(_id, _level, current, blockStack); blockStack = Elem; addForbidden(_id, forbiddenTag);}void KHTMLParser::popBlock( int _id ){ HTMLStackElem *Elem = blockStack; int maxLevel = 0; while( Elem && (Elem->id != _id)) { if (maxLevel < Elem->level) { maxLevel = Elem->level; } Elem = Elem->next; } if (!Elem || maxLevel > Elem->level) return; Elem = blockStack; while (Elem) { if (Elem->id == _id) { popOneBlock(); Elem = 0; } else { popOneBlock(); Elem = blockStack; } }}void KHTMLParser::popOneBlock(){ HTMLStackElem *Elem = blockStack; // we should never get here, but some bad html might cause it.#ifndef PARSER_DEBUG if(!Elem) return;#else //kdDebug( 6035 ) << "popping block: " << Elem->id << endl;#endif if(Elem->node != current) if(current->renderer()) current->renderer()->close(); removeForbidden(Elem->id, forbiddenTag); blockStack = Elem->next; // we only set inline to false, if the element we close is a block level element. // This helps getting cases as <p><b>bla</b> <b>bla</b> right. if(!current->isInline()) _inline = false; current = Elem->node; delete Elem;}void KHTMLParser::popInlineBlocks(){ while(current->isInline()) popOneBlock();}void KHTMLParser::freeBlock(){ while (blockStack) popOneBlock(); blockStack = 0;}void KHTMLParser::createHead(){ if(head || !document->firstChild()) return; head = new HTMLHeadElementImpl(document); try { HTMLElementImpl *body = document->body(); document->firstChild()->insertBefore(head, body); } catch(DOMException e) {#ifdef PARSER_DEBUG //kdDebug( 6035 ) << "adding form before of table failed!!!!" << endl;#endif delete head; head = 0; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -