OSDN Git Service

am e5097951: (-s ours) am 5793dcc1: Merge "Do not merge: fix dns prefetch, multiply...
[android-x86/external-webkit.git] / WebCore / html / InputType.h
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #ifndef InputType_h
32 #define InputType_h
33
34 #include "ExceptionCode.h"
35 #include <wtf/Forward.h>
36 #include <wtf/Noncopyable.h>
37
38 namespace WebCore {
39
40 class DateComponents;
41 class FormDataList;
42 class HTMLInputElement;
43 class RenderArena;
44 class RenderObject;
45 class RenderStyle;
46
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 {
51 public:
52     static PassOwnPtr<InputType> create(HTMLInputElement*, const AtomicString&);
53     static PassOwnPtr<InputType> createText(HTMLInputElement*);
54     virtual ~InputType();
55
56     // Type query functions
57
58     virtual bool isTextField() const;
59     virtual bool isTextType() const;
60     virtual const AtomicString& formControlType() const = 0;
61
62     // Form value functions
63
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;
68
69     // DOM property functions
70
71     virtual double valueAsDate() const;
72     virtual void setValueAsDate(double, ExceptionCode&) const;
73     virtual double valueAsNumber() const;
74     virtual void setValueAsNumber(double, ExceptionCode&) const;
75
76     // Validation functions
77
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
82     // sanitization.
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;
97
98     // Miscellaneous functions
99
100     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
101
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;
116
117 protected:
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; }
122
123 private:
124     // Raw pointer because the HTMLInputElement object owns this InputType object.
125     HTMLInputElement* m_element;
126 };
127
128 namespace InputTypeNames {
129
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();
154
155 } // namespace WebCore::InputTypeNames
156
157 } // namespace WebCore
158
159 #endif