#ifndef HTMLCollectionImpl_H
#define HTMLCollectionImpl_H
#include "Shared.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
namespace WebCore {
class AtomicString;
class AtomicStringImpl;
class Node;
class String;
template <typename T> class DeprecatedValueList;
class HTMLCollection : public Shared<HTMLCollection>
{
public:
enum Type {
DocImages = 0, DocApplets, DocEmbeds, DocObjects, DocForms, DocLinks, DocAnchors, DocScripts, TableRows, TableTBodies, TSectionRows, TRCells, SelectOptions,
MapAreas,
DocAll, NodeChildren, WindowNamedItems,
DocumentNamedItems
};
enum {
UnnamedCollectionTypes = NodeChildren + 1,
CollectionTypes = DocumentNamedItems + 1
};
HTMLCollection(Node *_base, HTMLCollection::Type _type);
virtual ~HTMLCollection();
unsigned length() const;
virtual Node *item(unsigned index) const;
virtual Node *firstItem() const;
virtual Node *nextItem() const;
virtual Node *namedItem(const String &name, bool caseSensitive = true) const;
virtual Node *nextNamedItem(const String &name) const;
DeprecatedValueList< RefPtr<Node> > namedItems(const AtomicString &name) const;
Node *base() { return m_base.get(); }
struct CollectionInfo {
CollectionInfo();
~CollectionInfo();
void reset();
unsigned int version;
Node *current;
unsigned int position;
unsigned int length;
int elementsArrayPosition;
HashMap<AtomicStringImpl*, Vector<Node*>*> idCache;
HashMap<AtomicStringImpl*, Vector<Node*>*> nameCache;
bool haslength;
bool hasNameCache;
};
protected:
virtual void updateNameCache() const;
virtual Node *traverseNextItem(Node *start) const;
bool checkForNameMatch(Node *node, bool checkName, const String &name, bool caseSensitive) const;
virtual unsigned calcLength() const;
virtual void resetCollectionInfo() const;
RefPtr<Node> m_base;
Type type;
mutable CollectionInfo *info;
mutable bool idsDone;
mutable bool m_ownsInfo;
};
}
#endif