Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'HTMLCollectionImpl (./kdelibs/khtml/html/html_miscimpl.h:52)
class HTMLCollectionImpl : public DomShared
{
public:
enum Type {
// from HTMLDocument
DOC_IMAGES, // all IMG elements in the document
DOC_APPLETS, // all OBJECT and APPLET elements
DOC_FORMS, // all FORMS
DOC_LINKS, // all A _and_ AREA elements with a value for href
DOC_ANCHORS, // all A elements with a value for name
// from HTMLTable, HTMLTableSection, HTMLTableRow
TABLE_ROWS, // all rows in this table or tablesection
TABLE_TBODIES, // all TBODY elements in this table
TSECTION_ROWS, // all rows elements in this table section
TR_CELLS, // all CELLS in this row
// from FORM
FORM_ELEMENTS,
// from SELECT
SELECT_OPTIONS,
// from HTMLMap
MAP_AREAS
};
HTMLCollectionImpl(NodeImpl *_base, int _tagId);
~HTMLCollectionImpl();
unsigned long length() const;
NodeImpl *item ( unsigned long index ) const;
NodeImpl *namedItem ( const DOMString &name ) const;
protected:
unsigned long calcLength(NodeImpl *current) const;
NodeImpl *getItem(NodeImpl *current, int index, int &pos) const;
NodeImpl *getNamedItem( NodeImpl *current, int attr_id,
const DOMString &name ) const;
// the base node, the collection refers to
NodeImpl *base;
// The collection list the following elements
int type;
};
}; //namespace
kdelibs'HTMLCollectionImpl::HTMLCollectionImpl() (./kdelibs/khtml/html/html_miscimpl.cpp:56)
HTMLCollectionImpl::HTMLCollectionImpl(NodeImpl *_base, int _type)
{
base = _base;
base->ref();
type = _type;
}
kdelibs'HTMLCollectionImpl::~HTMLCollectionImpl() (./kdelibs/khtml/html/html_miscimpl.cpp:63)
HTMLCollectionImpl::~HTMLCollectionImpl()
{
base->deref();
}
kdelibs'HTMLCollectionImpl::calcLength() (./kdelibs/khtml/html/html_miscimpl.cpp:68)
unsigned long HTMLCollectionImpl::calcLength(NodeImpl *current) const
{
unsigned long len = 0;
while(current)
{
if(!current->isTextNode())
{
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 FORM_ELEMENTS:
switch(e->id())
{
case ID_INPUT:
case ID_BUTTON:
case ID_SELECT:
case ID_TEXTAREA:
case ID_ISINDEX:
//case ID_LABEL: // ### does it really belong here???
len++;
break;
default:
break;
}
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
if(e->id() == ID_A)
if(e->getAttribute(ATTR_NAME) != 0)
len++;
break;
default:
kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl;
}
if(deep && current->firstChild())
len += calcLength(current->firstChild());
}
current = current->nextSibling();
}
return len;
}
// since the collections are to be "live", we have to do the
// calculation every time...
kdelibs'HTMLCollectionImpl::length() (./kdelibs/khtml/html/html_miscimpl.cpp:156)
unsigned long HTMLCollectionImpl::length() const
{
return calcLength(base->firstChild());
}
kdelibs'HTMLCollectionImpl::getItem() (./kdelibs/khtml/html/html_miscimpl.cpp:161)
NodeImpl *HTMLCollectionImpl::getItem(NodeImpl *current, int index, int &len) const
{
while(current)
{
if(!current->isTextNode())
{
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 FORM_ELEMENTS:
switch(e->id())
{
case ID_INPUT:
case ID_BUTTON:
case ID_SELECT:
case ID_TEXTAREA:
case ID_ISINDEX:
//case ID_LABEL: // ### does it really belong here???
len++;
break;
default:
break;
}
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
if(e->id() == ID_A)
if(e->getAttribute(ATTR_NAME) != 0)
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;
}
kdelibs'HTMLCollectionImpl::item() (./kdelibs/khtml/html/html_miscimpl.cpp:249)
NodeImpl *HTMLCollectionImpl::item( unsigned long index ) const
{
int pos = 0;
return getItem(base->firstChild(), index, pos);
}
kdelibs'HTMLCollectionImpl::getNamedItem() (./kdelibs/khtml/html/html_miscimpl.cpp:255)
NodeImpl *HTMLCollectionImpl::getNamedItem( NodeImpl *current, int attr_id,
const DOMString &name ) const
{
while(current)
{
if(!current->isTextNode())
{
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 FORM_ELEMENTS:
switch(e->id())
{
case ID_INPUT:
case ID_BUTTON:
case ID_SELECT:
case ID_TEXTAREA:
case ID_ISINDEX:
//case ID_LABEL: // ### does it really belong here???
check = true;
break;
default:
break;
}
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->id() == ID_A)
if(e->getAttribute(ATTR_NAME) != 0)
check = true;
break;
default:
kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl;
}
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;
}
kdelibs'HTMLCollectionImpl::namedItem() (./kdelibs/khtml/html/html_miscimpl.cpp:355)
NodeImpl *HTMLCollectionImpl::namedItem( const DOMString &name ) const
{
NodeImpl *n;
n = getNamedItem(base->firstChild(), ATTR_ID, name);
if(n) return n;
return getNamedItem(base->firstChild(), ATTR_NAME, name);
}