2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "ExceptionCode.h"
35 #include <wtf/Forward.h>
36 #include <wtf/Noncopyable.h>
43 class HTMLInputElement;
50 // An InputType object represents the type-specific part of an HTMLInputElement.
51 // Do not expose instances of InputType and classes derived from it to classes
52 // other than HTMLInputElement.
53 class InputType : public Noncopyable {
55 static PassOwnPtr<InputType> create(HTMLInputElement*, const AtomicString&);
56 static PassOwnPtr<InputType> createText(HTMLInputElement*);
59 // Type query functions
61 virtual bool isTextField() const;
62 virtual bool isTextType() const;
63 virtual const AtomicString& formControlType() const = 0;
65 // Form value functions
67 virtual bool saveFormControlState(String&) const;
68 virtual void restoreFormControlState(const String&) const;
69 virtual bool isFormDataAppendable() const;
70 virtual bool appendFormData(FormDataList&, bool multipart) const;
72 // DOM property functions
74 virtual double valueAsDate() const;
75 virtual void setValueAsDate(double, ExceptionCode&) const;
76 virtual double valueAsNumber() const;
77 virtual void setValueAsNumber(double, ExceptionCode&) const;
79 // Validation functions
81 virtual bool supportsValidation() const;
82 virtual bool typeMismatchFor(const String&) const;
83 // Type check for the current input value. We do nothing for some types
84 // though typeMismatchFor() does something for them because of value
86 virtual bool typeMismatch() const;
87 virtual bool supportsRequired() const;
88 virtual bool valueMissing(const String&) const;
89 virtual bool patternMismatch(const String&) const;
90 virtual bool rangeUnderflow(const String&) const;
91 virtual bool rangeOverflow(const String&) const;
92 virtual double minimum() const;
93 virtual double maximum() const;
94 virtual bool stepMismatch(const String&, double) const;
95 virtual double stepBase() const;
96 virtual double stepBaseWithDecimalPlaces(unsigned*) const;
97 virtual double defaultStep() const;
98 virtual double stepScaleFactor() const;
99 virtual bool parsedStepValueShouldBeInteger() const;
100 virtual bool scaledStepValeuShouldBeInteger() const;
101 virtual double acceptableError(double) const;
102 virtual String typeMismatchText() const;
105 // If the return value is true, do no further default event handling in the
106 // default event handler. If an event handler calls Event::setDefaultHandled(),
107 // its return value must be true.
109 virtual bool handleClickEvent(MouseEvent*);
110 virtual bool handleDOMActivateEvent(Event*);
111 virtual bool handleKeydownEvent(KeyboardEvent*);
113 // Miscellaneous functions
115 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
117 // Parses the specified string for the type, and return
118 // the double value for the parsing result if the parsing
119 // succeeds; Returns defaultValue otherwise. This function can
120 // return NaN or Infinity only if defaultValue is NaN or Infinity.
121 virtual double parseToDouble(const String&, double defaultValue) const;
122 // Parses the specified string for the type as parseToDouble() does.
123 // In addition, it stores the number of digits after the decimal point
124 // into *decimalPlaces.
125 virtual double parseToDoubleWithDecimalPlaces(const String& src, double defaultValue, unsigned *decimalPlaces) const;
126 // Parses the specified string for this InputType, and returns true if it
127 // is successfully parsed. An instance pointed by the DateComponents*
128 // parameter will have parsed values and be modified even if the parsing
129 // fails. The DateComponents* parameter may be 0.
130 virtual bool parseToDateComponents(const String&, DateComponents*) const;
131 // Create a string representation of the specified double value for the
132 // input type. If NaN or Infinity is specified, this returns an empty
133 // string. This should not be called for types without valueAsNumber.
134 virtual String serialize(double) const;
137 InputType(HTMLInputElement* element) : m_element(element) { }
138 HTMLInputElement* element() const { return m_element; }
139 // We can't make this a static const data member because VC++ doesn't like it.
140 static double defaultStepBase() { return 0.0; }
143 // Raw pointer because the HTMLInputElement object owns this InputType object.
144 HTMLInputElement* m_element;
147 namespace InputTypeNames {
149 const AtomicString& button();
150 const AtomicString& checkbox();
151 const AtomicString& color();
152 const AtomicString& date();
153 const AtomicString& datetime();
154 const AtomicString& datetimelocal();
155 const AtomicString& email();
156 const AtomicString& file();
157 const AtomicString& hidden();
158 const AtomicString& image();
159 const AtomicString& isindex();
160 const AtomicString& month();
161 const AtomicString& number();
162 const AtomicString& password();
163 const AtomicString& radio();
164 const AtomicString& range();
165 const AtomicString& reset();
166 const AtomicString& search();
167 const AtomicString& submit();
168 const AtomicString& telephone();
169 const AtomicString& text();
170 const AtomicString& time();
171 const AtomicString& url();
172 const AtomicString& week();
174 } // namespace WebCore::InputTypeNames
176 } // namespace WebCore