OSDN Git Service

Merge WebKit at r70209: Initial merge by Git
[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 HTMLInputElement;
42
43 class InputType : public Noncopyable {
44 public:
45     static PassOwnPtr<InputType> create(HTMLInputElement*, const AtomicString&);
46     static PassOwnPtr<InputType> createText(HTMLInputElement*);
47     virtual ~InputType();
48
49     virtual bool isTextField() const;
50     virtual bool isTextType() const;
51     virtual const AtomicString& formControlType() const = 0;
52
53     virtual double valueAsDate() const;
54     virtual void setValueAsDate(double, ExceptionCode&) const;
55     virtual double valueAsNumber() const;
56     virtual void setValueAsNumber(double, ExceptionCode&) const;
57
58     // Validation-related functions
59
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
64     // sanitization.
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;
79
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;
94
95 protected:
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; }
100
101 private:
102     // Raw pointer because the HTMLInputElement object owns this InputType object.
103     HTMLInputElement* m_element;
104 };
105
106 namespace InputTypeNames {
107
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();
132
133 } // namespace WebCore::InputTypeNames
134
135 } // namespace WebCore
136
137 #endif