Do not select range when picker input element has focus in focus ui mode
[framework/web/webkit-efl.git] / Source / WebCore / 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 "HTMLTextFormControlElement.h"
29 #include "ImageLoaderClient.h"
30 #include "StepRange.h"
31
32 namespace WebCore {
33
34 class CheckedRadioButtons;
35 class DragData;
36 class FileList;
37 class HTMLDataListElement;
38 class HTMLOptionElement;
39 class Icon;
40 class InputType;
41 class KURL;
42 class ListAttributeTargetObserver;
43
44 class HTMLInputElement : public HTMLTextFormControlElement, public ImageLoaderClientBase<HTMLInputElement> {
45 public:
46     static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
47     virtual ~HTMLInputElement();
48
49     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange);
50
51     virtual HTMLInputElement* toInputElement() { return this; }
52
53     virtual bool shouldAutocomplete() const;
54
55     // For ValidityState
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;
65
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;
75
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;
83
84     bool isTextButton() const;
85
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;
93
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.
98     bool isText() const;
99
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;
113
114 #if ENABLE(INPUT_SPEECH)
115     bool isSpeechEnabled() const;
116 #endif
117
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;
126 #endif
127     HTMLElement* sliderThumbElement() const;
128     virtual HTMLElement* placeholderElement() const;
129
130     bool checked() const { return m_isChecked; }
131     void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent);
132
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;
139
140     int size() const;
141     bool sizeShouldIncludeDecoration(int& preferredSize) const;
142
143     void setType(const String&);
144
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(); };
152
153     String sanitizeValue(const String&) const;
154
155     String localizeValue(const String&) const;
156
157     // The value which is drawn by a renderer.
158     String visibleValue() const;
159
160     const String& suggestedValue() const;
161     void setSuggestedValue(const String&);
162
163     void setEditingValue(const String&);
164
165     double valueAsDate() const;
166     void setValueAsDate(double, ExceptionCode&);
167
168     double valueAsNumber() const;
169     void setValueAsNumber(double, ExceptionCode&, TextFieldEventBehavior = DispatchNoEvent);
170
171     virtual String placeholder() const;
172     virtual void setPlaceholder(const String&);
173
174     String valueWithDefault() const;
175
176     void setValueFromRenderer(const String&);
177
178     bool canHaveSelection() const;
179
180     virtual bool rendererIsNeeded(const NodeRenderingContext&);
181     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
182     virtual void detach();
183
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);
189
190     String altText() const;
191
192     int maxResults() const { return m_maxResults; }
193
194     String defaultValue() const;
195     void setDefaultValue(const String&);
196
197     Vector<String> acceptMIMETypes();
198     Vector<String> acceptFileExtensions();
199     String accept() const;
200     String alt() const;
201
202     void setSize(unsigned);
203
204     KURL src() const;
205
206     virtual int maxLength() const;
207     void setMaxLength(int, ExceptionCode&);
208
209     bool multiple() const;
210
211     bool isAutofilled() const { return m_isAutofilled; }
212     void setAutofilled(bool = true);
213
214     FileList* files();
215     void setFiles(PassRefPtr<FileList>);
216
217     // Returns true if the given DragData has more than one dropped files.
218     bool receiveDroppedFiles(const DragData*);
219
220 #if ENABLE(FILE_SYSTEM)
221     String droppedFileSystemId();
222 #endif
223
224     Icon* icon() const;
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);
229
230     void addSearchResult();
231     void onSearch();
232
233     virtual bool willRespondToMouseClickEvents() OVERRIDE;
234
235 #if ENABLE(DATALIST_ELEMENT)
236     HTMLElement* list() const;
237     HTMLDataListElement* dataList() const;
238     void listAttributeTargetChanged();
239 #endif
240
241     HTMLInputElement* checkedRadioButtonForGroup() const;
242     bool isInRequiredRadioButtonGroup() const;
243
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; }
250
251     void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); }
252
253 #if ENABLE(INPUT_TYPE_COLOR)
254     // For test purposes.
255     void selectColorInColorChooser(const Color&);
256 #endif
257
258     String defaultToolTip() const;
259
260 #if ENABLE(MEDIA_CAPTURE)
261     String capture() const;
262     void setCapture(const String& value);
263 #endif
264
265     static const int maximumLength;
266
267     unsigned height() const;
268     unsigned width() const;
269     void setHeight(unsigned);
270     void setWidth(unsigned);
271
272     virtual const AtomicString& name() const OVERRIDE;
273
274 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
275     bool shouldUsePicker();
276 #endif
277
278 protected:
279     HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
280     void createShadowSubtree();
281     virtual void defaultEventHandler(Event*);
282
283 private:
284     enum AutoCompleteSetting { Uninitialized, On, Off };
285
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;
291
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();
299
300     virtual bool isTextFormControl() const { return isTextField(); }
301
302     virtual bool canTriggerImplicitSubmission() const { return isTextField(); }
303
304     virtual const AtomicString& formControlType() const;
305
306     virtual bool shouldSaveAndRestoreFormControlState() const OVERRIDE;
307     virtual FormControlState saveFormControlState() const OVERRIDE;
308     virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
309
310     virtual bool canStartSelection() const;
311
312     virtual void accessKeyAction(bool sendMouseEvents);
313
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();
318
319     virtual void copyNonAttributePropertiesFromElement(const Element&);
320
321     virtual void attach();
322
323     virtual bool appendFormData(FormDataList&, bool);
324
325     virtual bool isSuccessfulSubmitButton() const;
326
327     virtual void reset();
328
329     virtual void* preDispatchEventHandler(Event*);
330     virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
331
332     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
333
334     virtual bool isInRange() const;
335     virtual bool isOutOfRange() const;
336
337     virtual void documentDidResumeFromPageCache();
338
339     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
340
341     bool needsSuspensionCallback();
342     void registerForSuspensionCallbackIfNeeded();
343     void unregisterForSuspensionCallbackIfNeeded();
344
345     bool supportsMaxLength() const { return isTextType(); }
346     bool isTextType() const;
347     bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
348
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();
356
357     virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
358     virtual bool isRequiredFormControl() const;
359     virtual bool recalcWillValidate() const;
360     virtual void requiredAttributeChanged() OVERRIDE;
361
362     void updateType();
363     
364     virtual void subtreeHasChanged();
365
366 #if ENABLE(DATALIST_ELEMENT)
367     void resetListAttributeTargetObserver();
368 #endif
369     void parseMaxLengthAttribute(const Attribute&);
370     void updateValueIfNeeded();
371
372     // Returns null if this isn't associated with any radio button group.
373     CheckedRadioButtons* checkedRadioButtons() const;
374     void addToRadioButtonGroup();
375     void removeFromRadioButtonGroup();
376
377     AtomicString m_name;
378     String m_valueIfDirty;
379     String m_suggestedValue;
380     int m_size;
381     int m_maxLength;
382     short m_maxResults;
383     bool m_isChecked : 1;
384     bool m_reflectsCheckedAttribute : 1;
385     bool m_isIndeterminate : 1;
386     bool m_hasType : 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;
392 #endif
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;
402 #endif
403 };
404
405 } //namespace
406 #endif