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.
6 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #ifndef HTMLInputElement_h
26 #define HTMLInputElement_h
28 #include "HTMLTextFormControlElement.h"
29 #include "ImageLoaderClient.h"
30 #include "StepRange.h"
34 class CheckedRadioButtons;
37 class HTMLDataListElement;
38 class HTMLOptionElement;
42 class ListAttributeTargetObserver;
44 class HTMLInputElement : public HTMLTextFormControlElement, public ImageLoaderClientBase<HTMLInputElement> {
46 static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
47 virtual ~HTMLInputElement();
49 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange);
51 virtual HTMLInputElement* toInputElement() { return this; }
53 virtual bool shouldAutocomplete() const;
56 virtual bool hasBadInput() const OVERRIDE;
57 virtual bool patternMismatch() const OVERRIDE;
58 virtual bool rangeUnderflow() const OVERRIDE;
59 virtual bool rangeOverflow() const;
60 virtual bool stepMismatch() const OVERRIDE;
61 virtual bool tooLong() const OVERRIDE;
62 virtual bool typeMismatch() const OVERRIDE;
63 virtual bool valueMissing() const OVERRIDE;
64 virtual String validationMessage() const OVERRIDE;
66 // Returns the minimum value for type=date, number, or range. Don't call this for other types.
67 double minimum() const;
68 // Returns the maximum value for type=date, number, or range. Don't call this for other types.
69 // This always returns a value which is >= minimum().
70 double maximum() const;
71 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer.
72 // Returns false if there is no "allowed value step."
73 bool getAllowedValueStep(Decimal*) const;
74 StepRange createStepRange(AnyStepHandling) const;
76 // Implementations of HTMLInputElement::stepUp() and stepDown().
77 void stepUp(int, ExceptionCode&);
78 void stepDown(int, ExceptionCode&);
79 void stepUp(ExceptionCode& ec) { stepUp(1, ec); }
80 void stepDown(ExceptionCode& ec) { stepDown(1, ec); }
81 // stepUp()/stepDown() for user-interaction.
82 bool isSteppable() const;
84 bool isTextButton() const;
86 bool isRadioButton() const;
87 bool isTextField() const;
88 bool isSearchField() const;
89 bool isInputTypeHidden() const;
90 bool isPasswordField() const;
91 bool isCheckbox() const;
92 bool isRangeControl() const;
94 // FIXME: It's highly likely that any call site calling this function should instead
95 // be using a different one. Many input elements behave like text fields, and in addition
96 // any unknown input type is treated as text. Consider, for example, isTextField or
97 // isTextField && !isPasswordField.
100 bool isEmailField() const;
101 bool isFileUpload() const;
102 bool isImageButton() const;
103 bool isNumberField() const;
104 bool isSubmitButton() const;
105 bool isTelephoneField() const;
106 bool isURLField() const;
107 bool isDateField() const;
108 bool isDateTimeField() const;
109 bool isDateTimeLocalField() const;
110 bool isMonthField() const;
111 bool isTimeField() const;
112 bool isWeekField() const;
114 #if ENABLE(INPUT_SPEECH)
115 bool isSpeechEnabled() const;
118 HTMLElement* containerElement() const;
119 virtual HTMLElement* innerTextElement() const;
120 HTMLElement* innerBlockElement() const;
121 HTMLElement* innerSpinButtonElement() const;
122 HTMLElement* resultsButtonElement() const;
123 HTMLElement* cancelButtonElement() const;
124 #if ENABLE(INPUT_SPEECH)
125 HTMLElement* speechButtonElement() const;
127 HTMLElement* sliderThumbElement() const;
128 virtual HTMLElement* placeholderElement() const;
130 bool checked() const { return m_isChecked; }
131 void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent);
133 // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state.
134 bool indeterminate() const { return m_isIndeterminate; }
135 void setIndeterminate(bool);
136 // shouldAppearChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
137 bool shouldAppearChecked() const;
138 virtual bool isIndeterminate() const;
141 bool sizeShouldIncludeDecoration(int& preferredSize) const;
143 void setType(const String&);
145 String value() const;
146 void setValue(const String&, TextFieldEventBehavior = DispatchNoEvent);
147 void setValueForUser(const String&);
148 // Checks if the specified string would be a valid value.
149 // We should not call this for types with no string value such as CHECKBOX and RADIO.
150 bool isValidValue(const String&) const;
151 bool hasDirtyValue() const { return !m_valueIfDirty.isNull(); };
153 String sanitizeValue(const String&) const;
155 String localizeValue(const String&) const;
157 // The value which is drawn by a renderer.
158 String visibleValue() const;
160 const String& suggestedValue() const;
161 void setSuggestedValue(const String&);
163 void setEditingValue(const String&);
165 double valueAsDate() const;
166 void setValueAsDate(double, ExceptionCode&);
168 double valueAsNumber() const;
169 void setValueAsNumber(double, ExceptionCode&, TextFieldEventBehavior = DispatchNoEvent);
171 virtual String placeholder() const;
172 virtual void setPlaceholder(const String&);
174 String valueWithDefault() const;
176 void setValueFromRenderer(const String&);
178 bool canHaveSelection() const;
180 virtual bool rendererIsNeeded(const NodeRenderingContext&);
181 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
182 virtual void detach();
184 // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making
185 // it private virtual in all classes and expose a public method in HTMLFormControlElement to call
186 // the private virtual method.
187 virtual bool isActivatedSubmit() const;
188 virtual void setActivatedSubmit(bool flag);
190 String altText() const;
192 int maxResults() const { return m_maxResults; }
194 String defaultValue() const;
195 void setDefaultValue(const String&);
197 Vector<String> acceptMIMETypes();
198 Vector<String> acceptFileExtensions();
199 String accept() const;
202 void setSize(unsigned);
206 virtual int maxLength() const;
207 void setMaxLength(int, ExceptionCode&);
209 bool multiple() const;
211 bool isAutofilled() const { return m_isAutofilled; }
212 void setAutofilled(bool = true);
215 void setFiles(PassRefPtr<FileList>);
217 // Returns true if the given DragData has more than one dropped files.
218 bool receiveDroppedFiles(const DragData*);
220 #if ENABLE(FILE_SYSTEM)
221 String droppedFileSystemId();
225 // These functions are used for rendering the input active during a
226 // drag-and-drop operation.
227 bool canReceiveDroppedFiles() const;
228 void setCanReceiveDroppedFiles(bool);
230 void addSearchResult();
233 virtual bool willRespondToMouseClickEvents() OVERRIDE;
235 #if ENABLE(DATALIST_ELEMENT)
236 HTMLElement* list() const;
237 HTMLDataListElement* dataList() const;
238 void listAttributeTargetChanged();
241 HTMLInputElement* checkedRadioButtonForGroup() const;
242 bool isInRequiredRadioButtonGroup() const;
244 // Functions for InputType classes.
245 void setValueInternal(const String&, TextFieldEventBehavior);
246 bool isTextFormControlFocusable() const;
247 bool isTextFormControlKeyboardFocusable(KeyboardEvent*) const;
248 bool isTextFormControlMouseFocusable() const;
249 bool valueAttributeWasUpdatedAfterParsing() const { return m_valueAttributeWasUpdatedAfterParsing; }
251 void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); }
253 #if ENABLE(INPUT_TYPE_COLOR)
254 // For test purposes.
255 void selectColorInColorChooser(const Color&);
258 String defaultToolTip() const;
260 #if ENABLE(MEDIA_CAPTURE)
261 String capture() const;
262 void setCapture(const String& value);
265 static const int maximumLength;
267 unsigned height() const;
268 unsigned width() const;
269 void setHeight(unsigned);
270 void setWidth(unsigned);
272 virtual const AtomicString& name() const OVERRIDE;
274 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
275 bool shouldUsePicker();
279 HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
280 void createShadowSubtree();
281 virtual void defaultEventHandler(Event*);
284 enum AutoCompleteSetting { Uninitialized, On, Off };
286 virtual void willChangeForm() OVERRIDE;
287 virtual void didChangeForm() OVERRIDE;
288 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
289 virtual void removedFrom(ContainerNode*) OVERRIDE;
290 virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
292 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
293 virtual bool isMouseFocusable() const;
294 virtual bool isEnumeratable() const;
295 virtual bool supportLabels() const OVERRIDE;
296 virtual void updateFocusAppearance(bool restorePreviousSelection);
297 virtual void aboutToUnload();
298 virtual bool shouldUseInputMethod();
300 virtual bool isTextFormControl() const { return isTextField(); }
302 virtual bool canTriggerImplicitSubmission() const { return isTextField(); }
304 virtual const AtomicString& formControlType() const;
306 virtual bool shouldSaveAndRestoreFormControlState() const OVERRIDE;
307 virtual FormControlState saveFormControlState() const OVERRIDE;
308 virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
310 virtual bool canStartSelection() const;
312 virtual void accessKeyAction(bool sendMouseEvents);
314 virtual void parseAttribute(const Attribute&) OVERRIDE;
315 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
316 virtual void collectStyleForAttribute(const Attribute&, StylePropertySet*) OVERRIDE;
317 virtual void finishParsingChildren();
319 virtual void copyNonAttributePropertiesFromElement(const Element&);
321 virtual void attach();
323 virtual bool appendFormData(FormDataList&, bool);
325 virtual bool isSuccessfulSubmitButton() const;
327 virtual void reset();
329 virtual void* preDispatchEventHandler(Event*);
330 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
332 virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
334 virtual bool isInRange() const;
335 virtual bool isOutOfRange() const;
337 virtual void documentDidResumeFromPageCache();
339 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
341 bool needsSuspensionCallback();
342 void registerForSuspensionCallbackIfNeeded();
343 void unregisterForSuspensionCallbackIfNeeded();
345 bool supportsMaxLength() const { return isTextType(); }
346 bool isTextType() const;
347 bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
349 virtual bool supportsPlaceholder() const;
350 virtual bool isPlaceholderEmpty() const OVERRIDE;
351 virtual void updatePlaceholderText();
352 virtual bool isEmptyValue() const OVERRIDE { return innerTextValue().isEmpty(); }
353 virtual bool isEmptySuggestedValue() const { return suggestedValue().isEmpty(); }
354 virtual void handleFocusEvent();
355 virtual void handleBlurEvent();
357 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
358 virtual bool isRequiredFormControl() const;
359 virtual bool recalcWillValidate() const;
360 virtual void requiredAttributeChanged() OVERRIDE;
364 virtual void subtreeHasChanged();
366 #if ENABLE(DATALIST_ELEMENT)
367 void resetListAttributeTargetObserver();
369 void parseMaxLengthAttribute(const Attribute&);
370 void updateValueIfNeeded();
372 // Returns null if this isn't associated with any radio button group.
373 CheckedRadioButtons* checkedRadioButtons() const;
374 void addToRadioButtonGroup();
375 void removeFromRadioButtonGroup();
378 String m_valueIfDirty;
379 String m_suggestedValue;
383 bool m_isChecked : 1;
384 bool m_reflectsCheckedAttribute : 1;
385 bool m_isIndeterminate : 1;
387 bool m_isActivatedSubmit : 1;
388 unsigned m_autocomplete : 2; // AutoCompleteSetting
389 bool m_isAutofilled : 1;
390 #if ENABLE(DATALIST_ELEMENT)
391 bool m_hasNonEmptyList : 1;
393 bool m_stateRestored : 1;
394 bool m_parsingInProgress : 1;
395 bool m_valueAttributeWasUpdatedAfterParsing : 1;
396 bool m_wasModifiedByUser : 1;
397 bool m_canReceiveDroppedFiles : 1;
398 bool m_hasTouchEventHandler: 1;
399 OwnPtr<InputType> m_inputType;
400 #if ENABLE(DATALIST_ELEMENT)
401 OwnPtr<ListAttributeTargetObserver> m_listAttributeTargetObserver;