#ifndef HTMLCollection_h
#define HTMLCollection_h
#include <wtf/RefCounted.h>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
namespace WebCore {
class AtomicString;
class AtomicStringImpl;
class Element;
class Node;
class NodeList;
class String;
class HTMLCollection : public RefCounted<HTMLCollection> {
public:
enum Type {
DocImages, DocApplets, DocEmbeds, DocObjects, DocForms, DocLinks, DocAnchors, DocScripts,
DocAll, NodeChildren,
WindowNamedItems,
DocumentNamedItems,
TableTBodies, TSectionRows, TRCells, SelectOptions,
MapAreas,
Other
};
static const Type FirstUnnamedDocumentCachedType = DocImages;
static const unsigned NumUnnamedDocumentCachedTypes = NodeChildren - DocImages + 1;
static const Type FirstNamedDocumentCachedType = WindowNamedItems;
static const unsigned NumNamedDocumentCachedTypes = DocumentNamedItems - WindowNamedItems + 1;
HTMLCollection(PassRefPtr<Node> base, Type);
virtual ~HTMLCollection();
unsigned length() const;
virtual Node* item(unsigned index) const;
virtual Node* nextItem() const;
virtual Node* namedItem(const String& name, bool caseSensitive = true) const;
virtual Node* nextNamedItem(const String& name) const;
Node* firstItem() const;
void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const;
PassRefPtr<NodeList> tags(const String&);
Node* base() const { return m_base.get(); }
Type type() const { return m_type; }
struct CollectionInfo {
CollectionInfo();
CollectionInfo(const CollectionInfo&);
CollectionInfo& operator=(const CollectionInfo& other)
{
CollectionInfo tmp(other);
swap(tmp);
return *this;
}
~CollectionInfo();
void reset();
void swap(CollectionInfo&);
typedef HashMap<AtomicStringImpl*, Vector<Element*>*> NodeCacheMap;
unsigned version;
Element* current;
unsigned position;
unsigned length;
int elementsArrayPosition;
NodeCacheMap idCache;
NodeCacheMap nameCache;
bool hasLength;
bool hasNameCache;
private:
static void copyCacheMap(NodeCacheMap&, const NodeCacheMap&);
};
protected:
HTMLCollection(PassRefPtr<Node> base, Type, CollectionInfo*);
CollectionInfo* info() const { return m_info; }
virtual void resetCollectionInfo() const;
mutable bool m_idsDone;
private:
virtual Element* itemAfter(Element*) const;
virtual unsigned calcLength() const;
virtual void updateNameCache() const;
bool checkForNameMatch(Element*, bool checkName, const String &name, bool caseSensitive) const;
RefPtr<Node> m_base;
Type m_type;
mutable CollectionInfo* m_info;
mutable bool m_ownsInfo;
};
}
#endif