2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
4 * (C) 1999 Antti Koivisto (koivisto@kde.org)
5 * (C) 2000 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #ifndef HTMLSelectElement_h
27 #define HTMLSelectElement_h
29 #include "CollectionCache.h"
31 #include "HTMLFormControlElement.h"
32 #include "SelectElement.h"
36 class HTMLOptionElement;
37 class HTMLOptionsCollection;
39 class HTMLSelectElement : public HTMLFormControlElementWithState, public SelectElement {
41 static PassRefPtr<HTMLSelectElement> create(const QualifiedName&, Document*, HTMLFormElement*);
43 virtual int selectedIndex() const;
44 virtual void setSelectedIndex(int index, bool deselect = true);
45 virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false, bool allowMultipleSelection = false);
48 bool valueMissing() const;
50 unsigned length() const;
52 virtual int size() const { return m_data.size(); }
53 virtual bool multiple() const { return m_data.multiple(); }
55 void add(HTMLElement*, HTMLElement* beforeElement, ExceptionCode&);
56 void remove(int index);
57 void remove(HTMLOptionElement*);
60 void setValue(const String&);
62 PassRefPtr<HTMLOptionsCollection> options();
64 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
66 void setRecalcListItems();
67 void recalcListItemsIfNeeded();
69 virtual const Vector<Element*>& listItems() const { return m_data.listItems(this); }
71 virtual void accessKeyAction(bool sendToAnyElement);
72 void accessKeySetSelectedIndex(int);
74 void setMultiple(bool);
78 void setOption(unsigned index, HTMLOptionElement*, ExceptionCode&);
79 void setLength(unsigned, ExceptionCode&);
81 Node* namedItem(const AtomicString& name);
82 Node* item(unsigned index);
84 CollectionCache* collectionInfo() { m_collectionInfo.checkConsistency(); return &m_collectionInfo; }
86 void scrollToSelection();
88 void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true);
90 virtual void updateValidity() { setNeedsValidityCheck(); }
92 virtual bool canSelectAll() const;
93 virtual void selectAll();
96 HTMLSelectElement(const QualifiedName&, Document*, HTMLFormElement*);
99 virtual const AtomicString& formControlType() const;
101 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
102 virtual bool isMouseFocusable() const;
104 virtual void dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode);
105 virtual void dispatchBlurEvent(PassRefPtr<Node> newFocusedNode);
107 virtual bool canStartSelection() const { return false; }
109 virtual bool isEnumeratable() const { return true; }
111 virtual bool saveFormControlState(String& value) const;
112 virtual void restoreFormControlState(const String&);
114 virtual void parseMappedAttribute(Attribute*);
116 virtual RenderObject* createRenderer(RenderArena*, RenderStyle *);
117 virtual bool appendFormData(FormDataList&, bool);
119 virtual int optionToListIndex(int optionIndex) const;
120 virtual int listToOptionIndex(int listIndex) const;
122 virtual void reset();
124 virtual void defaultEventHandler(Event*);
126 virtual void setActiveSelectionAnchorIndex(int index);
127 virtual void setActiveSelectionEndIndex(int index);
128 virtual void updateListBoxSelection(bool deselectOtherOptions);
129 virtual void listBoxOnChange();
130 virtual void menuListOnChange();
132 virtual int activeSelectionStartListIndex() const;
133 virtual int activeSelectionEndListIndex() const;
135 void recalcListItems(bool updateSelectedStates = true) const;
137 void deselectItems(HTMLOptionElement* excludeElement = 0);
138 void typeAheadFind(KeyboardEvent*);
139 void saveLastSelection();
141 virtual void insertedIntoTree(bool);
143 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
144 virtual bool isRequiredFormControl() const;
146 bool hasPlaceholderLabelOption() const;
148 SelectElementData m_data;
149 CollectionCache m_collectionInfo;