#include "config.h"
#include "Attribute.h"
#include "Attr.h"
#include "Element.h"
#include <wtf/HashMap.h>
namespace WebCore {
typedef HashMap<Attribute*, Attr*> AttributeAttrMap;
static AttributeAttrMap& attributeAttrMap()
{
DEFINE_STATIC_LOCAL(AttributeAttrMap, map, ());
return map;
}
PassRefPtr<Attribute> Attribute::clone() const
{
return adoptRef(new Attribute(m_name, m_value, m_isMappedAttribute, m_styleDecl.get()));
}
Attr* Attribute::attr() const
{
if (m_hasAttr) {
ASSERT(attributeAttrMap().contains(const_cast<Attribute*>(this)));
return attributeAttrMap().get(const_cast<Attribute*>(this));
}
ASSERT(!attributeAttrMap().contains(const_cast<Attribute*>(this)));
return 0;
}
PassRefPtr<Attr> Attribute::createAttrIfNeeded(Element* e)
{
RefPtr<Attr> r;
if (m_hasAttr) {
ASSERT(attributeAttrMap().contains(this));
r = attributeAttrMap().get(this);
} else {
ASSERT(!attributeAttrMap().contains(this));
r = Attr::create(e, e->document(), this); ASSERT(attributeAttrMap().contains(this));
}
return r.release();
}
void Attribute::bindAttr(Attr* attr)
{
ASSERT(!m_hasAttr);
ASSERT(!attributeAttrMap().contains(this));
attributeAttrMap().set(this, attr);
m_hasAttr = true;
}
void Attribute::unbindAttr(Attr* attr)
{
UNUSED_PARAM(attr);
ASSERT(m_hasAttr);
ASSERT(attributeAttrMap().contains(this));
ASSERT(attributeAttrMap().get(this) == attr);
attributeAttrMap().remove(this);
m_hasAttr = false;
}
}