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*);
41 virtual ~HTMLInputElement();
43 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange);
45 bool autoComplete() const;
48 bool typeMismatch() const;
49 // valueMissing() ignores the specified string value for CHECKBOX and RADIO.
50 bool valueMissing(const String&) const;
51 bool patternMismatch(const String&) const;
52 bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
53 bool rangeUnderflow(const String&) const;
54 bool rangeOverflow(const String&) const;
55 // Returns the minimum value for type=date, number, or range. Don't call this for other types.
56 double minimum() const;
57 // Returns the maximum value for type=date, number, or range. Don't call this for other types.
58 // This always returns a value which is >= minimum().
59 double maximum() const;
60 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer.
61 // Returns false if there is no "allowed value step."
62 bool getAllowedValueStep(double*) const;
63 bool getAllowedValueStepWithDecimalPlaces(double*, unsigned*) const;
65 bool stepMismatch(const String&) const;
66 String minimumString() const;
67 String maximumString() const;
68 String stepBaseString() const;
69 String stepString() const;
70 String typeMismatchText() const;
71 String valueMissingText() const;
73 // Implementations of HTMLInputElement::stepUp() and stepDown().
74 void stepUp(int, ExceptionCode&);
75 void stepDown(int, ExceptionCode&);
76 void stepUp(ExceptionCode& ec) { stepUp(1, ec); }
77 void stepDown(ExceptionCode& ec) { stepDown(1, ec); }
78 // stepUp()/stepDown() for user-interaction.
79 void stepUpFromRenderer(int);
81 bool isTextButton() const;
83 virtual bool isRadioButton() const;
84 virtual bool isTextField() const;
85 virtual bool isSearchField() const;
86 virtual bool isInputTypeHidden() const;
87 virtual bool isPasswordField() const;
88 virtual bool isCheckbox() const;
90 // FIXME: It's highly likely that any call site calling this function should instead
91 // be using a different one. Many input elements behave like text fields, and in addition
92 // any unknown input type is treated as text. Consider, for example, isTextField or
93 // isTextField && !isPasswordField.
96 bool isEmailField() const;
97 bool isFileUpload() const;
98 bool isImageButton() const;
99 bool isNumberField() const;
100 bool isSubmitButton() const;
101 bool isTelephoneField() const;
102 bool isURLField() const;
104 #if ENABLE(INPUT_SPEECH)
105 virtual bool isSpeechEnabled() const;
108 bool checked() const { return m_isChecked; }
109 void setChecked(bool, bool sendChangeEvent = false);
111 // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state.
112 bool indeterminate() const { return m_isIndeterminate; }
113 void setIndeterminate(bool);
115 virtual int size() const;
117 void setType(const String&);
119 virtual String value() const;
120 virtual void setValue(const String&, bool sendChangeEvent = false);
121 virtual void setValueForUser(const String&);
122 // Checks if the specified string would be a valid value.
123 // We should not call this for types with no string value such as CHECKBOX and RADIO.
124 bool isValidValue(const String&) const;
126 virtual const String& suggestedValue() const;
127 void setSuggestedValue(const String&);
129 double valueAsDate() const;
130 void setValueAsDate(double, ExceptionCode&);
132 double valueAsNumber() const;
133 void setValueAsNumber(double, ExceptionCode&);
135 virtual String placeholder() const;
136 virtual void setPlaceholder(const String&);
138 String valueWithDefault() const;
140 virtual void setValueFromRenderer(const String&);
141 void setFileListFromRenderer(const Vector<String>&);
143 bool canHaveSelection() const;
144 virtual void select() { HTMLTextFormControlElement::select(); }
146 virtual bool rendererIsNeeded(RenderStyle*);
147 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
148 virtual void detach();
150 // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making
151 // it private virtual in all classes and expose a public method in HTMLFormControlElement to call
152 // the private virtual method.
153 virtual bool isActivatedSubmit() const;
154 virtual void setActivatedSubmit(bool flag);
156 String altText() const;
158 int maxResults() const { return m_maxResults; }
160 String defaultValue() const;
161 void setDefaultValue(const String&);
163 void setDefaultName(const AtomicString&);
165 String accept() const;
168 void setSize(unsigned);
172 virtual int maxLength() const;
173 void setMaxLength(int, ExceptionCode&);
175 bool multiple() const;
177 virtual bool isAutofilled() const { return m_isAutofilled; }
178 void setAutofilled(bool = true);
182 void addSearchResult();
186 HTMLElement* list() const;
187 HTMLOptionElement* selectedOption() const;
191 void setWapInputFormat(String& mask);
194 // These functions are public so they can be used in InputType classes.
195 // Otherwise, they would be private.
196 CheckedRadioButtons& checkedRadioButtons() const;
197 void handleBeforeTextInsertedEvent(Event*);
198 void updateCheckedRadioButtons();
201 HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
203 virtual void defaultEventHandler(Event*);
206 enum AutoCompleteSetting { Uninitialized, On, Off };
208 virtual void willMoveToNewOwnerDocument();
209 virtual void didMoveToNewOwnerDocument();
211 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
212 virtual bool isMouseFocusable() const;
213 virtual bool isEnumeratable() const;
214 virtual bool isResettable() const { return true; }
215 virtual void updateFocusAppearance(bool restorePreviousSelection);
216 virtual void aboutToUnload();
217 virtual bool shouldUseInputMethod() const;
219 virtual const AtomicString& formControlName() const;
221 // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
222 virtual bool isChecked() const;
223 virtual bool isIndeterminate() const { return indeterminate(); }
225 virtual bool isTextFormControl() const { return isTextField(); }
227 virtual bool hasSpinButton() const;
228 virtual bool canTriggerImplicitSubmission() const { return isTextField(); }
230 virtual const AtomicString& formControlType() const;
232 virtual bool searchEventsShouldBeDispatched() const;
234 virtual bool saveFormControlState(String& value) const;
235 virtual void restoreFormControlState(const String&);
237 virtual bool canStartSelection() const;
239 virtual void accessKeyAction(bool sendToAnyElement);
241 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
242 virtual void parseMappedAttribute(Attribute*);
244 virtual void copyNonAttributeProperties(const Element* source);
246 virtual void attach();
248 virtual bool appendFormData(FormDataList&, bool);
250 virtual bool isSuccessfulSubmitButton() const;
252 virtual void reset();
254 virtual void* preDispatchEventHandler(Event*);
255 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
257 virtual bool isURLAttribute(Attribute*) const;
259 virtual void cacheSelection(int start, int end);
261 virtual bool isAcceptableValue(const String&) const;
262 virtual String sanitizeValue(const String&) const;
263 virtual bool hasUnacceptableValue() const;
265 virtual bool isInRange() const;
266 virtual bool isOutOfRange() const;
268 virtual void documentDidBecomeActive();
270 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
272 bool needsActivationCallback();
273 void registerForActivationCallbackIfNeeded();
274 void unregisterForActivationCallbackIfNeeded();
276 virtual bool supportsMaxLength() const { return isTextType(); }
277 bool isTextType() const;
279 virtual bool supportsPlaceholder() const;
280 virtual bool isEmptyValue() const { return value().isEmpty(); }
281 virtual void handleFocusEvent();
282 virtual void handleBlurEvent();
283 virtual int cachedSelectionStart() const { return m_data.cachedSelectionStart(); }
284 virtual int cachedSelectionEnd() const { return m_data.cachedSelectionEnd(); }
286 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
287 virtual bool isRequiredFormControl() const;
288 virtual bool recalcWillValidate() const;
292 // Helper for stepUp()/stepDown(). Adds step value * count to the current value.
293 void applyStep(double count, ExceptionCode&);
296 HTMLDataListElement* dataList() const;
300 virtual InputElementData data() const { return m_data; }
303 InputElementData m_data;
305 bool m_isChecked : 1;
306 bool m_reflectsCheckedAttribute : 1;
307 bool m_isIndeterminate : 1;
309 bool m_isActivatedSubmit : 1;
310 unsigned m_autocomplete : 2; // AutoCompleteSetting
311 bool m_isAutofilled : 1;
313 bool m_hasNonEmptyList : 1;
315 OwnPtr<InputType> m_inputType;