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 void updateFocusAppearance(bool restorePreviousSelection);
215 virtual void aboutToUnload();
216 virtual bool shouldUseInputMethod() const;
218 virtual const AtomicString& formControlName() const;
220 // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
221 virtual bool isChecked() const;
222 virtual bool isIndeterminate() const { return indeterminate(); }
224 virtual bool isTextFormControl() const { return isTextField(); }
226 virtual bool hasSpinButton() const;
227 virtual bool canTriggerImplicitSubmission() const { return isTextField(); }
229 virtual const AtomicString& formControlType() const;
231 virtual bool searchEventsShouldBeDispatched() const;
233 virtual bool saveFormControlState(String& value) const;
234 virtual void restoreFormControlState(const String&);
236 virtual bool canStartSelection() const;
238 virtual void accessKeyAction(bool sendToAnyElement);
240 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
241 virtual void parseMappedAttribute(Attribute*);
243 virtual void copyNonAttributeProperties(const Element* source);
245 virtual void attach();
247 virtual bool appendFormData(FormDataList&, bool);
249 virtual bool isSuccessfulSubmitButton() const;
251 virtual void reset();
253 virtual void* preDispatchEventHandler(Event*);
254 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
256 virtual bool isURLAttribute(Attribute*) const;
258 virtual void cacheSelection(int start, int end);
260 virtual bool isAcceptableValue(const String&) const;
261 virtual String sanitizeValue(const String&) const;
262 virtual bool hasUnacceptableValue() const;
264 virtual bool isInRange() const;
265 virtual bool isOutOfRange() const;
267 virtual void documentDidBecomeActive();
269 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
271 bool needsActivationCallback();
272 void registerForActivationCallbackIfNeeded();
273 void unregisterForActivationCallbackIfNeeded();
275 virtual bool supportsMaxLength() const { return isTextType(); }
276 bool isTextType() const;
278 virtual bool supportsPlaceholder() const;
279 virtual bool isEmptyValue() const { return value().isEmpty(); }
280 virtual void handleFocusEvent();
281 virtual void handleBlurEvent();
282 virtual int cachedSelectionStart() const { return m_data.cachedSelectionStart(); }
283 virtual int cachedSelectionEnd() const { return m_data.cachedSelectionEnd(); }
285 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
286 virtual bool isRequiredFormControl() const;
287 virtual bool recalcWillValidate() const;
291 // Helper for stepUp()/stepDown(). Adds step value * count to the current value.
292 void applyStep(double count, ExceptionCode&);
295 HTMLDataListElement* dataList() const;
299 virtual InputElementData data() const { return m_data; }
302 InputElementData m_data;
304 bool m_isChecked : 1;
305 bool m_reflectsCheckedAttribute : 1;
306 bool m_isIndeterminate : 1;
308 bool m_isActivatedSubmit : 1;
309 unsigned m_autocomplete : 2; // AutoCompleteSetting
310 bool m_isAutofilled : 1;
312 bool m_hasNonEmptyList : 1;
314 OwnPtr<InputType> m_inputType;