OSDN Git Service

Merge "Merge chromium at 10.0.634.0: Compile fixes"
[android-x86/external-webkit.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  *
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.
11  *
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.
16  *
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.
21  *
22  */
23
24 #ifndef HTMLInputElement_h
25 #define HTMLInputElement_h
26
27 #include "HTMLFormControlElement.h"
28 #include "InputElement.h"
29
30 namespace WebCore {
31
32 class FileList;
33 class HTMLDataListElement;
34 class HTMLOptionElement;
35 class InputType;
36 class KURL;
37
38 class HTMLInputElement : public HTMLTextFormControlElement, public InputElement {
39 public:
40     static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
41     virtual ~HTMLInputElement();
42
43     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange);
44
45     bool autoComplete() const;
46
47     // For ValidityState
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;
64     // For ValidityState.
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;
72
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);
80
81     bool isTextButton() const;
82
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;
89
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.
94     bool isText() const;
95
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;
103
104 #if ENABLE(INPUT_SPEECH)
105     virtual bool isSpeechEnabled() const;
106 #endif
107
108     bool checked() const { return m_isChecked; }
109     void setChecked(bool, bool sendChangeEvent = false);
110
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);
114
115     virtual int size() const;
116
117     void setType(const String&);
118
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;
125
126     virtual const String& suggestedValue() const;
127     void setSuggestedValue(const String&);
128
129     double valueAsDate() const;
130     void setValueAsDate(double, ExceptionCode&);
131
132     double valueAsNumber() const;
133     void setValueAsNumber(double, ExceptionCode&);
134
135     virtual String placeholder() const;
136     virtual void setPlaceholder(const String&);
137
138     String valueWithDefault() const;
139
140     virtual void setValueFromRenderer(const String&);
141     void setFileListFromRenderer(const Vector<String>&);
142
143     bool canHaveSelection() const;
144     virtual void select() { HTMLTextFormControlElement::select(); }
145
146     virtual bool rendererIsNeeded(RenderStyle*);
147     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
148     virtual void detach();
149
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);
155
156     String altText() const;
157
158     int maxResults() const { return m_maxResults; }
159
160     String defaultValue() const;
161     void setDefaultValue(const String&);
162
163     void setDefaultName(const AtomicString&);
164
165     String accept() const;
166     String alt() const;
167
168     void setSize(unsigned);
169
170     KURL src() const;
171
172     virtual int maxLength() const;
173     void setMaxLength(int, ExceptionCode&);
174
175     bool multiple() const;
176
177     virtual bool isAutofilled() const { return m_isAutofilled; }
178     void setAutofilled(bool = true);
179
180     FileList* files();
181
182     void addSearchResult();
183     void onSearch();
184
185 #if ENABLE(DATALIST)
186     HTMLElement* list() const;
187     HTMLOptionElement* selectedOption() const;
188 #endif
189
190 #if ENABLE(WCSS)
191     void setWapInputFormat(String& mask);
192 #endif
193
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();
199     
200 protected:
201     HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
202
203     virtual void defaultEventHandler(Event*);
204
205 private:
206     enum AutoCompleteSetting { Uninitialized, On, Off };
207
208     virtual void willMoveToNewOwnerDocument();
209     virtual void didMoveToNewOwnerDocument();
210
211     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
212     virtual bool isMouseFocusable() const;
213     virtual bool isEnumeratable() const;
214     virtual bool isResettable() const { return true; }
215     virtual void updateFocusAppearance(bool restorePreviousSelection);
216     virtual void aboutToUnload();
217     virtual bool shouldUseInputMethod() const;
218
219     virtual const AtomicString& formControlName() const;
220  
221     // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
222     virtual bool isChecked() const;
223     virtual bool isIndeterminate() const { return indeterminate(); }
224     
225     virtual bool isTextFormControl() const { return isTextField(); }
226
227     virtual bool hasSpinButton() const;
228     virtual bool canTriggerImplicitSubmission() const { return isTextField(); }
229
230     virtual const AtomicString& formControlType() const;
231
232     virtual bool searchEventsShouldBeDispatched() const;
233
234     virtual bool saveFormControlState(String& value) const;
235     virtual void restoreFormControlState(const String&);
236
237     virtual bool canStartSelection() const;
238     
239     virtual void accessKeyAction(bool sendToAnyElement);
240
241     virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
242     virtual void parseMappedAttribute(Attribute*);
243     virtual void finishParsingChildren();
244
245     virtual void copyNonAttributeProperties(const Element* source);
246
247     virtual void attach();
248
249     virtual bool appendFormData(FormDataList&, bool);
250
251     virtual bool isSuccessfulSubmitButton() const;
252
253     virtual void reset();
254
255     virtual void* preDispatchEventHandler(Event*);
256     virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
257
258     virtual bool isURLAttribute(Attribute*) const;
259
260     virtual void cacheSelection(int start, int end);
261
262     virtual String visibleValue() const;
263     virtual bool isAcceptableValue(const String&) const;
264     virtual String sanitizeValue(const String&) const;
265     virtual bool hasUnacceptableValue() const;
266
267     virtual bool isInRange() const;
268     virtual bool isOutOfRange() const;
269
270     virtual void documentDidBecomeActive();
271
272     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
273
274     bool needsActivationCallback();
275     void registerForActivationCallbackIfNeeded();
276     void unregisterForActivationCallbackIfNeeded();
277
278     virtual bool supportsMaxLength() const { return isTextType(); }
279     bool isTextType() const;
280
281     virtual bool supportsPlaceholder() const;
282     virtual bool isEmptyValue() const { return value().isEmpty(); }
283     virtual void handleFocusEvent();
284     virtual void handleBlurEvent();
285     virtual int cachedSelectionStart() const { return m_data.cachedSelectionStart(); }
286     virtual int cachedSelectionEnd() const { return m_data.cachedSelectionEnd(); }
287
288     virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
289     virtual bool isRequiredFormControl() const;
290     virtual bool recalcWillValidate() const;
291
292     void updateType();
293
294     // Helper for stepUp()/stepDown().  Adds step value * count to the current value.
295     void applyStep(double count, ExceptionCode&);
296
297 #if ENABLE(DATALIST)
298     HTMLDataListElement* dataList() const;
299 #endif
300
301 #if ENABLE(WCSS)
302     virtual InputElementData data() const { return m_data; }
303 #endif
304
305     InputElementData m_data;
306     short m_maxResults;
307     bool m_isChecked : 1;
308     bool m_reflectsCheckedAttribute : 1;
309     bool m_isIndeterminate : 1;
310     bool m_hasType : 1;
311     bool m_isActivatedSubmit : 1;
312     unsigned m_autocomplete : 2; // AutoCompleteSetting
313     bool m_isAutofilled : 1;
314 #if ENABLE(DATALIST)
315     bool m_hasNonEmptyList : 1;
316 #endif
317     bool m_stateRestored : 1;
318     bool m_parsingInProgress : 1;
319     OwnPtr<InputType> m_inputType;
320 };
321
322 } //namespace
323
324 #endif