📄 htmlparser.cpp
字号:
// ignore text inside the following elements. switch(current->id()) { case ID_SELECT: return false; default: ; // fall through!! }; break; case ID_DD: case ID_DT: e = new HTMLDListElementImpl(document); if ( insertNode(e) ) { insertNode(n); return true; } break; case ID_AREA: { if(map) { map->addChild(n);#if SPEED_DEBUG < 2 if(!n->attached() && HTMLWidget) n->attach();#endif handled = true; } else return false; return true; } case ID_TD: case ID_TH: // lets try to close the konqblock if ( haveKonqBlock ) { popBlock( ID__KONQBLOCK ); haveKonqBlock = false; return insertNode( n ); } default: break; } // switch on the currently active element switch(current->id()) { case ID_HTML: switch(id) { case ID_SCRIPT: case ID_STYLE: case ID_META: case ID_LINK: case ID_OBJECT: case ID_EMBED: case ID_TITLE: case ID_ISINDEX: case ID_BASE: if(!head) { head = new HTMLHeadElementImpl(document); e = head; insertNode(e); handled = true; } break; case ID_FRAME: if( haveFrameSet ) break; e = new HTMLFrameSetElementImpl(document); inBody = true; noRealBody = false; haveFrameSet = true; insertNode(e); handled = true; break; default: if ( haveFrameSet ) break; e = new HTMLBodyElementImpl(document); startBody(); insertNode(e); handled = true; break; } break; case ID_HEAD: // we can get here only if the element is not allowed in head. if (id == ID_HTML) return false; else { // This means the body starts here... if ( haveFrameSet ) break; popBlock(ID_HEAD); e = new HTMLBodyElementImpl(document); startBody(); insertNode(e); handled = true; } break; case ID_BODY: break; case ID__KONQBLOCK: switch( id ) { case ID_THEAD: case ID_TFOOT: case ID_TBODY: case ID_TR: case ID_TD: case ID_TH: // now the actual table contents starts // lets close our anonymous block before the table // and go ahead! popBlock( ID__KONQBLOCK ); haveKonqBlock = false; handled = checkChild( current->id(), id ); break; default: break; } break; case ID_TABLE: case ID_THEAD: case ID_TFOOT: case ID_TBODY: case ID_TR: switch(id) { case ID_TABLE: popBlock(ID_TABLE); // end the table handled = true; // ...and start a new one break; case ID_TEXT: { TextImpl *t = static_cast<TextImpl *>(n); DOMStringImpl *i = t->string(); unsigned int pos = 0; while(pos < i->l && ( *(i->s+pos) == QChar(' ') || *(i->s+pos) == QChar(0xa0))) pos++; if(pos == i->l) break; } default: { NodeImpl *node = current; NodeImpl *parent = node->parentNode(); NodeImpl *parentparent = parent->parentNode(); if(( node->id() == ID_TR && ( parent->id() == ID_THEAD || parent->id() == ID_TBODY || parent->id() == ID_TFOOT ) && parentparent->id() == ID_TABLE ) || ( !checkChild( ID_TR, id ) && ( node->id() == ID_THEAD || node->id() == ID_TBODY || node->id() == ID_TFOOT ) && parent->id() == ID_TABLE ) ) { node = ( node->id() == ID_TR ) ? parentparent : parent; NodeImpl *parent = node->parentNode(); int exceptioncode = 0; NodeImpl *container = new HTMLGenericElementImpl( document, ID__KONQBLOCK ); parent->insertBefore( container, node, exceptioncode ); if ( exceptioncode ) {#ifdef PARSER_DEBUG kdDebug( 6035 ) << "adding anonymous container before table failed!" << endl;#endif break; } if ( HTMLWidget ) container->attach(); pushBlock( ID__KONQBLOCK, tagPriority[ID__KONQBLOCK] ); haveKonqBlock = true; current = container; handled = true; break; } if ( current->id() == ID_TR ) e = new HTMLTableCellElementImpl(document, ID_TD); else if ( current->id() == ID_TABLE ) e = new HTMLTableSectionElementImpl( document, ID_TBODY ); else e = new HTMLTableRowElementImpl( document ); insertNode(e); handled = true; break; } // end default } // end switch break; case ID_OBJECT: discard_until = id + ID_CLOSE_TAG; return false; case ID_UL: case ID_OL: case ID_DIR: case ID_MENU: e = new HTMLLIElementImpl(document); e->addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, CSS_VAL_NONE); insertNode(e); handled = true; break; case ID_DL: popBlock(ID_DL); handled = true; break; case ID_DT: popBlock(ID_DT); handled = true; break; case ID_SELECT: if( n->isInline() ) return false; break; case ID_P: case ID_H1: case ID_H2: case ID_H3: case ID_H4: case ID_H5: case ID_H6: if(!n->isInline()) { popBlock(current->id()); handled = true; } break; case ID_OPTION: if (id == ID_OPTGROUP) { popBlock(ID_OPTION); handled = true; } else if(id == ID_SELECT) { // IE treats a nested select as </select>. Let's do the same popBlock( ID_SELECT ); break; } break; // head elements in the body should be ignored. case ID_ADDRESS: popBlock(ID_ADDRESS); handled = true; break; case ID_COLGROUP: popBlock(ID_COLGROUP); handled = true; break; case ID_FONT: popBlock(ID_FONT); handled = true; break; default: if(current->isDocumentNode()) { if(current->firstChild() == 0) { e = new HTMLHtmlElementImpl(document); insertNode(e); handled = true; } } else if(current->isInline()) { popInlineBlocks(); handled = true; } } // if we couldn't handle the error, just rethrow the exception... if(!handled) { //kdDebug( 6035 ) << "Exception handler failed in HTMLPArser::insertNode()" << endl; return false; } return insertNode(n); }}NodeImpl *KHTMLParser::getElement(Token* t){ NodeImpl *n = 0; switch(t->id) { case ID_HTML: n = new HTMLHtmlElementImpl(document); break; case ID_HEAD: if(!head && current->id() == ID_HTML) { head = new HTMLHeadElementImpl(document); n = head; } break; case ID_BODY: // body no longer allowed if we have a frameset if(haveFrameSet) break; popBlock(ID_HEAD); n = new HTMLBodyElementImpl(document); startBody(); noRealBody = false; break;// head elements case ID_BASE: n = new HTMLBaseElementImpl(document); break; case ID_LINK: n = new HTMLLinkElementImpl(document); break; case ID_META: n = new HTMLMetaElementImpl(document); break; case ID_STYLE: n = new HTMLStyleElementImpl(document); break; case ID_TITLE: n = new HTMLTitleElementImpl(document); break;// frames case ID_FRAME: n = new HTMLFrameElementImpl(document); break; case ID_FRAMESET: popBlock(ID_HEAD); if ( inBody && !haveFrameSet) { popBlock( ID_BODY ); doc()->setBody( 0 ); inBody = false; noRealBody = true; } if ( haveFrameSet && current->id() == ID_HTML ) break; n = new HTMLFrameSetElementImpl(document); haveFrameSet = true; startBody(); noRealBody = false; break; // a bit a special case, since the frame is inlined... case ID_IFRAME: n = new HTMLIFrameElementImpl(document); discard_until = ID_IFRAME+ID_CLOSE_TAG; 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_ISINDEX: n = handleIsindex(t); if( !inBody ) { isindex = n; n = 0; } else flat = true; 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: {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -