📄 htmlparser.cpp
字号:
throw exception; break; // We can deal with a base, meta and link element in the body, by just adding the element to head. case ID_META: case ID_LINK: case ID_BASE: if( !head ) createHead(); if( head ) { head->addChild(n); n->attach(HTMLWidget); return; } break; case ID_HTML: if (!current->isDocumentNode()) throw exception; break; case ID_TITLE: case ID_STYLE: if ( !head ) createHead(); if ( head ) { try { head->addChild(n); pushBlock(id, tagPriority[id]); current = n; n->attach(HTMLWidget); } catch(DOMException e) {#ifdef PARSER_DEBUG //kdDebug( 6035 ) << "adding style before to body failed!!!!" << endl;#endif discard_until = ID_STYLE + ID_CLOSE_TAG; throw e; } return; } else if(inBody) { discard_until = ID_STYLE + ID_CLOSE_TAG; throw exception; } break; // SCRIPT and OBJECT are allowd in the body. case ID_BODY: if(inBody && document->body()) { // we have another <BODY> element.... apply attributes to existing one NamedNodeMapImpl *map = n->attributes(); unsigned long attrNo; for (attrNo = 0; attrNo < map->length(); attrNo++) document->body()->setAttributeNode(static_cast<AttrImpl*>(map->item(attrNo)->cloneNode(false))); document->body()->applyChanges(true,false); } else if ( current->isDocumentNode() ) break; throw exception; break; case ID_LI: e = new HTMLUListElementImpl(document); e->addCSSProperty(CSS_PROP_MARGIN_LEFT, DOMString("0pt"), false); e->addCSSProperty(CSS_PROP_LIST_STYLE_POSITION, DOMString("inside"), false); insertNode(e); insertNode(n); return; break; // the following is a hack to move non rendered elements // outside of tables. // needed for broken constructs like <table><form ...><tr>.... case ID_INPUT: { ElementImpl *e = static_cast<ElementImpl *>(n); DOMString type = e->getAttribute(ATTR_TYPE); if ( strcasecmp( type, "hidden" ) != 0 ) break; // Fall through! } case ID_MAP: case ID_FORM: case ID_SCRIPT: {#ifdef PARSER_DEBUG //kdDebug( 6035 ) << "--> badly placed element!!!" << endl;#endif NodeImpl *node = current; // in case the form is opened inside the table (<table><form ...><tr> or similar) // we need to move it outside the table. if(node->id() == ID_TR) node = node->parentNode(); if(node->id() == ID_THEAD) node = node->parentNode(); else if(node->id() == ID_TBODY) node = node->parentNode(); else if(node->id() == ID_TFOOT) node = node->parentNode(); if(node->id() == ID_TABLE) { NodeImpl *parent = node->parentNode(); ////kdDebug( 6035 ) << "trying to add form to " << parent->id() << endl; try { parent->insertBefore(n, node); if(tagPriority[id] != 0 && id != ID_FORM && id != ID_INPUT ) { pushBlock(id, tagPriority[id]); current = n; } n->attach(HTMLWidget); if(tagPriority[id] == 0 && n->renderer()) n->renderer()->close(); } catch(DOMException e) {#ifdef PARSER_DEBUG //kdDebug( 6035 ) << "adding form before of table failed!!!!" << endl;#endif throw e; } return; } break; } case ID_DD: case ID_DT: e = new HTMLDListElementImpl(document); insertNode(e); insertNode(n); return; break; case ID_AREA: { if(map) { map->addChild(n); n->attach(HTMLWidget); handled = true; } else throw exception; return; } case ID_TEXT: // ignore text inside the following elements. switch(current->id()) { case ID_SELECT: throw exception; return; default: break; } break; default: break; } // switch on the currently active element switch(current->id()) { case ID_HTML: switch(id) { // ### check, there's only one HTML and one BODY tag! 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: // ### what about <script> tags between head and body???? if(!head) { head = new HTMLHeadElementImpl(document); e = head; insertNode(e); handled = true; } break; case ID_FRAME: // TODO if( haveFrameSet ) break; e = new HTMLFrameSetElementImpl(document); inBody = true; haveFrameSet = true; insertNode(e); handled = true; break; default: e = new HTMLBodyElementImpl(document); inBody = true; insertNode(e); document->createSelector(); handled = true; break; } break; case ID_HEAD: // we can get here only if the element is not allowed in head. if (id == ID_HTML) throw exception; else { // This means the body starts here... popBlock(ID_HEAD); e = new HTMLBodyElementImpl(document); inBody = true; insertNode(e); document->createSelector(); handled = true; } break; case ID_BODY: break; case ID_TABLE: switch(id) { case ID_COL: case ID_COLGROUP: case ID_P: 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; } } case ID_COMMENT: break; // Fall through! default: e = new HTMLTableSectionElementImpl(document, ID_TBODY); insertNode(e); handled = true; break; } break; case ID_THEAD: case ID_TFOOT: case ID_TBODY: switch(id) { case ID_COMMENT: case ID_FONT: case ID_COL: case ID_COLGROUP: case ID_P: break; default: e = new HTMLTableRowElementImpl(document); insertNode(e); handled = true; break; } break; case ID_TR: switch(id) { case ID_COMMENT: case ID_FONT: case ID_COL: case ID_COLGROUP: case ID_P: 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; } } // Fall through! default: e = new HTMLTableCellElementImpl(document, ID_TD); insertNode(e); handled = true; break; } break; case ID_UL: case ID_OL: case ID_DIR: case ID_MENU: e = new HTMLLIElementImpl(document); e->addCSSProperty(CSS_PROP_LIST_STYLE_TYPE, DOMString("none"), false); insertNode(e); handled = true; break; case ID_DL: e = new HTMLGenericElementImpl(document, ID_DD); insertNode(e); handled = true; break; case ID_DT: popBlock(ID_DT); handled = true; break; case ID_SELECT: if( n->isInline() ) throw exception; 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; } 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; 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; throw exception; } 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: popBlock(ID_HEAD); n = new HTMLBodyElementImpl(document); inBody = true; break;// head elements case ID_BASE: n = new HTMLBaseElementImpl(document); break; case ID_ISINDEX: n = new HTMLIsIndexElementImpl(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;// TODO// frames case ID_FRAME: n = new HTMLFrameElementImpl(document); break; case ID_FRAMESET: popBlock(ID_HEAD); if ( haveFrameSet && current->id() == ID_HTML )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -