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 "FileChooser.h"
29 #include "HTMLTextFormControlElement.h"
30 #include "ImageLoaderClient.h"
31 #include "StepRange.h"
35 class CheckedRadioButtons;
38 class HTMLDataListElement;
39 class HTMLOptionElement;
43 class ListAttributeTargetObserver;
44 struct DateTimeChooserParameters;
46 class HTMLInputElement : public HTMLTextFormControlElement, public ImageLoaderClientBase<HTMLInputElement> {
48 static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
49 virtual ~HTMLInputElement();
51 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange);
53 virtual HTMLInputElement* toInputElement() { return this; }
55 virtual bool shouldAutocomplete() const;
58 virtual bool hasBadInput() const OVERRIDE;
59 virtual bool patternMismatch() const OVERRIDE;
60 virtual bool rangeUnderflow() const OVERRIDE;
61 virtual bool rangeOverflow() const;
62 virtual bool stepMismatch() const OVERRIDE;
63 virtual bool tooLong() const OVERRIDE;
64 virtual bool typeMismatch() const OVERRIDE;
65 virtual bool valueMissing() const OVERRIDE;
66 virtual String validationMessage() const OVERRIDE;
68 // Returns the minimum value for type=date, number, or range. Don't call this for other types.
69 double minimum() const;
70 // Returns the maximum value for type=date, number, or range. Don't call this for other types.
71 // This always returns a value which is >= minimum().
72 double maximum() const;
73 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer.
74 // Returns false if there is no "allowed value step."
75 bool getAllowedValueStep(Decimal*) const;
76 StepRange createStepRange(AnyStepHandling) const;
78 #if ENABLE(DATALIST_ELEMENT)
79 Decimal findClosestTickMarkValue(const Decimal&);
82 // Implementations of HTMLInputElement::stepUp() and stepDown().
83 void stepUp(int, ExceptionCode&);
84 void stepDown(int, ExceptionCode&);
85 void stepUp(ExceptionCode& ec) { stepUp(1, ec); }
86 void stepDown(ExceptionCode& ec) { stepDown(1, ec); }
87 // stepUp()/stepDown() for user-interaction.
88 bool isSteppable() const;
90 bool isTextButton() const;
92 bool isRadioButton() const;
93 bool isTextField() const;
94 bool isSearchField() const;
95 bool isInputTypeHidden() const;
96 bool isPasswordField() const;
97 bool isCheckbox() const;
98 bool isRangeControl() const;
100 #if ENABLE(INPUT_TYPE_COLOR)
101 bool isColorControl() const;
104 // FIXME: It's highly likely that any call site calling this function should instead
105 // be using a different one. Many input elements behave like text fields, and in addition
106 // any unknown input type is treated as text. Consider, for example, isTextField or
107 // isTextField && !isPasswordField.
110 bool isEmailField() const;
111 bool isFileUpload() const;
112 bool isImageButton() const;
113 bool isNumberField() const;
114 bool isSubmitButton() const;
115 bool isTelephoneField() const;
116 bool isURLField() const;
117 bool isDateField() const;
118 bool isDateTimeField() const;
119 bool isDateTimeLocalField() const;
120 bool isMonthField() const;
121 bool isTimeField() const;
122 bool isWeekField() const;
124 #if ENABLE(INPUT_SPEECH)
125 bool isSpeechEnabled() const;
128 HTMLElement* containerElement() const;
129 virtual HTMLElement* innerTextElement() const;
130 HTMLElement* innerBlockElement() const;
131 HTMLElement* innerSpinButtonElement() const;
132 HTMLElement* resultsButtonElement() const;
133 HTMLElement* cancelButtonElement() const;
134 #if ENABLE(INPUT_SPEECH)
135 HTMLElement* speechButtonElement() const;
137 HTMLElement* sliderThumbElement() const;
138 HTMLElement* sliderTrackElement() const;
139 virtual HTMLElement* placeholderElement() const;
141 bool checked() const { return m_isChecked; }
142 void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent);
144 // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state.
145 bool indeterminate() const { return m_isIndeterminate; }
146 void setIndeterminate(bool);
147 // shouldAppearChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
148 bool shouldAppearChecked() const;
149 virtual bool isIndeterminate() const;
152 bool sizeShouldIncludeDecoration(int& preferredSize) const;
154 void setType(const String&);
156 String value() const;
157 void setValue(const String&, ExceptionCode&, TextFieldEventBehavior = DispatchNoEvent);
158 void setValue(const String&, TextFieldEventBehavior = DispatchNoEvent);
159 void setValueForUser(const String&);
160 // Checks if the specified string would be a valid value.
161 // We should not call this for types with no string value such as CHECKBOX and RADIO.
162 bool isValidValue(const String&) const;
163 bool hasDirtyValue() const { return !m_valueIfDirty.isNull(); };
165 String sanitizeValue(const String&) const;
167 String localizeValue(const String&) const;
169 // The value which is drawn by a renderer.
170 String visibleValue() const;
172 const String& suggestedValue() const;
173 void setSuggestedValue(const String&);
175 void setEditingValue(const String&);
177 double valueAsDate() const;
178 void setValueAsDate(double, ExceptionCode&);
180 double valueAsNumber() const;
181 void setValueAsNumber(double, ExceptionCode&, TextFieldEventBehavior = DispatchNoEvent);
183 String valueWithDefault() const;
185 void setValueFromRenderer(const String&);
187 bool canHaveSelection() const;
189 virtual bool rendererIsNeeded(const NodeRenderingContext&);
190 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
191 virtual void detach();
193 // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making
194 // it private virtual in all classes and expose a public method in HTMLFormControlElement to call
195 // the private virtual method.
196 virtual bool isActivatedSubmit() const;
197 virtual void setActivatedSubmit(bool flag);
199 String altText() const;
201 int maxResults() const { return m_maxResults; }
203 String defaultValue() const;
204 void setDefaultValue(const String&);
206 Vector<String> acceptMIMETypes();
207 Vector<String> acceptFileExtensions();
208 String accept() const;
211 void setSize(unsigned);
212 void setSize(unsigned, ExceptionCode&);
216 virtual int maxLength() const;
217 void setMaxLength(int, ExceptionCode&);
219 bool multiple() const;
221 bool isAutofilled() const { return m_isAutofilled; }
222 void setAutofilled(bool = true);
225 void setFiles(PassRefPtr<FileList>);
227 // Returns true if the given DragData has more than one dropped files.
228 bool receiveDroppedFiles(const DragData*);
230 #if ENABLE(FILE_SYSTEM)
231 String droppedFileSystemId();
235 // These functions are used for rendering the input active during a
236 // drag-and-drop operation.
237 bool canReceiveDroppedFiles() const;
238 void setCanReceiveDroppedFiles(bool);
240 void addSearchResult();
243 virtual bool willRespondToMouseClickEvents() OVERRIDE;
245 #if ENABLE(DATALIST_ELEMENT)
246 HTMLElement* list() const;
247 HTMLDataListElement* dataList() const;
248 void listAttributeTargetChanged();
251 HTMLInputElement* checkedRadioButtonForGroup() const;
252 bool isInRequiredRadioButtonGroup();
254 // Functions for InputType classes.
255 void setValueInternal(const String&, TextFieldEventBehavior);
256 bool isTextFormControlFocusable() const;
257 bool isTextFormControlKeyboardFocusable(KeyboardEvent*) const;
258 bool isTextFormControlMouseFocusable() const;
259 bool valueAttributeWasUpdatedAfterParsing() const { return m_valueAttributeWasUpdatedAfterParsing; }
261 void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); }
263 #if ENABLE(INPUT_TYPE_COLOR)
264 // For test purposes.
265 void selectColorInColorChooser(const Color&);
268 String defaultToolTip() const;
270 #if ENABLE(MEDIA_CAPTURE)
271 String capture() const;
272 void setCapture(const String& value);
275 static const int maximumLength;
277 unsigned height() const;
278 unsigned width() const;
279 void setHeight(unsigned);
280 void setWidth(unsigned);
282 virtual void blur() OVERRIDE;
284 void defaultFocus(bool restorePreviousSelection);
285 virtual void focus(bool restorePreviousSelection = true) OVERRIDE;
287 virtual const AtomicString& name() const OVERRIDE;
291 static Vector<FileChooserFileInfo> filesFromFileInputFormControlState(const FormControlState&);
293 virtual bool matchesReadOnlyPseudoClass() const OVERRIDE;
294 virtual bool matchesReadWritePseudoClass() const OVERRIDE;
295 virtual void setRangeText(const String& replacement, ExceptionCode&) OVERRIDE;
296 virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionCode&) OVERRIDE;
298 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)
299 bool setupDateTimeChooserParameters(DateTimeChooserParameters&);
301 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
304 HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
305 void createShadowSubtree();
306 virtual void defaultEventHandler(Event*);
307 // FIXME: Author shadows should be allowed
308 // https://bugs.webkit.org/show_bug.cgi?id=92608
309 virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
312 enum AutoCompleteSetting { Uninitialized, On, Off };
314 virtual void willChangeForm() OVERRIDE;
315 virtual void didChangeForm() OVERRIDE;
316 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
317 virtual void removedFrom(ContainerNode*) OVERRIDE;
318 virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
320 virtual bool hasCustomFocusLogic() const OVERRIDE;
321 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
322 virtual bool isMouseFocusable() const;
323 virtual bool isEnumeratable() const;
324 virtual bool supportLabels() const OVERRIDE;
325 virtual void updateFocusAppearance(bool restorePreviousSelection);
326 virtual bool shouldUseInputMethod();
328 virtual bool isTextFormControl() const { return isTextField(); }
330 virtual bool canTriggerImplicitSubmission() const { return isTextField(); }
332 virtual const AtomicString& formControlType() const;
334 virtual bool shouldSaveAndRestoreFormControlState() const OVERRIDE;
335 virtual FormControlState saveFormControlState() const OVERRIDE;
336 virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
338 virtual bool canStartSelection() const;
340 virtual void accessKeyAction(bool sendMouseEvents);
342 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
343 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
344 virtual void collectStyleForPresentationAttribute(const Attribute&, StylePropertySet*) OVERRIDE;
345 virtual void finishParsingChildren();
347 virtual void copyNonAttributePropertiesFromElement(const Element&);
349 virtual void attach();
351 virtual bool appendFormData(FormDataList&, bool);
353 virtual bool isSuccessfulSubmitButton() const;
355 virtual void reset();
357 virtual void* preDispatchEventHandler(Event*);
358 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
360 virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
362 virtual bool isInRange() const;
363 virtual bool isOutOfRange() const;
365 virtual void documentDidResumeFromPageCache();
367 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
369 bool needsSuspensionCallback();
370 void registerForSuspensionCallbackIfNeeded();
371 void unregisterForSuspensionCallbackIfNeeded();
373 bool supportsMaxLength() const { return isTextType(); }
374 bool isTextType() const;
375 bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
377 virtual bool supportsPlaceholder() const;
378 virtual void updatePlaceholderText();
379 virtual bool isEmptyValue() const OVERRIDE { return innerTextValue().isEmpty(); }
380 virtual bool isEmptySuggestedValue() const { return suggestedValue().isEmpty(); }
381 virtual void handleFocusEvent();
382 virtual void handleBlurEvent();
384 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
385 virtual bool isRequiredFormControl() const;
386 virtual bool recalcWillValidate() const;
387 virtual void requiredAttributeChanged() OVERRIDE;
391 virtual void subtreeHasChanged();
393 #if ENABLE(DATALIST_ELEMENT)
394 void resetListAttributeTargetObserver();
396 void parseMaxLengthAttribute(const AtomicString&);
397 void updateValueIfNeeded();
399 // Returns null if this isn't associated with any radio button group.
400 CheckedRadioButtons* checkedRadioButtons() const;
401 void addToRadioButtonGroup();
402 void removeFromRadioButtonGroup();
405 String m_valueIfDirty;
406 String m_suggestedValue;
410 bool m_isChecked : 1;
411 bool m_reflectsCheckedAttribute : 1;
412 bool m_isIndeterminate : 1;
414 bool m_isActivatedSubmit : 1;
415 unsigned m_autocomplete : 2; // AutoCompleteSetting
416 bool m_isAutofilled : 1;
417 #if ENABLE(DATALIST_ELEMENT)
418 bool m_hasNonEmptyList : 1;
420 bool m_stateRestored : 1;
421 bool m_parsingInProgress : 1;
422 bool m_valueAttributeWasUpdatedAfterParsing : 1;
423 bool m_wasModifiedByUser : 1;
424 bool m_canReceiveDroppedFiles : 1;
425 #if ENABLE(TOUCH_EVENTS)
426 bool m_hasTouchEventHandler : 1;
428 OwnPtr<InputType> m_inputType;
429 #if ENABLE(DATALIST_ELEMENT)
430 OwnPtr<ListAttributeTargetObserver> m_listAttributeTargetObserver;