10940efc70991f43f5c2e6f1dc6612eaf396e0db
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLInputElement.h
1 /*
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.
7  *
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.
12  *
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.
17  *
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.
22  *
23  */
24
25 #ifndef HTMLInputElement_h
26 #define HTMLInputElement_h
27
28 #include "core/html/HTMLTextFormControlElement.h"
29 #include "core/html/forms/StepRange.h"
30 #include "platform/FileChooser.h"
31
32 namespace blink {
33
34 class DragData;
35 class ExceptionState;
36 class FileList;
37 class HTMLDataListElement;
38 class HTMLImageLoader;
39 class HTMLOptionElement;
40 class InputType;
41 class InputTypeView;
42 class KURL;
43 class ListAttributeTargetObserver;
44 class RadioButtonGroupScope;
45 struct DateTimeChooserParameters;
46
47 class HTMLInputElement : public HTMLTextFormControlElement {
48 public:
49     static PassRefPtrWillBeRawPtr<HTMLInputElement> create(Document&, HTMLFormElement*, bool createdByParser);
50     virtual ~HTMLInputElement();
51     virtual void trace(Visitor*) OVERRIDE;
52
53     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange);
54
55     virtual bool shouldAutocomplete() const OVERRIDE FINAL;
56
57     // For ValidityState
58     virtual bool hasBadInput() const OVERRIDE FINAL;
59     virtual bool patternMismatch() const OVERRIDE FINAL;
60     virtual bool rangeUnderflow() const OVERRIDE FINAL;
61     virtual bool rangeOverflow() const OVERRIDE FINAL;
62     virtual bool stepMismatch() const OVERRIDE FINAL;
63     virtual bool tooLong() const OVERRIDE FINAL;
64     virtual bool typeMismatch() const OVERRIDE FINAL;
65     virtual bool valueMissing() const OVERRIDE FINAL;
66     virtual String validationMessage() const OVERRIDE FINAL;
67
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;
77
78     Decimal findClosestTickMarkValue(const Decimal&);
79
80     // Implementations of HTMLInputElement::stepUp() and stepDown().
81     void stepUp(int, ExceptionState&);
82     void stepDown(int, ExceptionState&);
83     void stepUp(ExceptionState& exceptionState) { stepUp(1, exceptionState); }
84     void stepDown(ExceptionState& exceptionState) { stepDown(1, exceptionState); }
85     // stepUp()/stepDown() for user-interaction.
86     bool isSteppable() const;
87
88     bool isTextButton() const;
89
90     bool isRadioButton() const;
91     bool isTextField() const;
92     bool isSearchField() const;
93     bool isInputTypeHidden() const;
94     bool isPasswordField() const;
95     bool isCheckbox() const;
96     bool isRangeControl() const;
97
98     // FIXME: It's highly likely that any call site calling this function should instead
99     // be using a different one. Many input elements behave like text fields, and in addition
100     // any unknown input type is treated as text. Consider, for example, isTextField or
101     // isTextField && !isPasswordField.
102     bool isText() const;
103
104     bool isEmailField() const;
105     bool isFileUpload() const;
106     bool isImageButton() const;
107     bool isNumberField() const;
108     bool isTelephoneField() const;
109     bool isURLField() const;
110     bool isDateField() const;
111     bool isDateTimeLocalField() const;
112     bool isMonthField() const;
113     bool isTimeField() const;
114     bool isWeekField() const;
115
116     bool checked() const { return m_isChecked; }
117     void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent);
118
119     // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state.
120     bool indeterminate() const { return m_isIndeterminate; }
121     void setIndeterminate(bool);
122     // shouldAppearChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
123     bool shouldAppearChecked() const;
124     virtual bool shouldAppearIndeterminate() const OVERRIDE;
125
126     int size() const;
127     bool sizeShouldIncludeDecoration(int& preferredSize) const;
128
129     void setType(const AtomicString&);
130
131     virtual String value() const OVERRIDE;
132     void setValue(const String&, ExceptionState&, TextFieldEventBehavior = DispatchNoEvent);
133     void setValue(const String&, TextFieldEventBehavior = DispatchNoEvent);
134     void setValueForUser(const String&);
135     // Checks if the specified string would be a valid value.
136     // We should not call this for types with no string value such as CHECKBOX and RADIO.
137     bool isValidValue(const String&) const;
138     bool hasDirtyValue() const { return !m_valueIfDirty.isNull(); };
139
140     String sanitizeValue(const String&) const;
141
142     String localizeValue(const String&) const;
143
144     const String& suggestedValue() const;
145     void setSuggestedValue(const String&);
146
147     void setEditingValue(const String&);
148
149     double valueAsDate(bool& isNull) const;
150     void setValueAsDate(double, ExceptionState&);
151
152     double valueAsNumber() const;
153     void setValueAsNumber(double, ExceptionState&, TextFieldEventBehavior = DispatchNoEvent);
154
155     String valueWithDefault() const;
156
157     void setValueFromRenderer(const String&);
158
159     int selectionStartForBinding(ExceptionState&) const;
160     int selectionEndForBinding(ExceptionState&) const;
161     String selectionDirectionForBinding(ExceptionState&) const;
162     void setSelectionStartForBinding(int, ExceptionState&);
163     void setSelectionEndForBinding(int, ExceptionState&);
164     void setSelectionDirectionForBinding(const String&, ExceptionState&);
165     void setSelectionRangeForBinding(int start, int end, ExceptionState&);
166     void setSelectionRangeForBinding(int start, int end, const String& direction, ExceptionState&);
167
168     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE FINAL;
169     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
170     virtual void detach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
171     virtual void updateFocusAppearance(bool restorePreviousSelection) OVERRIDE FINAL;
172
173     // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making
174     // it private virtual in all classes and expose a public method in HTMLFormControlElement to call
175     // the private virtual method.
176     virtual bool isActivatedSubmit() const OVERRIDE FINAL;
177     virtual void setActivatedSubmit(bool flag) OVERRIDE FINAL;
178
179     String altText() const;
180
181     int maxResults() const { return m_maxResults; }
182
183     const AtomicString& defaultValue() const;
184
185     Vector<String> acceptMIMETypes();
186     Vector<String> acceptFileExtensions();
187     const AtomicString& alt() const;
188
189     void setSize(unsigned);
190     void setSize(unsigned, ExceptionState&);
191
192     KURL src() const;
193
194     int maxLength() const;
195     void setMaxLength(int, ExceptionState&);
196
197     bool multiple() const;
198
199     FileList* files();
200     void setFiles(PassRefPtrWillBeRawPtr<FileList>);
201
202     // Returns true if the given DragData has more than one dropped files.
203     bool receiveDroppedFiles(const DragData*);
204
205     String droppedFileSystemId();
206
207     // These functions are used for rendering the input active during a
208     // drag-and-drop operation.
209     bool canReceiveDroppedFiles() const;
210     void setCanReceiveDroppedFiles(bool);
211
212     void onSearch();
213
214     void updateClearButtonVisibility();
215
216     virtual bool willRespondToMouseClickEvents() OVERRIDE;
217
218     HTMLElement* list() const;
219     HTMLDataListElement* dataList() const;
220     bool hasValidDataListOptions() const;
221     void listAttributeTargetChanged();
222
223     HTMLInputElement* checkedRadioButtonForGroup() const;
224     bool isInRequiredRadioButtonGroup();
225
226     // Functions for InputType classes.
227     void setValueInternal(const String&, TextFieldEventBehavior);
228     bool valueAttributeWasUpdatedAfterParsing() const { return m_valueAttributeWasUpdatedAfterParsing; }
229     void updateView();
230     bool needsToUpdateViewValue() const { return m_needsToUpdateViewValue; }
231     virtual void setInnerEditorValue(const String&) OVERRIDE;
232
233     void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); }
234
235     // For test purposes.
236     void selectColorInColorChooser(const Color&);
237
238     String defaultToolTip() const;
239
240     static const int maximumLength;
241
242     unsigned height() const;
243     unsigned width() const;
244     void setHeight(unsigned);
245     void setWidth(unsigned);
246
247     virtual void blur() OVERRIDE FINAL;
248     void defaultBlur();
249
250     virtual const AtomicString& name() const OVERRIDE FINAL;
251
252     void beginEditing();
253     void endEditing();
254
255     static Vector<FileChooserFileInfo> filesFromFileInputFormControlState(const FormControlState&);
256
257     virtual bool matchesReadOnlyPseudoClass() const OVERRIDE FINAL;
258     virtual bool matchesReadWritePseudoClass() const OVERRIDE FINAL;
259     virtual void setRangeText(const String& replacement, ExceptionState&) OVERRIDE FINAL;
260     virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionState&) OVERRIDE FINAL;
261
262     bool hasImageLoader() const { return m_imageLoader; }
263     HTMLImageLoader* imageLoader();
264
265     bool setupDateTimeChooserParameters(DateTimeChooserParameters&);
266
267     bool supportsInputModeAttribute() const;
268
269     void setShouldRevealPassword(bool value);
270     bool shouldRevealPassword() const { return m_shouldRevealPassword; }
271
272     virtual void didNotifySubtreeInsertionsToDocument() OVERRIDE;
273
274 protected:
275     HTMLInputElement(Document&, HTMLFormElement*, bool createdByParser);
276
277     virtual void defaultEventHandler(Event*) OVERRIDE;
278
279 private:
280     enum AutoCompleteSetting { Uninitialized, On, Off };
281
282     virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE FINAL;
283     virtual void willAddFirstAuthorShadowRoot() OVERRIDE FINAL;
284
285     virtual void willChangeForm() OVERRIDE FINAL;
286     virtual void didChangeForm() OVERRIDE FINAL;
287     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
288     virtual void removedFrom(ContainerNode*) OVERRIDE FINAL;
289     virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE FINAL;
290     virtual void removeAllEventListeners() OVERRIDE FINAL;
291
292     virtual bool hasCustomFocusLogic() const OVERRIDE FINAL;
293     virtual bool isKeyboardFocusable() const OVERRIDE FINAL;
294     virtual bool shouldShowFocusRingOnMouseFocus() const OVERRIDE FINAL;
295     virtual bool isEnumeratable() const OVERRIDE FINAL;
296     virtual bool isInteractiveContent() const OVERRIDE FINAL;
297     virtual bool supportLabels() const OVERRIDE FINAL;
298
299     virtual bool isTextFormControl() const OVERRIDE FINAL { return isTextField(); }
300
301     virtual bool canTriggerImplicitSubmission() const OVERRIDE FINAL { return isTextField(); }
302
303     virtual const AtomicString& formControlType() const OVERRIDE FINAL;
304
305     virtual bool shouldSaveAndRestoreFormControlState() const OVERRIDE FINAL;
306     virtual FormControlState saveFormControlState() const OVERRIDE FINAL;
307     virtual void restoreFormControlState(const FormControlState&) OVERRIDE FINAL;
308
309     virtual bool canStartSelection() const OVERRIDE FINAL;
310
311     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE FINAL;
312
313     virtual void attributeWillChange(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue) OVERRIDE;
314     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
315     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE FINAL;
316     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE FINAL;
317     virtual void finishParsingChildren() OVERRIDE FINAL;
318
319     virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE FINAL;
320
321     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
322
323     virtual bool appendFormData(FormDataList&, bool) OVERRIDE FINAL;
324     virtual String resultForDialogSubmit() OVERRIDE FINAL;
325
326     virtual bool canBeSuccessfulSubmitButton() const OVERRIDE FINAL;
327
328     virtual void resetImpl() OVERRIDE FINAL;
329     virtual bool supportsAutofocus() const OVERRIDE FINAL;
330
331     virtual void* preDispatchEventHandler(Event*) OVERRIDE FINAL;
332     virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch) OVERRIDE FINAL;
333
334     virtual bool isURLAttribute(const Attribute&) const OVERRIDE FINAL;
335     virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE FINAL;
336     virtual const QualifiedName& subResourceAttributeName() const OVERRIDE FINAL;
337     virtual bool isInRange() const OVERRIDE FINAL;
338     virtual bool isOutOfRange() const OVERRIDE FINAL;
339
340     bool isTextType() const;
341     bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
342
343     virtual bool supportsPlaceholder() const OVERRIDE FINAL;
344     virtual void updatePlaceholderText() OVERRIDE FINAL;
345     virtual bool isEmptyValue() const OVERRIDE FINAL { return innerEditorValue().isEmpty(); }
346     virtual bool isEmptySuggestedValue() const OVERRIDE FINAL { return suggestedValue().isEmpty(); }
347     virtual void handleFocusEvent(Element* oldFocusedElement, FocusType) OVERRIDE FINAL;
348     virtual void handleBlurEvent() OVERRIDE FINAL;
349
350     virtual bool isOptionalFormControl() const OVERRIDE FINAL { return !isRequiredFormControl(); }
351     virtual bool isRequiredFormControl() const OVERRIDE FINAL;
352     virtual bool recalcWillValidate() const OVERRIDE FINAL;
353     virtual void requiredAttributeChanged() OVERRIDE FINAL;
354
355     void updateType();
356
357     virtual void subtreeHasChanged() OVERRIDE FINAL;
358
359     void setListAttributeTargetObserver(PassOwnPtrWillBeRawPtr<ListAttributeTargetObserver>);
360     void resetListAttributeTargetObserver();
361     void parseMaxLengthAttribute(const AtomicString&);
362     void updateValueIfNeeded();
363
364     // Returns null if this isn't associated with any radio button group.
365     RadioButtonGroupScope* radioButtonGroupScope() const;
366     void addToRadioButtonGroup();
367     void removeFromRadioButtonGroup();
368 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
369     virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE;
370 #endif
371
372     virtual bool shouldDispatchFormControlChangeEvent(String&, String&) OVERRIDE;
373
374     AtomicString m_name;
375     String m_valueIfDirty;
376     String m_suggestedValue;
377     int m_size;
378     int m_maxLength;
379     short m_maxResults;
380     bool m_isChecked : 1;
381     bool m_reflectsCheckedAttribute : 1;
382     bool m_isIndeterminate : 1;
383     bool m_isActivatedSubmit : 1;
384     unsigned m_autocomplete : 2; // AutoCompleteSetting
385     bool m_hasNonEmptyList : 1;
386     bool m_stateRestored : 1;
387     bool m_parsingInProgress : 1;
388     bool m_valueAttributeWasUpdatedAfterParsing : 1;
389     bool m_canReceiveDroppedFiles : 1;
390     bool m_hasTouchEventHandler : 1;
391     bool m_shouldRevealPassword : 1;
392     bool m_needsToUpdateViewValue : 1;
393     RefPtrWillBeMember<InputType> m_inputType;
394     RefPtrWillBeMember<InputTypeView> m_inputTypeView;
395     // The ImageLoader must be owned by this element because the loader code assumes
396     // that it lives as long as its owning element lives. If we move the loader into
397     // the ImageInput object we may delete the loader while this element lives on.
398     OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader;
399     OwnPtrWillBeMember<ListAttributeTargetObserver> m_listAttributeTargetObserver;
400 };
401
402 } //namespace
403 #endif