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 "HTMLFormControlElement.h"
30 #include <wtf/Vector.h>
34 class HTMLOptionElement
;
35 class HTMLOptionsCollection
;
38 class HTMLSelectElement
: public HTMLFormControlElementWithState
{
40 HTMLSelectElement(const QualifiedName
&, Document
*, HTMLFormElement
* = 0);
42 virtual int tagPriority() const { return 6; }
43 virtual bool checkDTD(const Node
* newChild
);
45 virtual const AtomicString
& type() const;
47 virtual bool isKeyboardFocusable(KeyboardEvent
*) const;
48 virtual bool isMouseFocusable() const;
49 virtual bool canSelectAll() const;
50 virtual void selectAll();
52 virtual void recalcStyle(StyleChange
);
54 virtual void dispatchFocusEvent();
55 virtual void dispatchBlurEvent();
57 virtual bool canStartSelection() const { return false; }
59 int selectedIndex() const;
60 void setSelectedIndex(int index
, bool deselect
= true, bool fireOnChange
= false);
61 int lastSelectedListIndex() const;
63 virtual bool isEnumeratable() const { return true; }
65 unsigned length() const;
67 int minWidth() const { return m_minwidth
; }
69 int size() const { return m_size
; }
71 bool multiple() const { return m_multiple
; }
73 void add(HTMLElement
* element
, HTMLElement
* before
, ExceptionCode
&);
74 void remove(int index
);
77 void setValue(const String
&);
79 PassRefPtr
<HTMLOptionsCollection
> options();
81 virtual bool saveState(String
& value
) const;
82 virtual void restoreState(const String
&);
84 virtual bool insertBefore(PassRefPtr
<Node
> newChild
, Node
* refChild
, ExceptionCode
&, bool shouldLazyAttach
= false);
85 virtual bool replaceChild(PassRefPtr
<Node
> newChild
, Node
* oldChild
, ExceptionCode
&, bool shouldLazyAttach
= false);
86 virtual bool removeChild(Node
* child
, ExceptionCode
&);
87 virtual bool appendChild(PassRefPtr
<Node
> newChild
, ExceptionCode
&, bool shouldLazyAttach
= false);
88 virtual bool removeChildren();
89 virtual void childrenChanged(bool changedByParser
= false, Node
* beforeChange
= 0, Node
* afterChange
= 0, int childCountDelta
= 0);
91 virtual void parseMappedAttribute(MappedAttribute
*);
93 virtual RenderObject
* createRenderer(RenderArena
*, RenderStyle
*);
94 virtual bool appendFormData(FormDataList
&, bool);
96 // get the actual listbox index of the optionIndexth option
97 int optionToListIndex(int optionIndex
) const;
98 // reverse of optionToListIndex - get optionIndex from listboxIndex
99 int listToOptionIndex(int listIndex
) const;
101 void setRecalcListItems();
103 const Vector
<HTMLElement
*>& listItems() const
105 if (m_recalcListItems
)
111 virtual void reset();
113 virtual void defaultEventHandler(Event
*);
114 virtual void accessKeyAction(bool sendToAnyElement
);
115 void accessKeySetSelectedIndex(int);
117 void setMultiple(bool);
121 void setOption(unsigned index
, HTMLOptionElement
*, ExceptionCode
&);
122 void setLength(unsigned, ExceptionCode
&);
124 Node
* namedItem(const AtomicString
& name
);
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();
140 virtual bool willRespondToMouseClickEvents();
143 void recalcListItems(bool updateSelectedStates
= true) const;
144 void checkListItems() const;
146 void deselectItems(HTMLOptionElement
* excludeElement
= 0);
147 bool usesMenuList() const { return !m_multiple
; }
148 int nextSelectableListIndex(int startIndex
);
149 int previousSelectableListIndex(int startIndex
);
150 void menuListDefaultEventHandler(Event
*);
151 void listBoxDefaultEventHandler(Event
*);
152 void typeAheadFind(KeyboardEvent
*);
153 void saveLastSelection();
155 mutable Vector
<HTMLElement
*> m_listItems
;
156 Vector
<bool> m_cachedStateForActiveSelection
;
157 Vector
<bool> m_lastOnChangeSelection
;
161 mutable bool m_recalcListItems
;
162 mutable int m_lastOnChangeIndex
;
164 int m_activeSelectionAnchorIndex
;
165 int m_activeSelectionEndIndex
;
166 bool m_activeSelectionState
;
168 // Instance variables for type-ahead find
169 UChar m_repeatingChar
;
170 DOMTimeStamp m_lastCharTime
;
171 String m_typedString
;
173 HTMLCollection::CollectionInfo m_collectionInfo
;
178 inline void HTMLSelectElement::checkListItems() const