darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1 | /* |
eric@webkit.org | 28784e0 | 2010-03-18 19:32:03 +0000 | [diff] [blame] | 2 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 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) |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. |
eric@webkit.org | 30c9445 | 2010-01-23 06:19:10 +0000 | [diff] [blame] | 7 | * Copyright (C) 2010 Google Inc. All rights reserved. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 | * Boston, MA 02110-1301, USA. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 23 | * |
| 24 | */ |
| 25 | |
eseidel | 8eddecf | 2007-01-16 00:49:43 +0000 | [diff] [blame] | 26 | #ifndef HTMLSelectElement_h |
| 27 | #define HTMLSelectElement_h |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 28 | |
tonyg@chromium.org | 8d183cb | 2011-05-10 08:19:52 +0000 | [diff] [blame] | 29 | #include "Event.h" |
tkent@chromium.org | bd75655 | 2012-01-06 08:33:24 +0000 | [diff] [blame] | 30 | #include "HTMLFormControlElementWithState.h" |
kling@webkit.org | fe42004 | 2012-01-07 09:35:21 +0000 | [diff] [blame] | 31 | #include "HTMLOptionsCollection.h" |
tkent@chromium.org | 608cbb0 | 2011-10-11 08:45:38 +0000 | [diff] [blame] | 32 | #include <wtf/Vector.h> |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | class HTMLOptionElement; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 37 | |
tkent@chromium.org | 8ce493b | 2011-10-07 06:05:18 +0000 | [diff] [blame] | 38 | class HTMLSelectElement : public HTMLFormControlElementWithState { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 39 | public: |
darin@apple.com | 877ce5b | 2010-05-28 15:38:58 +0000 | [diff] [blame] | 40 | static PassRefPtr<HTMLSelectElement> create(const QualifiedName&, Document*, HTMLFormElement*); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 41 | |
tkent@chromium.org | 8ce493b | 2011-10-07 06:05:18 +0000 | [diff] [blame] | 42 | int selectedIndex() const; |
darin@apple.com | 92c0a62 | 2011-11-02 02:47:18 +0000 | [diff] [blame] | 43 | void setSelectedIndex(int); |
| 44 | |
| 45 | void optionSelectedByUser(int index, bool dispatchChangeEvent, bool allowMultipleSelection = false); |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 46 | |
commit-queue@webkit.org | a259a13 | 2010-12-09 13:07:15 +0000 | [diff] [blame] | 47 | // For ValidityState |
commit-queue@webkit.org | 0252775 | 2012-05-14 04:22:44 +0000 | [diff] [blame] | 48 | virtual String validationMessage() const OVERRIDE; |
| 49 | virtual bool valueMissing() const OVERRIDE; |
commit-queue@webkit.org | a259a13 | 2010-12-09 13:07:15 +0000 | [diff] [blame] | 50 | |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 51 | unsigned length() const; |
| 52 | |
tkent@chromium.org | 0c74c3e | 2011-10-12 07:14:12 +0000 | [diff] [blame] | 53 | int size() const { return m_size; } |
| 54 | bool multiple() const { return m_multiple; } |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 55 | |
jonlee@apple.com | a30a69a | 2011-10-26 18:36:22 +0000 | [diff] [blame] | 56 | bool usesMenuList() const; |
| 57 | |
darin@apple.com | 7e8868d | 2011-01-01 00:58:22 +0000 | [diff] [blame] | 58 | void add(HTMLElement*, HTMLElement* beforeElement, ExceptionCode&); |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 59 | void remove(int index); |
darin@apple.com | 7e8868d | 2011-01-01 00:58:22 +0000 | [diff] [blame] | 60 | void remove(HTMLOptionElement*); |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 61 | |
commit-queue@webkit.org | 28926bc | 2011-01-28 12:46:50 +0000 | [diff] [blame] | 62 | String value() const; |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 63 | void setValue(const String&); |
| 64 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 65 | PassRefPtr<HTMLOptionsCollection> options(); |
| 66 | PassRefPtr<HTMLCollection> selectedOptions(); |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 67 | |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 68 | void optionElementChildrenChanged(); |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 69 | |
| 70 | void setRecalcListItems(); |
alexis.menard@openbossa.org | 0fcb566 | 2012-06-28 01:05:27 +0000 | [diff] [blame] | 71 | void invalidateSelectedItems(); |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 72 | void updateListItemSelectedStates(); |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 73 | |
tkent@chromium.org | 76e5b12 | 2011-10-13 09:08:18 +0000 | [diff] [blame] | 74 | const Vector<HTMLElement*>& listItems() const; |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 75 | |
commit-queue@webkit.org | 5bc308c | 2011-11-18 21:19:14 +0000 | [diff] [blame] | 76 | virtual void accessKeyAction(bool sendMouseEvents); |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 77 | void accessKeySetSelectedIndex(int); |
| 78 | |
| 79 | void setMultiple(bool); |
| 80 | |
| 81 | void setSize(int); |
| 82 | |
| 83 | void setOption(unsigned index, HTMLOptionElement*, ExceptionCode&); |
| 84 | void setLength(unsigned, ExceptionCode&); |
| 85 | |
| 86 | Node* namedItem(const AtomicString& name); |
| 87 | Node* item(unsigned index); |
| 88 | |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 89 | void scrollToSelection(); |
| 90 | |
abecsi@webkit.org | c44c9f8 | 2011-10-27 13:02:42 +0000 | [diff] [blame] | 91 | void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true); |
abecsi@webkit.org | c44c9f8 | 2011-10-27 13:02:42 +0000 | [diff] [blame] | 92 | |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 93 | bool canSelectAll() const; |
| 94 | void selectAll(); |
tkent@chromium.org | 8ce493b | 2011-10-07 06:05:18 +0000 | [diff] [blame] | 95 | int listToOptionIndex(int listIndex) const; |
| 96 | void listBoxOnChange(); |
| 97 | int optionToListIndex(int optionIndex) const; |
| 98 | int activeSelectionStartListIndex() const; |
| 99 | int activeSelectionEndListIndex() const; |
| 100 | void setActiveSelectionAnchorIndex(int); |
| 101 | void setActiveSelectionEndIndex(int); |
| 102 | void updateListBoxSelection(bool deselectOtherOptions); |
| 103 | |
darin@apple.com | 92c0a62 | 2011-11-02 02:47:18 +0000 | [diff] [blame] | 104 | // For use in the implementation of HTMLOptionElement. |
| 105 | void optionSelectionStateChanged(HTMLOptionElement*, bool optionIsSelected); |
| 106 | |
darin@apple.com | 877ce5b | 2010-05-28 15:38:58 +0000 | [diff] [blame] | 107 | protected: |
| 108 | HTMLSelectElement(const QualifiedName&, Document*, HTMLFormElement*); |
| 109 | |
darin@apple.com | 8bca65c | 2009-05-30 23:27:00 +0000 | [diff] [blame] | 110 | private: |
zimmermann@webkit.org | b75da28 | 2009-05-07 21:43:11 +0000 | [diff] [blame] | 111 | virtual const AtomicString& formControlType() const; |
adele | c157733 | 2006-07-07 02:29:11 +0000 | [diff] [blame] | 112 | |
darin | 2a7db55 | 2006-11-09 02:00:10 +0000 | [diff] [blame] | 113 | virtual bool isKeyboardFocusable(KeyboardEvent*) const; |
adele | c157733 | 2006-07-07 02:29:11 +0000 | [diff] [blame] | 114 | virtual bool isMouseFocusable() const; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 115 | |
hayato@chromium.org | 91ac134 | 2011-08-18 02:41:10 +0000 | [diff] [blame] | 116 | virtual void dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode); |
| 117 | virtual void dispatchBlurEvent(PassRefPtr<Node> newFocusedNode); |
adele | 79c8ed2 | 2007-09-19 18:04:30 +0000 | [diff] [blame] | 118 | |
| 119 | virtual bool canStartSelection() const { return false; } |
aroben | 026ca89 | 2006-10-10 21:57:14 +0000 | [diff] [blame] | 120 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 121 | virtual bool isEnumeratable() const { return true; } |
commit-queue@webkit.org | a3eabcd | 2012-03-16 01:49:05 +0000 | [diff] [blame] | 122 | virtual bool supportLabels() const OVERRIDE { return true; } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 123 | |
tkent@chromium.org | d08b551 | 2012-06-19 06:20:48 +0000 | [diff] [blame] | 124 | virtual FormControlState saveFormControlState() const OVERRIDE; |
| 125 | virtual void restoreFormControlState(const FormControlState&) OVERRIDE; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 126 | |
kling@webkit.org | 260fca8 | 2012-05-16 00:34:16 +0000 | [diff] [blame] | 127 | virtual void parseAttribute(const Attribute&) OVERRIDE; |
kling@webkit.org | 44bc0dd | 2012-02-28 22:21:02 +0000 | [diff] [blame] | 128 | virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 129 | |
morrita@google.com | beaa664 | 2012-02-24 09:59:07 +0000 | [diff] [blame] | 130 | virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const OVERRIDE; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 131 | virtual RenderObject* createRenderer(RenderArena*, RenderStyle *); |
| 132 | virtual bool appendFormData(FormDataList&, bool); |
| 133 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 134 | virtual void reset(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 135 | |
| 136 | virtual void defaultEventHandler(Event*); |
zimmermann@webkit.org | 7c6ec00 | 2009-05-28 17:49:09 +0000 | [diff] [blame] | 137 | |
darin@apple.com | 92c0a62 | 2011-11-02 02:47:18 +0000 | [diff] [blame] | 138 | void dispatchChangeEventForMenuList(); |
antti | 7241719 | 2007-02-22 19:57:49 +0000 | [diff] [blame] | 139 | |
mitz@apple.com | 7a1fd56 | 2007-12-13 00:23:34 +0000 | [diff] [blame] | 140 | void recalcListItems(bool updateSelectedStates = true) const; |
darin@apple.com | c2e05f9 | 2007-12-07 19:44:20 +0000 | [diff] [blame] | 141 | |
adele | ab6a386 | 2006-10-31 22:10:51 +0000 | [diff] [blame] | 142 | void deselectItems(HTMLOptionElement* excludeElement = 0); |
aroben | 4a062e8 | 2006-10-26 18:19:57 +0000 | [diff] [blame] | 143 | void typeAheadFind(KeyboardEvent*); |
adele | 31872c8 | 2007-03-17 07:40:53 +0000 | [diff] [blame] | 144 | void saveLastSelection(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 145 | |
darin@apple.com | 183547b | 2012-05-23 16:56:33 +0000 | [diff] [blame] | 146 | virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; |
ap@webkit.org | 2827d62 | 2009-04-30 16:55:02 +0000 | [diff] [blame] | 147 | |
commit-queue@webkit.org | a259a13 | 2010-12-09 13:07:15 +0000 | [diff] [blame] | 148 | virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } |
| 149 | virtual bool isRequiredFormControl() const; |
| 150 | |
| 151 | bool hasPlaceholderLabelOption() const; |
pkasting@chromium.org | b8a7204 | 2009-07-17 22:37:41 +0000 | [diff] [blame] | 152 | |
darin@apple.com | 92c0a62 | 2011-11-02 02:47:18 +0000 | [diff] [blame] | 153 | enum SelectOptionFlag { |
| 154 | DeselectOtherOptions = 1 << 0, |
| 155 | DispatchChangeEvent = 1 << 1, |
| 156 | UserDriven = 1 << 2, |
| 157 | }; |
| 158 | typedef unsigned SelectOptionFlags; |
| 159 | void selectOption(int optionIndex, SelectOptionFlags = 0); |
| 160 | void deselectItemsWithoutValidation(HTMLElement* elementToExclude = 0); |
kling@webkit.org | 260fca8 | 2012-05-16 00:34:16 +0000 | [diff] [blame] | 161 | void parseMultipleAttribute(const Attribute&); |
tkent@chromium.org | 150660f | 2011-10-10 03:25:36 +0000 | [diff] [blame] | 162 | int lastSelectedListIndex() const; |
| 163 | void updateSelectedState(int listIndex, bool multi, bool shift); |
| 164 | void menuListDefaultEventHandler(Event*); |
| 165 | bool platformHandleKeydownEvent(KeyboardEvent*); |
| 166 | void listBoxDefaultEventHandler(Event*); |
| 167 | void setOptionsChangedOnRenderer(); |
tkent@chromium.org | f5e42c2 | 2012-06-25 01:47:35 +0000 | [diff] [blame] | 168 | size_t searchOptionsForValue(const String&, size_t listIndexStart, size_t listIndexEnd) const; |
tkent@chromium.org | 8ce493b | 2011-10-07 06:05:18 +0000 | [diff] [blame] | 169 | |
tkent@chromium.org | afd1fb0 | 2011-10-10 18:01:09 +0000 | [diff] [blame] | 170 | enum SkipDirection { |
| 171 | SkipBackwards = -1, |
| 172 | SkipForwards = 1 |
| 173 | }; |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 174 | int nextValidIndex(int listIndex, SkipDirection, int skip) const; |
tkent@chromium.org | afd1fb0 | 2011-10-10 18:01:09 +0000 | [diff] [blame] | 175 | int nextSelectableListIndex(int startIndex) const; |
| 176 | int previousSelectableListIndex(int startIndex) const; |
| 177 | int firstSelectableListIndex() const; |
| 178 | int lastSelectableListIndex() const; |
| 179 | int nextSelectableListIndexPageAway(int startIndex, SkipDirection) const; |
| 180 | |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 181 | virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); |
morrita@google.com | c2ca66f | 2012-09-12 16:16:14 +0000 | [diff] [blame] | 182 | virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; } |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 183 | |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 184 | // m_listItems contains HTMLOptionElement, HTMLOptGroupElement, and HTMLHRElement objects. |
| 185 | mutable Vector<HTMLElement*> m_listItems; |
tkent@chromium.org | 0c74c3e | 2011-10-12 07:14:12 +0000 | [diff] [blame] | 186 | Vector<bool> m_lastOnChangeSelection; |
| 187 | Vector<bool> m_cachedStateForActiveSelection; |
| 188 | DOMTimeStamp m_lastCharTime; |
| 189 | String m_typedString; |
| 190 | int m_size; |
| 191 | int m_lastOnChangeIndex; |
| 192 | int m_activeSelectionAnchorIndex; |
| 193 | int m_activeSelectionEndIndex; |
| 194 | UChar m_repeatingChar; |
darin@apple.com | 92c0a62 | 2011-11-02 02:47:18 +0000 | [diff] [blame] | 195 | bool m_isProcessingUserDrivenChange; |
tkent@chromium.org | 0c74c3e | 2011-10-12 07:14:12 +0000 | [diff] [blame] | 196 | bool m_multiple; |
| 197 | bool m_activeSelectionState; |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 198 | mutable bool m_shouldRecalcListItems; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
shinyak@chromium.org | 9327f7a | 2012-08-15 09:51:56 +0000 | [diff] [blame] | 201 | inline bool isHTMLSelectElement(const Node* node) |
| 202 | { |
| 203 | return node->hasTagName(HTMLNames::selectTag); |
| 204 | } |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 205 | |
| 206 | inline HTMLSelectElement* toHTMLSelectElement(Node* node) |
| 207 | { |
shinyak@chromium.org | 9327f7a | 2012-08-15 09:51:56 +0000 | [diff] [blame] | 208 | ASSERT(!node || isHTMLSelectElement(node)); |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 209 | return static_cast<HTMLSelectElement*>(node); |
| 210 | } |
| 211 | |
| 212 | inline const HTMLSelectElement* toHTMLSelectElement(const Node* node) |
| 213 | { |
shinyak@chromium.org | 9327f7a | 2012-08-15 09:51:56 +0000 | [diff] [blame] | 214 | ASSERT(!node || isHTMLSelectElement(node)); |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 215 | return static_cast<const HTMLSelectElement*>(node); |
| 216 | } |
| 217 | |
shinyak@chromium.org | 9327f7a | 2012-08-15 09:51:56 +0000 | [diff] [blame] | 218 | void toHTMLSelectElement(const HTMLSelectElement*); // This overload will catch anyone doing an unnecessary cast. |
darin@apple.com | 318f889 | 2011-10-15 00:30:43 +0000 | [diff] [blame] | 219 | |
darin | 419b2c2 | 2006-07-12 02:55:47 +0000 | [diff] [blame] | 220 | } // namespace |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 221 | |
| 222 | #endif |