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, 2010 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 HTMLInputElement_h
25 #define HTMLInputElement_h
27 #include "HTMLFormControlElement.h"
28 #include "InputElement.h"
33 class HTMLDataListElement;
34 class HTMLOptionElement;
38 class HTMLInputElement : public HTMLTextFormControlElement, public InputElement {
40 static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
41 virtual ~HTMLInputElement();
43 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange);
45 virtual InputElement* toInputElement() { return this; }
47 bool autoComplete() const;
50 bool typeMismatch() const;
51 // valueMissing() ignores the specified string value for CHECKBOX and RADIO.
52 bool valueMissing(const String&) const;
53 bool patternMismatch(const String&) const;
54 bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
55 bool rangeUnderflow(const String&) const;
56 bool rangeOverflow(const String&) const;
57 // Returns the minimum value for type=date, number, or range. Don't call this for other types.
58 double minimum() const;
59 // Returns the maximum value for type=date, number, or range. Don't call this for other types.
60 // This always returns a value which is >= minimum().
61 double maximum() const;
62 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer.
63 // Returns false if there is no "allowed value step."
64 bool getAllowedValueStep(double*) const;
65 bool getAllowedValueStepWithDecimalPlaces(double*, unsigned*) const;
67 bool stepMismatch(const String&) const;
68 String minimumString() const;
69 String maximumString() const;
70 String stepBaseString() const;
71 String stepString() const;
72 String typeMismatchText() const;
73 String valueMissingText() const;
75 // Implementations of HTMLInputElement::stepUp() and stepDown().
76 void stepUp(int, ExceptionCode&);
77 void stepDown(int, ExceptionCode&);
78 void stepUp(ExceptionCode& ec) { stepUp(1, ec); }
79 void stepDown(ExceptionCode& ec) { stepDown(1, ec); }
80 // stepUp()/stepDown() for user-interaction.
81 void stepUpFromRenderer(int);
83 bool isTextButton() const;
85 virtual bool isRadioButton() const;
86 virtual bool isTextField() const;
87 virtual bool isSearchField() const;
88 virtual bool isInputTypeHidden() const;
89 virtual bool isPasswordField() const;
90 virtual bool isCheckbox() const;
92 // FIXME: It's highly likely that any call site calling this function should instead
93 // be using a different one. Many input elements behave like text fields, and in addition
94 // any unknown input type is treated as text. Consider, for example, isTextField or
95 // isTextField && !isPasswordField.
98 bool isEmailField() const;
99 bool isFileUpload() const;
100 bool isImageButton() const;
101 bool isNumberField() const;
102 bool isSubmitButton() const;
103 bool isTelephoneField() const;
104 bool isURLField() const;
106 #if ENABLE(INPUT_SPEECH)
107 virtual bool isSpeechEnabled() const;
110 bool checked() const { return m_isChecked; }
111 void setChecked(bool, bool sendChangeEvent = false);
113 // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state.
114 bool indeterminate() const { return m_isIndeterminate; }
115 void setIndeterminate(bool);
117 virtual int size() const;
119 void setType(const String&);
121 virtual String value() const;
122 virtual void setValue(const String&, bool sendChangeEvent = false);
123 virtual void setValueForUser(const String&);
124 // Checks if the specified string would be a valid value.
125 // We should not call this for types with no string value such as CHECKBOX and RADIO.
126 bool isValidValue(const String&) const;
128 virtual const String& suggestedValue() const;
129 void setSuggestedValue(const String&);
131 double valueAsDate() const;
132 void setValueAsDate(double, ExceptionCode&);
134 double valueAsNumber() const;
135 void setValueAsNumber(double, ExceptionCode&);
137 virtual String placeholder() const;
138 virtual void setPlaceholder(const String&);
140 String valueWithDefault() const;
142 virtual void setValueFromRenderer(const String&);
143 void setFileListFromRenderer(const Vector<String>&);
145 bool canHaveSelection() const;
146 virtual void select() { HTMLTextFormControlElement::select(); }
148 virtual bool rendererIsNeeded(RenderStyle*);
149 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
150 virtual void detach();
152 // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making
153 // it private virtual in all classes and expose a public method in HTMLFormControlElement to call
154 // the private virtual method.
155 virtual bool isActivatedSubmit() const;
156 virtual void setActivatedSubmit(bool flag);
158 String altText() const;
160 int maxResults() const { return m_maxResults; }
162 String defaultValue() const;
163 void setDefaultValue(const String&);
165 void setDefaultName(const AtomicString&);
167 String accept() const;
170 void setSize(unsigned);
174 virtual int maxLength() const;
175 void setMaxLength(int, ExceptionCode&);
177 bool multiple() const;
179 virtual bool isAutofilled() const { return m_isAutofilled; }
180 void setAutofilled(bool = true);
184 void addSearchResult();
188 HTMLElement* list() const;
189 HTMLOptionElement* selectedOption() const;
193 void setWapInputFormat(String& mask);
196 // These functions are public so they can be used in InputType classes.
197 // Otherwise, they would be private.
198 CheckedRadioButtons& checkedRadioButtons() const;
199 void handleBeforeTextInsertedEvent(Event*);
200 void updateCheckedRadioButtons();
202 bool lastChangeWasUserEdit() const;
205 HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
207 virtual void defaultEventHandler(Event*);
210 enum AutoCompleteSetting { Uninitialized, On, Off };
212 virtual void willMoveToNewOwnerDocument();
213 virtual void didMoveToNewOwnerDocument();
215 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
216 virtual bool isMouseFocusable() const;
217 virtual bool isEnumeratable() const;
218 virtual void updateFocusAppearance(bool restorePreviousSelection);
219 virtual void aboutToUnload();
220 virtual bool shouldUseInputMethod() const;
222 virtual const AtomicString& formControlName() const;
224 // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
225 virtual bool isChecked() const;
226 virtual bool isIndeterminate() const { return indeterminate(); }
228 virtual bool isTextFormControl() const { return isTextField(); }
230 virtual bool hasSpinButton() const;
231 virtual bool canTriggerImplicitSubmission() const { return isTextField(); }
233 virtual const AtomicString& formControlType() const;
235 virtual bool searchEventsShouldBeDispatched() const;
237 virtual bool saveFormControlState(String& value) const;
238 virtual void restoreFormControlState(const String&);
240 virtual bool canStartSelection() const;
242 virtual void accessKeyAction(bool sendToAnyElement);
244 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
245 virtual void parseMappedAttribute(Attribute*);
246 virtual void finishParsingChildren();
248 virtual void copyNonAttributeProperties(const Element* source);
250 virtual void attach();
252 virtual bool appendFormData(FormDataList&, bool);
254 virtual bool isSuccessfulSubmitButton() const;
256 virtual void reset();
258 virtual void* preDispatchEventHandler(Event*);
259 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
261 virtual bool isURLAttribute(Attribute*) const;
263 virtual void cacheSelection(int start, int end);
265 virtual String visibleValue() const;
266 virtual String convertFromVisibleValue(const String&) const;
267 virtual bool isAcceptableValue(const String&) const;
268 virtual String sanitizeValue(const String&) const;
269 virtual bool hasUnacceptableValue() const;
271 virtual bool isInRange() const;
272 virtual bool isOutOfRange() const;
274 virtual void documentDidBecomeActive();
276 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
278 bool needsActivationCallback();
279 void registerForActivationCallbackIfNeeded();
280 void unregisterForActivationCallbackIfNeeded();
282 virtual bool supportsMaxLength() const { return isTextType(); }
283 bool isTextType() const;
285 virtual bool supportsPlaceholder() const;
286 virtual bool isEmptyValue() const { return value().isEmpty(); }
287 virtual bool isEmptySuggestedValue() const { return suggestedValue().isEmpty(); }
288 virtual void handleFocusEvent();
289 virtual void handleBlurEvent();
290 virtual int cachedSelectionStart() const { return m_data.cachedSelectionStart(); }
291 virtual int cachedSelectionEnd() const { return m_data.cachedSelectionEnd(); }
293 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
294 virtual bool isRequiredFormControl() const;
295 virtual bool recalcWillValidate() const;
299 // Helper for stepUp()/stepDown(). Adds step value * count to the current value.
300 void applyStep(double count, ExceptionCode&);
303 HTMLDataListElement* dataList() const;
307 virtual InputElementData data() const { return m_data; }
310 InputElementData m_data;
312 bool m_isChecked : 1;
313 bool m_reflectsCheckedAttribute : 1;
314 bool m_isIndeterminate : 1;
316 bool m_isActivatedSubmit : 1;
317 unsigned m_autocomplete : 2; // AutoCompleteSetting
318 bool m_isAutofilled : 1;
320 bool m_hasNonEmptyList : 1;
322 bool m_stateRestored : 1;
323 bool m_parsingInProgress : 1;
324 OwnPtr<InputType> m_inputType;