void HTMLDocumentImpl::close() { bool doload = !parsing() && m_tokenizer; DocumentImpl::close(); HTMLElementImpl* b = body(); if (b && doload) { // According to dom the load event must not bubble // but other browsers execute in a frameset document // the first(IE)/last(Moz/Konq) registered onload on a <frame> and the // first(IE)/last(Moz/Konq) registered onload on a <frameset>. // The body has the listener for <frame onload> b->dispatchWindowEvent(EventImpl::LOAD_EVENT, false, false); b = body(); // the onload code could have changed it (e.g. document.open/write/close) // The document has the listener for <frameset onload> if (b && b->id() == ID_FRAMESET) getDocument()->dispatchWindowEvent(EventImpl::LOAD_EVENT, false, false); // don't update rendering if we're going to redirect anyway if ( view() && ( view()->part()->d->m_redirectURL.isNull() || view()->part()->d->m_delayRedirect > 1 ) ) updateRendering(); } }
void HTMLTableCellElementImpl::attach(KHTMLView *_view) { HTMLElementImpl* p = static_cast<HTMLElementImpl*>(_parent); while(p && p->id() != ID_TABLE) p = static_cast<HTMLElementImpl*>(p->parentNode()); if(p) { HTMLTableElementImpl* table = static_cast<HTMLTableElementImpl*>(p); if(table->m_noBorder && getAttribute(ATTR_BORDER).isNull()) addCSSProperty(CSS_PROP_BORDER_WIDTH, "0px"); if(!table->getAttribute(ATTR_BORDERCOLOR).isNull()) addCSSProperty(CSS_PROP_BORDER_STYLE, "solid"); } setStyle(document->styleSelector()->styleForElement(this)); khtml::RenderObject *r = _parent->renderer(); if(r) { m_render = khtml::RenderObject::createObject(this); if(m_render && m_render->style()->display() == TABLE_CELL) { RenderTableCell *cell = static_cast<RenderTableCell *>(m_render); cell->setRowSpan(rSpan); cell->setColSpan(cSpan); cell->setNoWrap(nWrap); } if(m_render) r->addChild(m_render, _next ? _next->renderer() : 0); } NodeBaseImpl::attach(_view); }
void HTMLFrameSetElementImpl::attach() { assert(!m_render); assert(parentNode()); assert(parentNode()->renderer()); // inherit default settings from parent frameset HTMLElementImpl* node = static_cast<HTMLElementImpl*>(parentNode()); while(node) { if(node->id() == ID_FRAMESET) { HTMLFrameSetElementImpl* frameset = static_cast<HTMLFrameSetElementImpl*>(node); if(!frameBorderSet) frameborder = frameset->frameBorder(); if(!noresize) noresize = frameset->noResize(); break; } node = static_cast<HTMLElementImpl*>(node->parentNode()); } // ignore display: none m_render = new RenderFrameSet(this); m_render->setStyle(getDocument()->styleSelector()->styleForElement(this)); parentNode()->renderer()->addChild(m_render, nextRenderer()); NodeBaseImpl::attach(); }
void HTMLTableCellElementImpl::attach() { HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parentNode()); while(p && p->id() != ID_TABLE) p = static_cast<HTMLElementImpl*>(p->parentNode()); if(p) { HTMLTableElementImpl* table = static_cast<HTMLTableElementImpl*>(p); if (table->m_noBorder) { addCSSProperty(CSS_PROP_BORDER_WIDTH, "0"); } else { addCSSProperty(CSS_PROP_BORDER_WIDTH, "1px"); int v = (table->m_solid || m_solid) ? CSS_VAL_SOLID : CSS_VAL_INSET; addCSSProperty(CSS_PROP_BORDER_TOP_STYLE, v); addCSSProperty(CSS_PROP_BORDER_BOTTOM_STYLE, v); addCSSProperty(CSS_PROP_BORDER_LEFT_STYLE, v); addCSSProperty(CSS_PROP_BORDER_RIGHT_STYLE, v); if (!m_solid) addCSSProperty(CSS_PROP_BORDER_COLOR, "inherit"); } } HTMLTablePartElementImpl::attach(); }
void HTMLTableCellElementImpl::attach() { HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parentNode()); while(p && p->id() != ID_TABLE) p = static_cast<HTMLElementImpl*>(p->parentNode()); HTMLTablePartElementImpl::attach(); }
unsigned long HTMLFormCollectionImpl::calcLength(NodeImpl*) const { if(base->nodeType() == Node::ELEMENT_NODE) { HTMLElementImpl* e = static_cast<HTMLElementImpl*>(base); if(e->id() == ID_FORM) return static_cast<HTMLFormElementImpl*>(e)->formElements.count(); } return 0; }
void HTMLFrameElementImpl::attach() { assert(!attached()); assert(parentNode()); name = getAttribute(ATTR_NAME); if(name.isNull()) name = getAttribute(ATTR_ID); // inherit default settings from parent frameset HTMLElementImpl *node = static_cast< HTMLElementImpl * >(parentNode()); while(node) { if(node->id() == ID_FRAMESET) { HTMLFrameSetElementImpl *frameset = static_cast< HTMLFrameSetElementImpl * >(node); if(!frameBorderSet) frameBorder = frameset->frameBorder(); if(!noresize) noresize = frameset->noResize(); break; } node = static_cast< HTMLElementImpl * >(node->parentNode()); } if(parentNode()->renderer() && getDocument()->isURLAllowed(url.string())) { RenderStyle *_style = getDocument()->styleSelector()->styleForElement(this); _style->ref(); if(_style->display() != NONE) { m_render = new(getDocument()->renderArena()) RenderFrame(this); m_render->setStyle(_style); parentNode()->renderer()->addChild(m_render, nextRenderer()); } _style->deref(); } NodeBaseImpl::attach(); if(!m_render) return; KHTMLView *w = getDocument()->view(); if(w) { // we need a unique name for every frame in the frameset. Hope that's unique enough. if(name.isEmpty() || w->part()->frameExists(name.string())) name = DOMString(w->part()->requestFrameName()); // load the frame contents w->part()->requestFrame(static_cast< RenderFrame * >(m_render), url.string(), name.string()); } }
NodeImpl* HTMLFormCollectionImpl::getItem(NodeImpl *, int index, int&) const { if(base->nodeType() == Node::ELEMENT_NODE) { HTMLElementImpl* e = static_cast<HTMLElementImpl*>(base); if(e->id() == ID_FORM) return static_cast<HTMLFormElementImpl*>(e)->formElements.at(index); } return 0; }
// used by table cells to share style decls created by the enclosing table. CSSMutableStyleDeclarationImpl* HTMLTableCellElementImpl::additionalAttributeStyleDecl() { HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parentNode()); while(p && p->id() != ID_TABLE) p = static_cast<HTMLElementImpl*>(p->parentNode()); if (p) { HTMLTableElementImpl* table = static_cast<HTMLTableElementImpl*>(p); return table->getSharedCellDecl(); } return 0; }
void HTMLFrameElementImpl::attach() { assert(!attached()); assert(parentNode()); assert(parentNode()->renderer()); // we should first look up via id, then via name. // this shortterm hack fixes the ugly case. ### rewrite needed for next release name = getAttribute(ATTR_NAME); if (name.isNull()) name = getAttribute(ATTR_ID); // inherit default settings from parent frameset HTMLElementImpl* node = static_cast<HTMLElementImpl*>(parentNode()); while(node) { if(node->id() == ID_FRAMESET) { HTMLFrameSetElementImpl* frameset = static_cast<HTMLFrameSetElementImpl*>(node); if(!frameBorderSet) frameBorder = frameset->frameBorder(); if(!noresize) noresize = frameset->noResize(); break; } node = static_cast<HTMLElementImpl*>(node->parentNode()); } // ignore display: none for this element! KHTMLView* w = getDocument()->view(); if (isURLAllowed(url.string())) { m_render = new RenderFrame(this); m_render->setStyle(getDocument()->styleSelector()->styleForElement(this)); parentNode()->renderer()->addChild(m_render, nextRenderer()); } NodeBaseImpl::attach(); if (!m_render) return; // we need a unique name for every frame in the frameset. Hope that's unique enough. if(name.isEmpty() || w->part()->frameExists( name.string() ) ) name = DOMString(w->part()->requestFrameName()); // load the frame contents w->part()->requestFrame( static_cast<RenderFrame*>(m_render), url.string(), name.string() ); }
NodeImpl* HTMLFormCollectionImpl::getNamedItem(NodeImpl*, int attr_id, const DOMString& name) const { if(base->nodeType() == Node::ELEMENT_NODE) { HTMLElementImpl* e = static_cast<HTMLElementImpl*>(base); if(e->id() == ID_FORM) { HTMLGenericFormElementImpl* element; HTMLFormElementImpl* f = static_cast<HTMLFormElementImpl*>(e); for(element = f->formElements.first(); element; element = f->formElements.next()) if(element->getAttribute(attr_id) == name) return element; } } return 0; }
void RenderPartObject::updateWidget() { QString url; QString serviceType; QStringList params; KHTMLPart *part = m_view->part(); setNeedsLayoutAndMinMaxRecalc(); if (element()->id() == ID_OBJECT) { HTMLObjectElementImpl *o = static_cast<HTMLObjectElementImpl *>(element()); // Check for a child EMBED tag. HTMLEmbedElementImpl *embed = 0; for (NodeImpl *child = o->firstChild(); child; child = child->nextSibling()) { if (child->id() == ID_EMBED) { embed = static_cast<HTMLEmbedElementImpl *>( child ); break; } } // Use the attributes from the EMBED tag instead of the OBJECT tag including WIDTH and HEIGHT. HTMLElementImpl *embedOrObject; if (embed) { embedOrObject = (HTMLElementImpl *)embed; DOMString attribute = embedOrObject->getAttribute(ATTR_WIDTH); if (!attribute.isEmpty()) { o->setAttribute(ATTR_WIDTH, attribute); } attribute = embedOrObject->getAttribute(ATTR_HEIGHT); if (!attribute.isEmpty()) { o->setAttribute(ATTR_HEIGHT, attribute); } url = embed->url; serviceType = embed->serviceType; } else { embedOrObject = (HTMLElementImpl *)o; } // If there was no URL or type defined in EMBED, try the OBJECT tag. if (url.isEmpty()) { url = o->url; } if (serviceType.isEmpty()) { serviceType = o->serviceType; } // Then try the PARAM tags for the URL and type attributes. NodeImpl *child = o->firstChild(); while (child && (url.isEmpty() || serviceType.isEmpty())) { if (child->id() == ID_PARAM) { HTMLParamElementImpl *p = static_cast<HTMLParamElementImpl *>( child ); QString name = p->name().lower(); if (url.isEmpty() && (QString::equals(name,"src") || QString::equals(name,"movie") || QString::equals(name,"code"))) { url = p->value(); } if (serviceType.isEmpty() && QString::equals(name,"type")) { serviceType = p->value(); } } child = child->nextSibling(); } // Lastly try to map a specific CLASSID to a type. if (serviceType.isEmpty() && !o->classId.isEmpty()) { if (o->classId.contains("D27CDB6E-AE6D-11cf-96B8-444553540000")) { // It is ActiveX, but the nsplugin system handling // should also work, that's why we don't override the // serviceType with application/x-activex-handler // but let the KTrader in khtmlpart::createPart() detect // the user's preference: launch with activex viewer or // with nspluginviewer (Niko) serviceType = "application/x-shockwave-flash"; } else if(o->classId.contains("CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA")) { serviceType = "audio/x-pn-realaudio-plugin"; } else if(o->classId.contains("02BF25D5-8C17-4B23-BC80-D3488ABDDC6B")) { serviceType = "video/quicktime"; } else if(o->classId.contains("166B1BCA-3F9C-11CF-8075-444553540000")) { serviceType = "application/x-director"; } else { // We have a clsid, means this is activex (Niko) serviceType = "application/x-activex-handler"; } // TODO: add more plugins here } // If no URL and type, abort. if (url.isEmpty() && serviceType.isEmpty()) { #ifdef DEBUG_LAYOUT kdDebug() << "RenderPartObject::close - empty url and serverType" << endl; #endif return; } // Turn the attributes of either the EMBED tag or OBJECT tag into an array. NamedAttrMapImpl* attributes = embedOrObject->attributes(); if (attributes) { for (unsigned long i = 0; i < attributes->length(); ++i) { AttributeImpl* it = attributes->attributeItem(i); params.append(o->getDocument()->attrName(it->id()).string() + "=\"" + it->value().string() + "\""); } } params.append( QString::fromLatin1("__KHTML__CLASSID=\"%1\"").arg( o->classId ) ); params.append( QString::fromLatin1("__KHTML__CODEBASE=\"%1\"").arg( o->getAttribute(ATTR_CODEBASE).string() ) ); part->requestObject( this, url, serviceType, params ); } else if ( element()->id() == ID_EMBED ) { HTMLEmbedElementImpl *o = static_cast<HTMLEmbedElementImpl *>(element()); url = o->url; serviceType = o->serviceType; if ( url.isEmpty() && serviceType.isEmpty() ) { #ifdef DEBUG_LAYOUT kdDebug() << "RenderPartObject::close - empty url and serverType" << endl; #endif return; } // add all attributes set on the embed object NamedAttrMapImpl* a = o->attributes(); if (a) { for (unsigned long i = 0; i < a->length(); ++i) { AttributeImpl* it = a->attributeItem(i); params.append(o->getDocument()->attrName(it->id()).string() + "=\"" + it->value().string() + "\""); } } part->requestObject( this, url, serviceType, params ); } else { assert(element()->id() == ID_IFRAME); HTMLIFrameElementImpl *o = static_cast<HTMLIFrameElementImpl *>(element()); url = o->url.string(); if (url.isEmpty()) url = "about:blank"; KHTMLView *v = static_cast<KHTMLView *>(m_view); bool requestSucceeded = v->part()->requestFrame( this, url, o->name.string(), QStringList(), true ); if (requestSucceeded && QString::equals(url,"about:blank")) { KHTMLPart *newPart = v->part()->findFrame( o->name.string() ); if (newPart && newPart->xmlDocImpl()) { newPart->xmlDocImpl()->setBaseURL( v->part()->baseURL().url() ); } } } }
bool KHTMLParser::insertNode(NodeImpl *n, bool flat) { int id = n->id(); // let's be stupid and just try to insert it. // this should work if the document is wellformed #ifdef PARSER_DEBUG NodeImpl *tmp = current; #endif NodeImpl *newNode = current->addChild(n); if ( newNode ) { #ifdef PARSER_DEBUG kdDebug( 6035 ) << "added " << n->nodeName().string() << " to " << tmp->nodeName().string() << ", new current=" << newNode->nodeName().string() << endl; #endif // have to do this here (and not when creating the node, as we don't know before where we add the LI element to. if ( id == ID_LI && n->isElementNode() ) { int cid = current->id(); if ( cid != ID_UL && cid != ID_OL ) static_cast<HTMLElementImpl*>(n)->addCSSProperty(CSS_PROP_LIST_STYLE_POSITION, CSS_VAL_INSIDE); } // don't push elements without end tag on the stack if(tagPriority[id] != 0 && !flat) { #if SPEED_DEBUG < 2 if(!n->attached() && HTMLWidget ) n->attach(); #endif if(n->isInline()) m_inline = true; pushBlock(id, tagPriority[id]); current = newNode; } else { #if SPEED_DEBUG < 2 if(!n->attached() && HTMLWidget) n->attach(); if (n->maintainsState()) { document->document()->registerMaintainsState(n); QString state(document->document()->nextState()); if (!state.isNull()) n->restoreState(state); } if(n->renderer()) n->renderer()->close(); #endif if(n->isInline()) m_inline = true; } #if SPEED_DEBUG < 1 if(tagPriority[id] == 0 && n->renderer()) n->renderer()->calcMinMaxWidth(); #endif return true; } else { #ifdef PARSER_DEBUG kdDebug( 6035 ) << "ADDING NODE FAILED!!!! current = " << current->nodeName().string() << ", new = " << n->nodeName().string() << endl; #endif // error handling... HTMLElementImpl *e; bool handled = false; // never create anonymous objects just to hold a space. if ( id == ID_TEXT && static_cast<TextImpl *>(n)->string()->l == 1 && static_cast<TextImpl *>(n)->string()->s[0] == " " ) return false; // switch according to the element to insert switch(id) { case ID_COMMENT: break; case ID_HEAD: // ### alllow not having <HTML> in at all, as per HTML spec if (!current->isDocumentNode() && current->id() != ID_HTML ) return false; break; case ID_META: case ID_LINK: case ID_ISINDEX: 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; } 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(new AttributeImpl(it->id(), it->val())); } 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]); current = 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 + ID_CLOSE_TAG; return false; } break; case ID_SCRIPT: // if we failed to insert it, go into skip mode discard_until = id + ID_CLOSE_TAG; break; 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(new AttributeImpl(it->id(), it->val())); } 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 ) break; // Fall through! } 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_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; 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 = checkChild( current->id(), id); 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 ( !container->attached() && 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, true /* implicit */ ); 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_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_DL: case ID_DT: case ID_ADDRESS: case ID_COLGROUP: case ID_FONT: case ID_CAPTION: popBlock(current->id()); 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); } }
unsigned long HTMLCollectionImpl::calcLength(NodeImpl *current) const { unsigned long len = 0; while(current) { if(current->nodeType() == Node::ELEMENT_NODE) { bool deep = true; HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current); switch(type) { case DOC_IMAGES: if(e->id() == ID_IMG) len++; break; case DOC_FORMS: if(e->id() == ID_FORM) len++; break; case TABLE_TBODIES: if(e->id() == ID_TBODY) len++; else if(e->id() == ID_TABLE) deep = false; break; case TR_CELLS: if(e->id() == ID_TD) len++; else if(e->id() == ID_TABLE) deep = false; break; case TABLE_ROWS: case TSECTION_ROWS: if(e->id() == ID_TR || e->id() == ID_TH) len++; else if(e->id() == ID_TABLE) deep = false; break; case SELECT_OPTIONS: if(e->id() == ID_OPTION) len++; break; case MAP_AREAS: if(e->id() == ID_AREA) len++; break; case DOC_APPLETS: // all OBJECT and APPLET elements if(e->id() == ID_OBJECT || e->id() == ID_APPLET) len++; break; case DOC_LINKS: // all A _and_ AREA elements with a value for href if(e->id() == ID_A || e->id() == ID_AREA) if(e->getAttribute(ATTR_HREF) != 0) len++; break; case DOC_ANCHORS: // all A elements with a value for name and all elements with an id attribute if ( e->hasID() ) len++; else if(e->id() == ID_A) { if(e->getAttribute(ATTR_NAME) != 0) len++; } break; case DOC_ALL: // "all" elements len++; break; default: kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl; } if(deep && current->firstChild()) len += calcLength(current->firstChild()); } current = current->nextSibling(); } return len; }
NodeImpl *HTMLCollectionImpl::getNamedItem( NodeImpl *current, int attr_id, const DOMString &name ) const { if(name.isEmpty()) return 0; while(current) { if(current->nodeType() == Node::ELEMENT_NODE) { bool deep = true; bool check = false; HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current); switch(type) { case DOC_IMAGES: if(e->id() == ID_IMG) check = true; break; case DOC_FORMS: if(e->id() == ID_FORM) check = true; break; case TABLE_TBODIES: if(e->id() == ID_TBODY) check = true; else if(e->id() == ID_TABLE) deep = false; break; case TR_CELLS: if(e->id() == ID_TD) check = true; else if(e->id() == ID_TABLE) deep = false; break; case TABLE_ROWS: case TSECTION_ROWS: if(e->id() == ID_TR || e->id() == ID_TH) check = true; else if(e->id() == ID_TABLE) deep = false; break; case SELECT_OPTIONS: if(e->id() == ID_OPTION) check = true; break; case MAP_AREAS: if(e->id() == ID_AREA) check = true; break; case DOC_APPLETS: // all OBJECT and APPLET elements if(e->id() == ID_OBJECT || e->id() == ID_APPLET) check = true; break; case DOC_LINKS: // all A _and_ AREA elements with a value for href if(e->id() == ID_A || e->id() == ID_AREA) if(e->getAttribute(ATTR_HREF) != 0) check = true; break; case DOC_ANCHORS: // all A elements with a value for name if( e->hasID() ) check = true; else if(e->id() == ID_A) if(e->getAttribute(ATTR_NAME) != 0) check = true; break; case DOC_ALL: check = true; break; default: kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl; break; } if(check && e->getAttribute(attr_id) == name) { //kdDebug( 6030 ) << "found node: " << e << " " << current << " " << e->id() << endl; return current; } NodeImpl *retval = 0; if(deep && current->firstChild()) retval = getNamedItem(current->firstChild(), attr_id, name); if(retval) { //kdDebug( 6030 ) << "got a return value " << retval << endl; return retval; } } current = current->nextSibling(); } return 0; }
NodeImpl *HTMLCollectionImpl::getItem(NodeImpl *current, int index, int &len) const { while(current) { if(current->nodeType() == Node::ELEMENT_NODE) { bool deep = true; HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current); switch(type) { case DOC_IMAGES: if(e->id() == ID_IMG) len++; break; case DOC_FORMS: if(e->id() == ID_FORM) len++; break; case TABLE_TBODIES: if(e->id() == ID_TBODY) len++; else if(e->id() == ID_TABLE) deep = false; break; case TR_CELLS: if(e->id() == ID_TD) len++; else if(e->id() == ID_TABLE) deep = false; break; case TABLE_ROWS: case TSECTION_ROWS: if(e->id() == ID_TR || e->id() == ID_TH) len++; else if(e->id() == ID_TABLE) deep = false; break; case SELECT_OPTIONS: if(e->id() == ID_OPTION) len++; break; case MAP_AREAS: if(e->id() == ID_AREA) len++; break; case DOC_APPLETS: // all OBJECT and APPLET elements if(e->id() == ID_OBJECT || e->id() == ID_APPLET) len++; break; case DOC_LINKS: // all A _and_ AREA elements with a value for href if(e->id() == ID_A || e->id() == ID_AREA) if(e->getAttribute(ATTR_HREF) != 0) len++; break; case DOC_ANCHORS: // all A elements with a value for name or an id attribute if( e->hasID() ) len++; else if(e->id() == ID_A) if(e->getAttribute(ATTR_NAME) != 0) len++; break; case DOC_ALL: len++; break; default: kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl; } if(len == (index + 1)) return current; NodeImpl *retval=0; if(deep && current->firstChild()) retval = getItem(current->firstChild(), index, len); if(retval) return retval; } current = current->nextSibling(); } return 0; }