📄 html_miscimpl.cpp
字号:
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 || e->id() == ID_TH) check = true; else if(e->id() == ID_TABLE) deep = false; break; case TABLE_ROWS: case TSECTION_ROWS: if(e->id() == ID_TR) 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_EMBEDS: // all EMBED elements if(e->id() == ID_EMBED) 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).isNull()) check = true; break; case DOC_ANCHORS: // all A elements with a value for name if(e->id() == ID_A) if(!e->getAttribute(ATTR_NAME).isNull()) check = true; break; case DOC_ALL: check = true; break; case NODE_CHILDREN: check = true; deep = false; break; default: kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl; break; } if (check) { bool found; if (caseSensitive) found = e->getAttribute(attr_id) == name; else found = e->getAttribute(attr_id).domString().lower() == name.lower(); if (found) { //kdDebug( 6030 ) << "found node: " << e << " " << current << " " << e->id() << " " << e->tagName().string() << endl; return current; } } NodeImpl *retval = 0; if(deep && current->firstChild()) retval = getNamedItem(current->firstChild(), attr_id, name, caseSensitive); if(retval) { //kdDebug( 6030 ) << "got a return value " << retval << endl; return retval; } } current = current->nextSibling(); } return 0;}NodeImpl *HTMLCollectionImpl::namedItem( const DOMString &name, bool caseSensitive ) const{ // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp // This method first searches for an object with a matching id // attribute. If a match is not found, the method then searches for an // object with a matching name attribute, but only on those elements // that are allowed a name attribute. idsDone = false; currentItem = getNamedItem(base->firstChild(), ATTR_ID, name, caseSensitive); if(currentItem) return currentItem; idsDone = true; currentItem = getNamedItem(base->firstChild(), ATTR_NAME, name, caseSensitive); return currentItem;}NodeImpl *HTMLCollectionImpl::nextNamedItem( const DOMString &name ) const{ // nextNamedItemInternal can return an item that has both id=<name> and name=<name> // Here, we have to filter out such cases. NodeImpl *impl = nextNamedItemInternal( name ); if (!idsDone) // looking for id=<name> -> no filtering return impl; // looking for name=<name> -> filter out if id=<name> bool ok = false; while (impl && !ok) { if(impl->nodeType() == Node::ELEMENT_NODE) { HTMLElementImpl *e = static_cast<HTMLElementImpl *>(impl); ok = (e->getAttribute(ATTR_ID) != name); if (!ok) impl = nextNamedItemInternal( name ); } else // can't happen ok = true; } return impl;}NodeImpl *HTMLCollectionImpl::nextNamedItemInternal( const DOMString &name ) const{ //kdDebug() << "\nHTMLCollectionImpl::nextNamedItem starting at " << currentItem << endl; // Go to next item first (to avoid returning the same) currentItem = nextItem(); //kdDebug() << "*HTMLCollectionImpl::nextNamedItem next item is " << currentItem << endl; if ( currentItem ) { // Then look for next matching named item NodeImpl *retval = getNamedItem(currentItem, idsDone ? ATTR_NAME : ATTR_ID, name); if ( retval ) { //kdDebug() << "*HTMLCollectionImpl::nextNamedItem found " << retval << endl; currentItem = retval; return retval; } // retval was 0, means we have to go up while( !retval && currentItem->parentNode() && currentItem->parentNode() != base ) { currentItem = currentItem->parentNode(); if (currentItem->nextSibling()) { // ... and to take the first one from there retval = getNamedItem(currentItem->nextSibling(), idsDone ? ATTR_NAME : ATTR_ID, name); } } if ( retval ) { //kdDebug() << "*HTMLCollectionImpl::nextNamedItem found after going up " << retval << endl; currentItem = retval; return currentItem; } } if ( idsDone ) return 0; // After doing all ATTR_ID, do ATTR_NAME //kdDebug() << "*HTMLCollectionImpl::nextNamedItem going to ATTR_NAME now" << endl; idsDone = true; currentItem = getNamedItem(base->firstChild(), ATTR_NAME, name); return currentItem;}// -----------------------------------------------------------------------------unsigned long HTMLFormCollectionImpl::calcLength(NodeImpl*) const{ QPtrList<HTMLGenericFormElementImpl> l = static_cast<HTMLFormElementImpl*>( base )->formElements; int len = 0; for ( unsigned i = 0; i < l.count(); i++ ) if ( l.at( i )->isEnumeratable() ) ++len; return len;}NodeImpl* HTMLFormCollectionImpl::getItem(NodeImpl *, int index, int&) const{ QPtrList<HTMLGenericFormElementImpl> l = static_cast<HTMLFormElementImpl*>( base )->formElements; for ( unsigned i = 0; i < l.count(); i++ ) { if( l.at( i )->isEnumeratable() ) { if ( !index ) return l.at( i ); --index; } } return 0;}NodeImpl* HTMLFormCollectionImpl::getNamedItem(NodeImpl*, int attr_id, const DOMString& name, bool caseSensitive) const{ currentPos = 0; return getNamedFormItem( attr_id, name, 0, caseSensitive );}NodeImpl* HTMLFormCollectionImpl::getNamedFormItem(int attr_id, const DOMString& name, int duplicateNumber, bool caseSensitive) const{ if(base->nodeType() == Node::ELEMENT_NODE) { HTMLElementImpl* e = static_cast<HTMLElementImpl*>(base); if(e->id() == ID_FORM) { HTMLFormElementImpl* f = static_cast<HTMLFormElementImpl*>(e); for(HTMLGenericFormElementImpl* e = f->formElements.first(); e; e = f->formElements.next()) if(e->isEnumeratable()) { bool found; if (caseSensitive) found = e->getAttribute(attr_id) == name; else found = e->getAttribute(attr_id).domString().lower() == name.lower(); if (found) { if (!duplicateNumber) return e; --duplicateNumber; } } } NodeImpl* retval = getNamedImgItem( base->firstChild(), attr_id, name, duplicateNumber, caseSensitive ); if ( retval ) return retval; } return 0;}NodeImpl* HTMLFormCollectionImpl::getNamedImgItem(NodeImpl* current, int attr_id, const DOMString& name, int& duplicateNumber, bool caseSensitive) const{ // strange case. IE and NS allow to get hold of <img> tags, // but they don't include them in the elements() collection. while ( current ) { if(current->nodeType() == Node::ELEMENT_NODE) { HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current); if(e->id() == ID_IMG) { bool found; if (caseSensitive) found = e->getAttribute(attr_id) == name; else found = e->getAttribute(attr_id).domString().lower() == name.lower(); if (found) { if (!duplicateNumber) return current; --duplicateNumber; } } if(current->firstChild()) { // The recursion here is the reason why this is a separate method NodeImpl *retval = getNamedImgItem(current->firstChild(), attr_id, name, duplicateNumber, caseSensitive); if(retval) { //kdDebug( 6030 ) << "got a return value " << retval << endl; return retval; } } } current = current->nextSibling(); } // while return 0;}NodeImpl * HTMLFormCollectionImpl::firstItem() const{ currentPos = 0; int dummy = 0; return getItem(0 /*base->firstChild() unused*/, currentPos, dummy);}NodeImpl * HTMLFormCollectionImpl::nextItem() const{ // This implementation loses the whole benefit of firstItem/nextItem :( int dummy = 0; return getItem(0 /*base->firstChild() unused*/, ++currentPos, dummy);}NodeImpl * HTMLFormCollectionImpl::nextNamedItemInternal( const DOMString &name ) const{ NodeImpl *retval = getNamedFormItem( idsDone ? ATTR_NAME : ATTR_ID, name, ++currentPos, true ); if ( retval ) return retval; if ( idsDone ) // we're done return 0; // After doing all ATTR_ID, do ATTR_NAME idsDone = true; return getNamedItem(base->firstChild(), ATTR_NAME, name, true);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -