#include "config.h"
#include "NamedNodeMap.h"
#include "Attr.h"
#include "Element.h"
#include "ExceptionCode.h"
namespace WebCore {
using namespace HTMLNames;
void NamedNodeMap::ref()
{
m_element.ref();
}
void NamedNodeMap::deref()
{
m_element.deref();
}
RefPtr<Node> NamedNodeMap::getNamedItem(const AtomicString& name) const
{
return m_element.getAttributeNode(name);
}
RefPtr<Node> NamedNodeMap::getNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName) const
{
return m_element.getAttributeNodeNS(namespaceURI, localName);
}
RefPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionCode& ec)
{
unsigned index = m_element.hasAttributes() ? m_element.findAttributeIndexByName(name, shouldIgnoreAttributeCase(m_element)) : ElementData::attributeNotFound;
if (index == ElementData::attributeNotFound) {
ec = NOT_FOUND_ERR;
return nullptr;
}
return m_element.detachAttribute(index);
}
Vector<AtomicString> NamedNodeMap::supportedPropertyNames()
{
return Vector<AtomicString>();
}
RefPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode& ec)
{
unsigned index = m_element.hasAttributes() ? m_element.findAttributeIndexByName(QualifiedName(nullAtom, localName, namespaceURI)) : ElementData::attributeNotFound;
if (index == ElementData::attributeNotFound) {
ec = NOT_FOUND_ERR;
return nullptr;
}
return m_element.detachAttribute(index);
}
RefPtr<Node> NamedNodeMap::setNamedItem(Node& node, ExceptionCode& ec)
{
if (!is<Attr>(node)) {
ec = HIERARCHY_REQUEST_ERR;
return nullptr;
}
return m_element.setAttributeNode(downcast<Attr>(node), ec);
}
RefPtr<Node> NamedNodeMap::setNamedItemNS(Node& node, ExceptionCode& ec)
{
return setNamedItem(node, ec);
}
RefPtr<Node> NamedNodeMap::item(unsigned index) const
{
if (index >= length())
return 0;
return m_element.ensureAttr(m_element.attributeAt(index).name());
}
unsigned NamedNodeMap::length() const
{
if (!m_element.hasAttributes())
return 0;
return m_element.attributeCount();
}
}