2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <wtf/Forward.h>
36 #include <wtf/FastAllocBase.h>
37 #include <wtf/Noncopyable.h>
38 #include <wtf/RefPtr.h>
39 #include <wtf/Vector.h>
43 class BeforeTextInsertedEvent;
51 class HTMLFormElement;
52 class HTMLInputElement;
62 typedef int ExceptionCode;
64 struct ClickHandlingState {
65 WTF_MAKE_FAST_ALLOCATED;
69 RefPtr<HTMLInputElement> checkedRadioButton;
72 // An InputType object represents the type-specific part of an HTMLInputElement.
73 // Do not expose instances of InputType and classes derived from it to classes
74 // other than HTMLInputElement.
76 WTF_MAKE_NONCOPYABLE(InputType); WTF_MAKE_FAST_ALLOCATED;
78 static PassOwnPtr<InputType> create(HTMLInputElement*, const String&);
79 static PassOwnPtr<InputType> createText(HTMLInputElement*);
82 virtual const AtomicString& formControlType() const = 0;
83 virtual bool canChangeFromAnotherType() const;
85 // Type query functions
87 // Any time we are using one of these functions it's best to refactor
88 // to add a virtual function to allow the input type object to do the
89 // work instead, or at least make a query function that asks a higher
90 // level question. These functions make the HTMLInputElement class
91 // inflexible because it's harder to add new input types if there is
92 // scattered code with special cases for various types.
94 #if ENABLE(INPUT_COLOR)
95 virtual bool isColorControl() const;
97 virtual bool isCheckbox() const;
98 virtual bool isEmailField() const;
99 virtual bool isFileUpload() const;
100 virtual bool isHiddenType() const;
101 virtual bool isImageButton() const;
102 virtual bool isNumberField() const;
103 virtual bool isPasswordField() const;
104 virtual bool isRadioButton() const;
105 virtual bool isRangeControl() const;
106 virtual bool isSearchField() const;
107 virtual bool isSubmitButton() const;
108 virtual bool isTelephoneField() const;
109 virtual bool isTextButton() const;
110 virtual bool isTextField() const;
111 virtual bool isTextType() const;
112 virtual bool isURLField() const;
114 #if ENABLE(TIZEN_INPUT_TAG_DATE)
115 virtual bool isColorField() const;
116 virtual bool isDateField() const;
117 virtual bool isTimeField() const;
120 // Form value functions
122 virtual bool saveFormControlState(String&) const;
123 virtual void restoreFormControlState(const String&) const;
124 virtual bool isFormDataAppendable() const;
125 virtual bool appendFormData(FormDataList&, bool multipart) const;
127 // DOM property functions
129 virtual bool getTypeSpecificValue(String&); // Checked first, before internal storage or the value attribute.
130 virtual String fallbackValue() const; // Checked last, if both internal storage and value attribute are missing.
131 virtual String defaultValue() const; // Checked after even fallbackValue, only when the valueWithDefault function is called.
132 virtual double valueAsDate() const;
133 virtual void setValueAsDate(double, ExceptionCode&) const;
134 virtual double valueAsNumber() const;
135 virtual void setValueAsNumber(double, bool sendChangeEvent, ExceptionCode&) const;
137 // Validation functions
139 virtual bool supportsValidation() const;
140 virtual bool typeMismatchFor(const String&) const;
141 // Type check for the current input value. We do nothing for some types
142 // though typeMismatchFor() does something for them because of value
144 virtual bool typeMismatch() const;
145 virtual bool supportsRequired() const;
146 virtual bool valueMissing(const String&) const;
147 virtual bool patternMismatch(const String&) const;
148 virtual bool rangeUnderflow(const String&) const;
149 virtual bool rangeOverflow(const String&) const;
150 virtual bool supportsRangeLimitation() const;
151 virtual double defaultValueForStepUp() const;
152 virtual double minimum() const;
153 virtual double maximum() const;
154 virtual bool sizeShouldIncludeDecoration(int defaultSize, int& preferredSize) const;
155 virtual bool stepMismatch(const String&, double step) const;
156 virtual double stepBase() const;
157 virtual double stepBaseWithDecimalPlaces(unsigned*) const;
158 virtual double defaultStep() const;
159 virtual double stepScaleFactor() const;
160 virtual bool parsedStepValueShouldBeInteger() const;
161 virtual bool scaledStepValueShouldBeInteger() const;
162 virtual double acceptableError(double) const;
163 virtual String typeMismatchText() const;
164 virtual String valueMissingText() const;
165 virtual bool canSetStringValue() const;
166 virtual String visibleValue() const;
167 virtual String convertFromVisibleValue(const String&) const;
168 virtual bool isAcceptableValue(const String&);
169 // Returing the null string means "use the default value."
170 // This function must be called only by HTMLInputElement::sanitizeValue().
171 virtual String sanitizeValue(const String&) const;
172 virtual bool hasUnacceptableValue();
176 virtual void handleClickEvent(MouseEvent*);
177 virtual void handleMouseDownEvent(MouseEvent*);
178 virtual PassOwnPtr<ClickHandlingState> willDispatchClick();
179 virtual void didDispatchClick(Event*, const ClickHandlingState&);
180 virtual void handleDOMActivateEvent(Event*);
181 virtual void handleKeydownEvent(KeyboardEvent*);
182 virtual void handleKeypressEvent(KeyboardEvent*);
183 virtual void handleKeyupEvent(KeyboardEvent*);
184 virtual void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*);
185 virtual void handleWheelEvent(WheelEvent*);
186 virtual void forwardEvent(Event*);
187 // Helpers for event handlers.
188 virtual bool shouldSubmitImplicitly(Event*);
189 virtual PassRefPtr<HTMLFormElement> formForSubmission() const;
190 virtual bool isKeyboardFocusable() const;
191 virtual bool shouldUseInputMethod() const;
192 virtual void handleBlurEvent();
193 virtual void accessKeyAction(bool sendMouseEvents);
194 virtual bool canBeSuccessfulSubmitButton();
197 // Shadow tree handling
199 virtual void createShadowSubtree();
200 virtual void destroyShadowSubtree();
202 virtual HTMLElement* containerElement() const { return 0; }
203 virtual HTMLElement* innerBlockElement() const { return 0; }
204 virtual HTMLElement* innerTextElement() const { return 0; }
205 virtual HTMLElement* innerSpinButtonElement() const { return 0; }
206 virtual HTMLElement* resultsButtonElement() const { return 0; }
207 virtual HTMLElement* cancelButtonElement() const { return 0; }
208 #if ENABLE(INPUT_SPEECH)
209 virtual HTMLElement* speechButtonElement() const { return 0; }
211 virtual HTMLElement* placeholderElement() const;
213 // Miscellaneous functions
215 virtual bool rendererIsNeeded();
216 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
217 virtual void attach();
218 virtual void detach();
219 virtual void minOrMaxAttributeChanged();
220 virtual void stepAttributeChanged();
221 virtual void altAttributeChanged();
222 virtual void srcAttributeChanged();
223 virtual void willMoveToNewOwnerDocument();
224 virtual bool shouldRespectAlignAttribute();
225 virtual FileList* files();
226 virtual void receiveDroppedFiles(const Vector<String>&);
227 virtual Icon* icon() const;
228 // Should return true if the corresponding renderer for a type can display a suggested value.
229 virtual bool canSetSuggestedValue();
230 virtual bool shouldSendChangeEventAfterCheckedChanged();
231 virtual bool canSetValue(const String&);
232 virtual bool storesValueSeparateFromAttribute();
233 virtual void setValue(const String&, bool valueChanged, bool sendChangeEvent);
234 virtual void dispatchChangeEventInResponseToSetValue();
235 virtual bool shouldResetOnDocumentActivation();
236 virtual bool shouldRespectListAttribute();
237 virtual bool shouldRespectSpeechAttribute();
238 virtual bool isEnumeratable();
239 virtual bool isCheckable();
240 virtual bool isSteppable() const;
241 virtual bool shouldRespectHeightAndWidthAttributes();
242 virtual bool supportsPlaceholder() const;
243 virtual void updatePlaceholderText();
244 virtual void multipleAttributeChanged();
245 virtual void disabledAttributeChanged();
246 virtual void readonlyAttributeChanged();
247 virtual String defaultToolTip() const;
249 // Parses the specified string for the type, and return
250 // the double value for the parsing result if the parsing
251 // succeeds; Returns defaultValue otherwise. This function can
252 // return NaN or Infinity only if defaultValue is NaN or Infinity.
253 virtual double parseToDouble(const String&, double defaultValue) const;
255 // Parses the specified string for the type as parseToDouble() does.
256 // In addition, it stores the number of digits after the decimal point
257 // into *decimalPlaces.
258 virtual double parseToDoubleWithDecimalPlaces(const String&, double defaultValue, unsigned* decimalPlaces) const;
260 // Parses the specified string for this InputType, and returns true if it
261 // is successfully parsed. An instance pointed by the DateComponents*
262 // parameter will have parsed values and be modified even if the parsing
263 // fails. The DateComponents* parameter may be 0.
264 virtual bool parseToDateComponents(const String&, DateComponents*) const;
266 // Create a string representation of the specified double value for the
267 // input type. If NaN or Infinity is specified, this returns an empty
268 // string. This should not be called for types without valueAsNumber.
269 virtual String serialize(double) const;
272 InputType(HTMLInputElement* element) : m_element(element) { }
273 HTMLInputElement* element() const { return m_element; }
274 void dispatchSimulatedClickIfActive(KeyboardEvent*) const;
275 // We can't make this a static const data member because VC++ doesn't like it.
276 static double defaultStepBase() { return 0.0; }
277 Chrome* chrome() const;
280 // Raw pointer because the HTMLInputElement object owns this InputType object.
281 HTMLInputElement* m_element;
284 namespace InputTypeNames {
286 const AtomicString& button();
287 const AtomicString& checkbox();
288 #if ENABLE(INPUT_COLOR)
289 const AtomicString& color();
291 const AtomicString& date();
292 const AtomicString& datetime();
293 const AtomicString& datetimelocal();
294 const AtomicString& email();
295 const AtomicString& file();
296 const AtomicString& hidden();
297 const AtomicString& image();
298 const AtomicString& isindex();
299 const AtomicString& month();
300 const AtomicString& number();
301 const AtomicString& password();
302 const AtomicString& radio();
303 const AtomicString& range();
304 const AtomicString& reset();
305 const AtomicString& search();
306 const AtomicString& submit();
307 const AtomicString& telephone();
308 const AtomicString& text();
309 const AtomicString& time();
310 const AtomicString& url();
311 const AtomicString& week();
313 } // namespace WebCore::InputTypeNames
315 } // namespace WebCore