OSDN Git Service

am 1e5798a4: am d436a8e4: Allow HTML5 video to seek.
[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 Event;
42 class FormDataList;
43 class HTMLInputElement;
44 class KeyboardEvent;
45 class MouseEvent;
46 class RenderArena;
47 class RenderObject;
48 class RenderStyle;
49
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 {
54 public:
55     static PassOwnPtr<InputType> create(HTMLInputElement*, const AtomicString&);
56     static PassOwnPtr<InputType> createText(HTMLInputElement*);
57     virtual ~InputType();
58
59     // Type query functions
60
61     virtual bool isTextField() const;
62     virtual bool isTextType() const;
63     virtual const AtomicString& formControlType() const = 0;
64
65     // Form value functions
66
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;
71
72     // DOM property functions
73
74     virtual double valueAsDate() const;
75     virtual void setValueAsDate(double, ExceptionCode&) const;
76     virtual double valueAsNumber() const;
77     virtual void setValueAsNumber(double, ExceptionCode&) const;
78
79     // Validation functions
80
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
85     // sanitization.
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;
103
104     // Event handlers
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.
108
109     virtual bool handleClickEvent(MouseEvent*);
110     virtual bool handleDOMActivateEvent(Event*);
111     virtual bool handleKeydownEvent(KeyboardEvent*);
112
113     // Miscellaneous functions
114
115     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
116
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;
135
136 protected:
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; }
141
142 private:
143     // Raw pointer because the HTMLInputElement object owns this InputType object.
144     HTMLInputElement* m_element;
145 };
146
147 namespace InputTypeNames {
148
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();
173
174 } // namespace WebCore::InputTypeNames
175
176 } // namespace WebCore
177
178 #endif