initial import
[vuplus_webkit] / Source / WebCore / html / HTMLSelectElement.h
1 /*
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.
8  *
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.
13  *
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.
18  *
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.
23  *
24  */
25
26 #ifndef HTMLSelectElement_h
27 #define HTMLSelectElement_h
28
29 #include "CollectionCache.h"
30 #include "Event.h"
31 #include "HTMLFormControlElement.h"
32 #include "SelectElement.h"
33
34 namespace WebCore {
35
36 class HTMLOptionElement;
37 class HTMLOptionsCollection;
38
39 class HTMLSelectElement : public HTMLFormControlElementWithState, public SelectElement {
40 public:
41     static PassRefPtr<HTMLSelectElement> create(const QualifiedName&, Document*, HTMLFormElement*);
42
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);
46
47     // For ValidityState
48     bool valueMissing() const;
49
50     unsigned length() const;
51
52     virtual int size() const { return m_data.size(); }
53     virtual bool multiple() const { return m_data.multiple(); }
54
55     void add(HTMLElement*, HTMLElement* beforeElement, ExceptionCode&);
56     void remove(int index);
57     void remove(HTMLOptionElement*);
58
59     String value() const;
60     void setValue(const String&);
61
62     PassRefPtr<HTMLOptionsCollection> options();
63
64     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
65
66     void setRecalcListItems();
67     void recalcListItemsIfNeeded();
68
69     virtual const Vector<Element*>& listItems() const { return m_data.listItems(this); }
70
71     virtual void accessKeyAction(bool sendToAnyElement);
72     void accessKeySetSelectedIndex(int);
73
74     void setMultiple(bool);
75
76     void setSize(int);
77
78     void setOption(unsigned index, HTMLOptionElement*, ExceptionCode&);
79     void setLength(unsigned, ExceptionCode&);
80
81     Node* namedItem(const AtomicString& name);
82     Node* item(unsigned index);
83
84     CollectionCache* collectionInfo() { m_collectionInfo.checkConsistency(); return &m_collectionInfo; }
85
86     void scrollToSelection();
87
88     void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true);
89
90     virtual void updateValidity() { setNeedsValidityCheck(); }
91
92     virtual bool canSelectAll() const;
93     virtual void selectAll();
94
95 protected:
96     HTMLSelectElement(const QualifiedName&, Document*, HTMLFormElement*);
97
98 private:
99     virtual const AtomicString& formControlType() const;
100     
101     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
102     virtual bool isMouseFocusable() const;
103
104     virtual void dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode);
105     virtual void dispatchBlurEvent(PassRefPtr<Node> newFocusedNode);
106     
107     virtual bool canStartSelection() const { return false; }
108
109     virtual bool isEnumeratable() const { return true; }
110
111     virtual bool saveFormControlState(String& value) const;
112     virtual void restoreFormControlState(const String&);
113
114     virtual void parseMappedAttribute(Attribute*);
115
116     virtual RenderObject* createRenderer(RenderArena*, RenderStyle *);
117     virtual bool appendFormData(FormDataList&, bool);
118
119     virtual int optionToListIndex(int optionIndex) const;
120     virtual int listToOptionIndex(int listIndex) const;
121
122     virtual void reset();
123
124     virtual void defaultEventHandler(Event*);
125
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();
131     
132     virtual int activeSelectionStartListIndex() const;
133     virtual int activeSelectionEndListIndex() const;
134     
135     void recalcListItems(bool updateSelectedStates = true) const;
136
137     void deselectItems(HTMLOptionElement* excludeElement = 0);
138     void typeAheadFind(KeyboardEvent*);
139     void saveLastSelection();
140
141     virtual void insertedIntoTree(bool);
142
143     virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
144     virtual bool isRequiredFormControl() const;
145
146     bool hasPlaceholderLabelOption() const;
147
148     SelectElementData m_data;
149     CollectionCache m_collectionInfo;
150 };
151
152 } // namespace
153
154 #endif