#ifndef ShadowRootRareData_h
#define ShadowRootRareData_h
#include "core/dom/shadow/InsertionPoint.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
namespace WebCore {
class ShadowRootRareData {
public:
ShadowRootRareData()
: m_descendantShadowElementCount(0)
, m_descendantContentElementCount(0)
, m_childShadowRootCount(0)
{
}
HTMLShadowElement* shadowInsertionPointOfYoungerShadowRoot() const { return m_shadowInsertionPointOfYoungerShadowRoot.get(); }
void setShadowInsertionPointOfYoungerShadowRoot(PassRefPtr<HTMLShadowElement> shadowInsertionPoint) { m_shadowInsertionPointOfYoungerShadowRoot = shadowInsertionPoint; }
void didAddInsertionPoint(InsertionPoint*);
void didRemoveInsertionPoint(InsertionPoint*);
bool containsShadowElements() const { return m_descendantShadowElementCount; }
bool containsContentElements() const { return m_descendantContentElementCount; }
bool containsShadowRoots() const { return m_childShadowRootCount; }
unsigned descendantShadowElementCount() const { return m_descendantShadowElementCount; }
void didAddChildShadowRoot() { ++m_childShadowRootCount; }
void didRemoveChildShadowRoot() { ASSERT(m_childShadowRootCount > 0); --m_childShadowRootCount; }
unsigned childShadowRootCount() const { return m_childShadowRootCount; }
const Vector<RefPtr<InsertionPoint> >& descendantInsertionPoints() { return m_descendantInsertionPoints; }
void setDescendantInsertionPoints(Vector<RefPtr<InsertionPoint> >& list) { m_descendantInsertionPoints.swap(list); }
void clearDescendantInsertionPoints() { m_descendantInsertionPoints.clear(); }
StyleSheetList* styleSheets() { return m_styleSheetList.get(); }
void setStyleSheets(PassRefPtrWillBeRawPtr<StyleSheetList> styleSheetList) { m_styleSheetList = styleSheetList; }
private:
RefPtr<HTMLShadowElement> m_shadowInsertionPointOfYoungerShadowRoot;
unsigned m_descendantShadowElementCount;
unsigned m_descendantContentElementCount;
unsigned m_childShadowRootCount;
Vector<RefPtr<InsertionPoint> > m_descendantInsertionPoints;
RefPtrWillBePersistent<StyleSheetList> m_styleSheetList;
};
inline void ShadowRootRareData::didAddInsertionPoint(InsertionPoint* point)
{
ASSERT(point);
if (isHTMLShadowElement(*point))
++m_descendantShadowElementCount;
else if (isHTMLContentElement(*point))
++m_descendantContentElementCount;
else
ASSERT_NOT_REACHED();
}
inline void ShadowRootRareData::didRemoveInsertionPoint(InsertionPoint* point)
{
ASSERT(point);
if (isHTMLShadowElement(*point))
--m_descendantShadowElementCount;
else if (isHTMLContentElement(*point))
--m_descendantContentElementCount;
else
ASSERT_NOT_REACHED();
ASSERT(m_descendantContentElementCount >= 0);
ASSERT(m_descendantShadowElementCount >= 0);
}
}
#endif