#ifndef TreeScope_h
#define TreeScope_h
#include "DocumentOrderedMap.h"
#include <wtf/Forward.h>
#include <wtf/text/AtomicString.h>
namespace WebCore {
class ContainerNode;
class DOMSelection;
class Document;
class Element;
class HTMLLabelElement;
class HTMLMapElement;
class LayoutPoint;
class IdTargetObserverRegistry;
class Node;
class TreeScope {
friend class Document;
friend class TreeScopeAdopter;
public:
TreeScope* parentTreeScope() const { return m_parentTreeScope; }
void setParentTreeScope(TreeScope*);
Element* focusedElement();
Element* getElementById(const AtomicString&) const;
const Vector<Element*>* getAllElementsById(const AtomicString&) const;
bool hasElementWithId(AtomicStringImpl* id) const;
bool containsMultipleElementsWithId(const AtomicString& id) const;
void addElementById(const AtomicString& elementId, Element*);
void removeElementById(const AtomicString& elementId, Element*);
Element* getElementByName(const AtomicString&) const;
bool hasElementWithName(AtomicStringImpl*) const;
bool containsMultipleElementsWithName(const AtomicString&) const;
void addElementByName(const AtomicString&, Element*);
void removeElementByName(const AtomicString&, Element*);
Document* documentScope() const { return m_documentScope; }
Node* ancestorInThisScope(Node*) const;
void addImageMap(HTMLMapElement*);
void removeImageMap(HTMLMapElement*);
HTMLMapElement* getImageMap(const String& url) const;
Element* elementFromPoint(int x, int y) const;
bool shouldCacheLabelsByForAttribute() const { return m_labelsByForAttribute; }
void addLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
void removeLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
HTMLLabelElement* labelElementForId(const AtomicString& forAttributeValue);
DOMSelection* getSelection() const;
Element* findAnchor(const String& name);
virtual bool applyAuthorStyles() const;
virtual bool resetStyleInheritance() const;
void adoptIfNeeded(Node*);
ContainerNode* rootNode() const { return m_rootNode; }
IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTargetObserverRegistry.get(); }
static TreeScope* noDocumentInstance()
{
DEFINE_STATIC_LOCAL(TreeScope, instance, ());
return &instance;
}
void guardRef()
{
ASSERT(!deletionHasBegun());
++m_guardRefCount;
}
void guardDeref()
{
ASSERT(!deletionHasBegun());
--m_guardRefCount;
if (!m_guardRefCount && !refCount() && this != noDocumentInstance()) {
beginDeletion();
delete this;
}
}
void removedLastRefToScope();
protected:
TreeScope(ContainerNode*, Document*);
TreeScope(Document*);
virtual ~TreeScope();
void destroyTreeScopeData();
void clearDocumentScope();
void setDocumentScope(Document* document)
{
ASSERT(document);
ASSERT(this != noDocumentInstance());
m_documentScope = document;
}
bool hasGuardRefCount() const { return m_guardRefCount; }
private:
TreeScope();
virtual void dispose() { }
int refCount() const;
#ifndef NDEBUG
bool deletionHasBegun();
void beginDeletion();
#else
bool deletionHasBegun() { return false; }
void beginDeletion() { }
#endif
ContainerNode* m_rootNode;
Document* m_documentScope;
TreeScope* m_parentTreeScope;
int m_guardRefCount;
OwnPtr<DocumentOrderedMap> m_elementsById;
OwnPtr<DocumentOrderedMap> m_elementsByName;
OwnPtr<DocumentOrderedMap> m_imageMapsByName;
OwnPtr<DocumentOrderedMap> m_labelsByForAttribute;
OwnPtr<IdTargetObserverRegistry> m_idTargetObserverRegistry;
mutable RefPtr<DOMSelection> m_selection;
};
inline bool TreeScope::hasElementWithId(AtomicStringImpl* id) const
{
ASSERT(id);
return m_elementsById && m_elementsById->contains(id);
}
inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) const
{
return m_elementsById && m_elementsById->containsMultiple(id.impl());
}
inline bool TreeScope::hasElementWithName(AtomicStringImpl* id) const
{
ASSERT(id);
return m_elementsByName && m_elementsByName->contains(id);
}
inline bool TreeScope::containsMultipleElementsWithName(const AtomicString& name) const
{
return m_elementsByName && m_elementsByName->containsMultiple(name.impl());
}
Node* nodeFromPoint(Document*, int x, int y, LayoutPoint* localPoint = 0);
TreeScope* commonTreeScope(Node*, Node*);
}
#endif // TreeScope_h