2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef HTMLSelectElement_h
25 #define HTMLSelectElement_h
28 #include "HTMLCollection.h"
29 #include "HTMLGenericFormElement.h"
30 #include <wtf/Vector.h>
34 class HTMLOptionElement;
35 class HTMLOptionsCollection;
38 class HTMLSelectElement : public HTMLFormControlElementWithState {
40 HTMLSelectElement(Document*, HTMLFormElement* = 0);
41 HTMLSelectElement(const QualifiedName& tagName, Document*, HTMLFormElement* = 0);
43 virtual int tagPriority() const { return 6; }
44 virtual bool checkDTD(const Node* newChild);
46 virtual const AtomicString& type() const;
48 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
49 virtual bool isMouseFocusable() const;
50 virtual bool canSelectAll() const;
51 virtual void selectAll();
53 virtual void recalcStyle(StyleChange);
55 virtual void dispatchFocusEvent();
56 virtual void dispatchBlurEvent();
58 virtual bool canStartSelection() const { return false; }
60 int selectedIndex() const;
61 void setSelectedIndex(int index, bool deselect = true, bool fireOnChange = false);
62 int lastSelectedListIndex() const;
64 virtual bool isEnumeratable() const { return true; }
66 unsigned length() const;
68 int minWidth() const { return m_minwidth; }
70 int size() const { return m_size; }
72 bool multiple() const { return m_multiple; }
74 void add(HTMLElement* element, HTMLElement* before, ExceptionCode&);
75 void remove(int index);
78 void setValue(const String&);
80 PassRefPtr<HTMLOptionsCollection> options();
82 virtual bool saveState(String& value) const;
83 virtual void restoreState(const String&);
85 virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&);
86 virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&);
87 virtual bool removeChild(Node* child, ExceptionCode&);
88 virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&);
89 virtual bool removeChildren();
90 virtual void childrenChanged();
92 virtual void parseMappedAttribute(MappedAttribute*);
94 virtual RenderObject* createRenderer(RenderArena*, RenderStyle *);
95 virtual bool appendFormData(FormDataList&, bool);
97 // get the actual listbox index of the optionIndexth option
98 int optionToListIndex(int optionIndex) const;
99 // reverse of optionToListIndex - get optionIndex from listboxIndex
100 int listToOptionIndex(int listIndex) const;
102 void setRecalcListItems();
104 const Vector<HTMLElement*>& listItems() const
106 if (m_recalcListItems)
112 virtual void reset();
114 virtual void defaultEventHandler(Event*);
115 virtual void accessKeyAction(bool sendToAnyElement);
117 void setMultiple(bool);
121 void setOption(unsigned index, HTMLOptionElement*, ExceptionCode&);
122 void setLength(unsigned, ExceptionCode&);
124 Node* namedItem(const String& name, bool caseSensitive = true);
125 Node* item(unsigned index);
127 HTMLCollection::CollectionInfo* collectionInfo() { return &m_collectionInfo; }
129 void setActiveSelectionAnchorIndex(int index);
130 void setActiveSelectionEndIndex(int index) { m_activeSelectionEndIndex = index; }
131 void updateListBoxSelection(bool deselectOtherOptions);
132 void listBoxOnChange();
133 void menuListOnChange();
135 int activeSelectionStartListIndex() const;
136 int activeSelectionEndListIndex() const;
138 void scrollToSelection();
141 void recalcListItems(bool updateSelectedStates = true) const;
142 void checkListItems() const;
144 void deselectItems(HTMLOptionElement* excludeElement = 0);
145 bool usesMenuList() const { return !m_multiple && m_size <= 1; }
146 int nextSelectableListIndex(int startIndex);
147 int previousSelectableListIndex(int startIndex);
148 void menuListDefaultEventHandler(Event*);
149 void listBoxDefaultEventHandler(Event*);
150 void typeAheadFind(KeyboardEvent*);
151 void saveLastSelection();
153 mutable Vector<HTMLElement*> m_listItems;
154 Vector<bool> m_cachedStateForActiveSelection;
155 Vector<bool> m_lastOnChangeSelection;
159 mutable bool m_recalcListItems;
160 mutable int m_lastOnChangeIndex;
162 int m_activeSelectionAnchorIndex;
163 int m_activeSelectionEndIndex;
164 bool m_activeSelectionState;
166 // Instance variables for type-ahead find
167 UChar m_repeatingChar;
168 DOMTimeStamp m_lastCharTime;
169 String m_typedString;
171 HTMLCollection::CollectionInfo m_collectionInfo;
176 inline void HTMLSelectElement::checkListItems() const