2 * Copyright (C) 2006 Apple Computer, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "HTMLOptionsCollection.h"
24 #include "ExceptionCode.h"
25 #include "HTMLOptionElement.h"
26 #include "HTMLSelectElement.h"
30 HTMLOptionsCollection::HTMLOptionsCollection(PassRefPtr<HTMLSelectElement> select)
31 : HTMLCollection(select.get(), SelectOptions, select->collectionInfo())
35 PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(PassRefPtr<HTMLSelectElement> select)
37 return adoptRef(new HTMLOptionsCollection(select));
40 void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, ExceptionCode &ec)
42 add(element, length(), ec);
45 void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index, ExceptionCode &ec)
47 HTMLOptionElement* newOption = element.get();
50 ec = TYPE_MISMATCH_ERR;
60 HTMLSelectElement* select = static_cast<HTMLSelectElement*>(base());
62 if (index == -1 || unsigned(index) >= length())
63 select->add(newOption, 0, ec);
65 select->add(newOption, static_cast<HTMLOptionElement*>(item(index)), ec);
70 void HTMLOptionsCollection::remove(int index)
72 static_cast<HTMLSelectElement*>(base())->remove(index);
75 int HTMLOptionsCollection::selectedIndex() const
77 return static_cast<HTMLSelectElement*>(base())->selectedIndex();
80 void HTMLOptionsCollection::setSelectedIndex(int index)
82 static_cast<HTMLSelectElement*>(base())->setSelectedIndex(index);
85 void HTMLOptionsCollection::setLength(unsigned length, ExceptionCode& ec)
87 static_cast<HTMLSelectElement*>(base())->setLength(length, ec);