]>
Commit | Line | Data |
---|---|---|
a90939db JF |
1 | /* |
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. | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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. | |
21 | * | |
22 | */ | |
23 | ||
24 | #ifndef HTMLSelectElement_h | |
25 | #define HTMLSelectElement_h | |
26 | ||
27 | #include "Event.h" | |
28 | #include "HTMLCollection.h" | |
29 | #include "HTMLFormControlElement.h" | |
30 | #include <wtf/Vector.h> | |
31 | ||
32 | namespace WebCore { | |
33 | ||
34 | class HTMLOptionElement; | |
35 | class HTMLOptionsCollection; | |
36 | class KeyboardEvent; | |
37 | ||
38 | class HTMLSelectElement : public HTMLFormControlElementWithState { | |
39 | public: | |
40 | HTMLSelectElement(const QualifiedName&, Document*, HTMLFormElement* = 0); | |
41 | ||
42 | virtual int tagPriority() const { return 6; } | |
43 | virtual bool checkDTD(const Node* newChild); | |
44 | ||
45 | virtual const AtomicString& type() const; | |
46 | ||
47 | virtual bool isKeyboardFocusable(KeyboardEvent*) const; | |
48 | virtual bool isMouseFocusable() const; | |
49 | virtual bool canSelectAll() const; | |
50 | virtual void selectAll(); | |
51 | ||
52 | virtual void recalcStyle(StyleChange); | |
53 | ||
54 | virtual void dispatchFocusEvent(); | |
55 | virtual void dispatchBlurEvent(); | |
56 | ||
57 | virtual bool canStartSelection() const { return false; } | |
58 | ||
59 | int selectedIndex() const; | |
60 | void setSelectedIndex(int index, bool deselect = true, bool fireOnChange = false); | |
61 | int lastSelectedListIndex() const; | |
62 | ||
63 | virtual bool isEnumeratable() const { return true; } | |
64 | ||
65 | unsigned length() const; | |
66 | ||
67 | int minWidth() const { return m_minwidth; } | |
68 | ||
69 | int size() const { return m_size; } | |
70 | ||
71 | bool multiple() const { return m_multiple; } | |
72 | ||
73 | void add(HTMLElement* element, HTMLElement* before, ExceptionCode&); | |
74 | void remove(int index); | |
75 | ||
76 | String value(); | |
77 | void setValue(const String&); | |
78 | ||
79 | PassRefPtr<HTMLOptionsCollection> options(); | |
80 | ||
81 | virtual bool saveState(String& value) const; | |
82 | virtual void restoreState(const String&); | |
83 | ||
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); | |
90 | ||
91 | virtual void parseMappedAttribute(MappedAttribute*); | |
92 | ||
93 | virtual RenderObject* createRenderer(RenderArena*, RenderStyle *); | |
94 | virtual bool appendFormData(FormDataList&, bool); | |
95 | ||
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; | |
100 | ||
101 | void setRecalcListItems(); | |
102 | ||
103 | const Vector<HTMLElement*>& listItems() const | |
104 | { | |
105 | if (m_recalcListItems) | |
106 | recalcListItems(); | |
107 | else | |
108 | checkListItems(); | |
109 | return m_listItems; | |
110 | } | |
111 | virtual void reset(); | |
112 | ||
113 | virtual void defaultEventHandler(Event*); | |
114 | virtual void accessKeyAction(bool sendToAnyElement); | |
115 | void accessKeySetSelectedIndex(int); | |
116 | ||
117 | void setMultiple(bool); | |
118 | ||
119 | void setSize(int); | |
120 | ||
121 | void setOption(unsigned index, HTMLOptionElement*, ExceptionCode&); | |
122 | void setLength(unsigned, ExceptionCode&); | |
123 | ||
124 | Node* namedItem(const AtomicString& name); | |
125 | Node* item(unsigned index); | |
126 | ||
127 | HTMLCollection::CollectionInfo* collectionInfo() { return &m_collectionInfo; } | |
128 | ||
129 | void setActiveSelectionAnchorIndex(int index); | |
130 | void setActiveSelectionEndIndex(int index) { m_activeSelectionEndIndex = index; } | |
131 | void updateListBoxSelection(bool deselectOtherOptions); | |
132 | void listBoxOnChange(); | |
133 | void menuListOnChange(); | |
134 | ||
135 | int activeSelectionStartListIndex() const; | |
136 | int activeSelectionEndListIndex() const; | |
137 | ||
138 | void scrollToSelection(); | |
139 | ||
140 | virtual bool willRespondToMouseClickEvents(); | |
141 | ||
142 | private: | |
143 | void recalcListItems(bool updateSelectedStates = true) const; | |
144 | void checkListItems() const; | |
145 | ||
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(); | |
154 | ||
155 | mutable Vector<HTMLElement*> m_listItems; | |
156 | Vector<bool> m_cachedStateForActiveSelection; | |
157 | Vector<bool> m_lastOnChangeSelection; | |
158 | int m_minwidth; | |
159 | int m_size; | |
160 | bool m_multiple; | |
161 | mutable bool m_recalcListItems; | |
162 | mutable int m_lastOnChangeIndex; | |
163 | ||
164 | int m_activeSelectionAnchorIndex; | |
165 | int m_activeSelectionEndIndex; | |
166 | bool m_activeSelectionState; | |
167 | ||
168 | // Instance variables for type-ahead find | |
169 | UChar m_repeatingChar; | |
170 | DOMTimeStamp m_lastCharTime; | |
171 | String m_typedString; | |
172 | ||
173 | HTMLCollection::CollectionInfo m_collectionInfo; | |
174 | }; | |
175 | ||
176 | #ifdef NDEBUG | |
177 | ||
178 | inline void HTMLSelectElement::checkListItems() const | |
179 | { | |
180 | } | |
181 | ||
182 | #endif | |
183 | ||
184 | } // namespace | |
185 | ||
186 | #endif |