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>
41 class HTMLInputElement;
43 class InputType : public Noncopyable {
45 static PassOwnPtr<InputType> create(HTMLInputElement*, const AtomicString&);
46 static PassOwnPtr<InputType> createText(HTMLInputElement*);
49 virtual bool isTextField() const;
50 virtual bool isTextType() const;
51 virtual const AtomicString& formControlType() const = 0;
53 virtual double valueAsDate() const;
54 virtual void setValueAsDate(double, ExceptionCode&) const;
55 virtual double valueAsNumber() const;
56 virtual void setValueAsNumber(double, ExceptionCode&) const;
58 // Validation-related functions
60 virtual bool supportsValidation() const;
61 virtual bool typeMismatchFor(const String&) const;
62 // Type check for the current input value. We do nothing for some types
63 // though typeMismatchFor() does something for them because of value
65 virtual bool typeMismatch() const;
66 virtual bool supportsRequired() const;
67 virtual bool valueMissing(const String&) const;
68 virtual bool patternMismatch(const String&) const;
69 virtual bool rangeUnderflow(const String&) const;
70 virtual bool rangeOverflow(const String&) const;
71 virtual double minimum() const;
72 virtual double maximum() const;
73 virtual bool stepMismatch(const String&, double) const;
74 virtual double stepBase() const;
75 virtual double defaultStep() const;
76 virtual double stepScaleFactor() const;
77 virtual bool parsedStepValueShouldBeInteger() const;
78 virtual bool scaledStepValeuShouldBeInteger() const;
80 // Parses the specified string for the type, and return
81 // the double value for the parsing result if the parsing
82 // succeeds; Returns defaultValue otherwise. This function can
83 // return NaN or Infinity only if defaultValue is NaN or Infinity.
84 virtual double parseToDouble(const String&, double defaultValue) const;
85 // Parses the specified string for this InputType, and returns true if it
86 // is successfully parsed. An instance pointed by the DateComponents*
87 // parameter will have parsed values and be modified even if the parsing
88 // fails. The DateComponents* parameter may be 0.
89 virtual bool parseToDateComponents(const String&, DateComponents*) const;
90 // Create a string representation of the specified double value for the
91 // input type. If NaN or Infinity is specified, this returns an empty
92 // string. This should not be called for types without valueAsNumber.
93 virtual String serialize(double) const;
96 InputType(HTMLInputElement* element) : m_element(element) { }
97 HTMLInputElement* element() const { return m_element; }
98 // We can't make this a static const data member because VC++ doesn't like it.
99 static double defaultStepBase() { return 0.0; }
102 // Raw pointer because the HTMLInputElement object owns this InputType object.
103 HTMLInputElement* m_element;
106 namespace InputTypeNames {
108 const AtomicString& button();
109 const AtomicString& checkbox();
110 const AtomicString& color();
111 const AtomicString& date();
112 const AtomicString& datetime();
113 const AtomicString& datetimelocal();
114 const AtomicString& email();
115 const AtomicString& file();
116 const AtomicString& hidden();
117 const AtomicString& image();
118 const AtomicString& isindex();
119 const AtomicString& month();
120 const AtomicString& number();
121 const AtomicString& password();
122 const AtomicString& radio();
123 const AtomicString& range();
124 const AtomicString& reset();
125 const AtomicString& search();
126 const AtomicString& submit();
127 const AtomicString& telephone();
128 const AtomicString& text();
129 const AtomicString& time();
130 const AtomicString& url();
131 const AtomicString& week();
133 } // namespace WebCore::InputTypeNames
135 } // namespace WebCore