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>
42 class HTMLInputElement;
47 // An InputType object represents the type-specific part of an HTMLInputElement.
48 // Do not expose instances of InputType and classes derived from it to classes
49 // other than HTMLInputElement.
50 class InputType : public Noncopyable {
52 static PassOwnPtr<InputType> create(HTMLInputElement*, const AtomicString&);
53 static PassOwnPtr<InputType> createText(HTMLInputElement*);
56 // Type query functions
58 virtual bool isTextField() const;
59 virtual bool isTextType() const;
60 virtual const AtomicString& formControlType() const = 0;
62 // Form value functions
64 virtual bool saveFormControlState(String&) const;
65 virtual void restoreFormControlState(const String&) const;
66 virtual bool isFormDataAppendable() const;
67 virtual bool appendFormData(FormDataList&, bool multipart) const;
69 // DOM property functions
71 virtual double valueAsDate() const;
72 virtual void setValueAsDate(double, ExceptionCode&) const;
73 virtual double valueAsNumber() const;
74 virtual void setValueAsNumber(double, ExceptionCode&) const;
76 // Validation functions
78 virtual bool supportsValidation() const;
79 virtual bool typeMismatchFor(const String&) const;
80 // Type check for the current input value. We do nothing for some types
81 // though typeMismatchFor() does something for them because of value
83 virtual bool typeMismatch() const;
84 virtual bool supportsRequired() const;
85 virtual bool valueMissing(const String&) const;
86 virtual bool patternMismatch(const String&) const;
87 virtual bool rangeUnderflow(const String&) const;
88 virtual bool rangeOverflow(const String&) const;
89 virtual double minimum() const;
90 virtual double maximum() const;
91 virtual bool stepMismatch(const String&, double) const;
92 virtual double stepBase() const;
93 virtual double defaultStep() const;
94 virtual double stepScaleFactor() const;
95 virtual bool parsedStepValueShouldBeInteger() const;
96 virtual bool scaledStepValeuShouldBeInteger() const;
98 // Miscellaneous functions
100 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
102 // Parses the specified string for the type, and return
103 // the double value for the parsing result if the parsing
104 // succeeds; Returns defaultValue otherwise. This function can
105 // return NaN or Infinity only if defaultValue is NaN or Infinity.
106 virtual double parseToDouble(const String&, double defaultValue) const;
107 // Parses the specified string for this InputType, and returns true if it
108 // is successfully parsed. An instance pointed by the DateComponents*
109 // parameter will have parsed values and be modified even if the parsing
110 // fails. The DateComponents* parameter may be 0.
111 virtual bool parseToDateComponents(const String&, DateComponents*) const;
112 // Create a string representation of the specified double value for the
113 // input type. If NaN or Infinity is specified, this returns an empty
114 // string. This should not be called for types without valueAsNumber.
115 virtual String serialize(double) const;
118 InputType(HTMLInputElement* element) : m_element(element) { }
119 HTMLInputElement* element() const { return m_element; }
120 // We can't make this a static const data member because VC++ doesn't like it.
121 static double defaultStepBase() { return 0.0; }
124 // Raw pointer because the HTMLInputElement object owns this InputType object.
125 HTMLInputElement* m_element;
128 namespace InputTypeNames {
130 const AtomicString& button();
131 const AtomicString& checkbox();
132 const AtomicString& color();
133 const AtomicString& date();
134 const AtomicString& datetime();
135 const AtomicString& datetimelocal();
136 const AtomicString& email();
137 const AtomicString& file();
138 const AtomicString& hidden();
139 const AtomicString& image();
140 const AtomicString& isindex();
141 const AtomicString& month();
142 const AtomicString& number();
143 const AtomicString& password();
144 const AtomicString& radio();
145 const AtomicString& range();
146 const AtomicString& reset();
147 const AtomicString& search();
148 const AtomicString& submit();
149 const AtomicString& telephone();
150 const AtomicString& text();
151 const AtomicString& time();
152 const AtomicString& url();
153 const AtomicString& week();
155 } // namespace WebCore::InputTypeNames
157 } // namespace WebCore