📄 htmlparser.cpp
字号:
case ID_LINK:
case ID_BASE:
if( !head )
createHead();
if( head ) {
if ( head->addChild(n) ) {
#if SPEED_DEBUG < 2
if(!n->attached() && HTMLWidget)
n->attach();
#endif
return true;
} else {
return false;
}
}
break;
case ID_HTML:
if (!current->isDocumentNode() ) {
if ( doc()->firstChild()->id() == ID_HTML) {
// we have another <HTML> element.... apply attributes to existing one
// make sure we don't overwrite already existing attributes
NamedAttrMapImpl *map = static_cast<ElementImpl*>(n)->attributes(true);
NamedAttrMapImpl *bmap = static_cast<ElementImpl*>(doc()->firstChild())->attributes(false);
bool changed = false;
for (unsigned long l = 0; map && l < map->length(); ++l) {
AttributeImpl* it = map->attributeItem(l);
changed = !bmap->getAttributeItem(it->id());
bmap->insertAttribute(it->clone(false));
}
if ( changed )
doc()->recalcStyle( NodeImpl::Inherit );
}
return false;
}
break;
case ID_TITLE:
case ID_STYLE:
if ( !head )
createHead();
if ( head ) {
DOM::NodeImpl *newNode = head->addChild(n);
if ( newNode ) {
pushBlock(id, tagPriority(id));
setCurrent(newNode);
#if SPEED_DEBUG < 2
if(!n->attached() && HTMLWidget)
n->attach();
#endif
} else {
#ifdef PARSER_DEBUG
kdDebug( 6035 ) << "adding style before to body failed!!!!" << endl;
#endif
discard_until = ID_STYLE + ID_CLOSE_TAG;
return false;
}
return true;
} else if(inBody) {
discard_until = ID_STYLE + ID_CLOSE_TAG;
return false;
}
break;
// SCRIPT and OBJECT are allowed in the body.
case ID_BODY:
if(inBody && doc()->body()) {
// we have another <BODY> element.... apply attributes to existing one
// make sure we don't overwrite already existing attributes
// some sites use <body bgcolor=rightcolor>...<body bgcolor=wrongcolor>
NamedAttrMapImpl *map = static_cast<ElementImpl*>(n)->attributes(true);
NamedAttrMapImpl *bmap = doc()->body()->attributes(false);
bool changed = false;
for (unsigned long l = 0; map && l < map->length(); ++l) {
AttributeImpl* it = map->attributeItem(l);
changed = !bmap->getAttributeItem(it->id());
bmap->insertAttribute(it->clone(false));
}
if ( changed )
doc()->recalcStyle( NodeImpl::Inherit );
} else if ( current->isDocumentNode() )
break;
return false;
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 && form) {
form->addChild(n);
#if SPEED_DEBUG < 2
if(!n->attached() && HTMLWidget)
n->attach();
#endif
return true;
}
break;
}
case ID_TEXT:
// 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_CAPTION: {
switch (current->id()) {
case ID_THEAD:
case ID_TBODY:
case ID_TFOOT:
case ID_TR:
case ID_TH:
case ID_TD: {
NodeImpl* tsection = current;
if (current->id() == ID_TR)
tsection = current->parent();
else if (current->id() == ID_TD || current->id() == ID_TH)
tsection = current->parent()->parent();
NodeImpl* table = tsection->parent();
int exceptioncode = 0;
table->insertBefore(n, tsection, exceptioncode);
pushBlock(id, tagPriority(id));
setCurrent(n);
inStrayTableContent++;
blockStack->strayTableContent = true;
return true;
}
default:
break;
}
break;
}
case ID_THEAD:
case ID_TBODY:
case ID_TFOOT:
case ID_COLGROUP: {
if (isTableRelatedTag(current->id())) {
while (blockStack && current->id() != ID_TABLE && isTableRelatedTag(current->id()))
popOneBlock();
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_TEXT: {
TextImpl *t = static_cast<TextImpl *>(n);
if (t->containsOnlyWhitespace())
return false;
/* Fall through to default */
}
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_CAPTION:
// Illegal content in a caption. Close the caption and try again.
popBlock(ID_CAPTION);
switch( id ) {
case ID_THEAD:
case ID_TFOOT:
case ID_TBODY:
case ID_TR:
case ID_TD:
case ID_TH:
return insertNode(n, flat);
}
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);
if (t->containsOnlyWhitespace())
return false;
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 (n->isTextNode() ||
( 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_TABLE) ? node :
((node->id() == ID_TR) ? parentparent : parent);
NodeImpl *parent = node->parentNode();
int exceptioncode = 0;
parent->insertBefore( n, node, exceptioncode );
if ( exceptioncode ) {
#ifdef PARSER_DEBUG
kdDebug( 6035 ) << "adding content before table failed!" << endl;
#endif
break;
}
if (n->isElementNode() && tagPriority(id) != 0 &&
!flat && endTagRequirement(id) != DOM::FORBIDDEN)
{
pushBlock(id, tagPriority(id));
setCurrent(n);
inStrayTableContent++;
blockStack->strayTableContent = true;
}
return true;
}
if ( current->id() == ID_TR )
e = new HTMLTableCellElementImpl(document, ID_TD);
else if ( current->id() == ID_TABLE )
e = new HTMLTableSectionElementImpl( document, ID_TBODY, true /* implicit */ );
else
e = new HTMLTableRowElementImpl( document );
insertNode(e);
handled = true;
break;
} // end default
} // end switch
break;
case ID_OBJECT:
discard_until = ID_OBJECT + ID_CLOSE_TAG;
return false;
case ID_UL:
case ID_OL:
case ID_DIR:
case ID_MENU:
e = new HTMLDivElementImpl(document);
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:
case ID_OPTGROUP:
if (id == ID_OPTGROUP)
{
popBlock(current->id());
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:
if (id != ID_TEXT) {
popBlock(ID_COLGROUP);
handled = true;
}
break;
case ID_FONT:
popBlock(ID_FONT);
handled = true;
break;
default:
if(current->isDocumentNode())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -