HTMLOptionsCollection.cpp [plain text]
#include "config.h"
#include "HTMLOptionsCollection.h"
#include "ExceptionCode.h"
#include "HTMLOptionElement.h"
#include "HTMLSelectElement.h"
namespace WebCore {
HTMLOptionsCollection::HTMLOptionsCollection(Node* select)
: HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter)
{
ASSERT(select->hasTagName(HTMLNames::selectTag));
}
PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(Node* select, CollectionType)
{
return adoptRef(new HTMLOptionsCollection(select));
}
void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, ExceptionCode& ec)
{
add(element, length(), ec);
}
void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index, ExceptionCode& ec)
{
HTMLOptionElement* newOption = element.get();
if (!newOption) {
ec = TYPE_MISMATCH_ERR;
return;
}
if (index < -1) {
ec = INDEX_SIZE_ERR;
return;
}
ec = 0;
HTMLSelectElement* select = toHTMLSelectElement(ownerNode());
if (index == -1 || unsigned(index) >= length())
select->add(newOption, 0, ec);
else
select->add(newOption, static_cast<HTMLOptionElement*>(item(index)), ec);
ASSERT(!ec);
}
void HTMLOptionsCollection::remove(int index)
{
toHTMLSelectElement(ownerNode())->remove(index);
}
int HTMLOptionsCollection::selectedIndex() const
{
return toHTMLSelectElement(ownerNode())->selectedIndex();
}
void HTMLOptionsCollection::setSelectedIndex(int index)
{
toHTMLSelectElement(ownerNode())->setSelectedIndex(index);
}
void HTMLOptionsCollection::setLength(unsigned length, ExceptionCode& ec)
{
toHTMLSelectElement(ownerNode())->setLength(length, ec);
}
}