OSDN Git Service

Merge "Merge WebKit at Chromium 9.0.597.83: Trivial merge by git." into honeycomb
[android-x86/external-webkit.git] / WebCore / dom / InputElement.h
1 /*
2  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #ifndef InputElement_h
22 #define InputElement_h
23
24 #include "PlatformString.h"
25 #include <wtf/text/AtomicString.h>
26
27 namespace WebCore {
28
29 class Attribute;
30 class Document;
31 class Element;
32 class Event;
33 class InputElementData;
34
35 class InputElement {
36 public:
37     virtual ~InputElement() { }
38
39     virtual bool isAutofilled() const = 0;
40     virtual bool isChecked() const = 0;
41     virtual bool isIndeterminate() const = 0;
42     virtual bool isInputTypeHidden() const = 0;
43     virtual bool isPasswordField() const = 0;
44     virtual bool isSearchField() const = 0;
45     virtual bool isTextField() const = 0;
46     virtual bool isRadioButton() const = 0;
47     virtual bool isCheckbox() const = 0;
48     
49     virtual bool supportsMaxLength() const = 0;
50     virtual bool hasSpinButton() const { return false; }
51 #if ENABLE(INPUT_SPEECH)
52     virtual bool isSpeechEnabled() const = 0;
53 #endif    
54
55     virtual bool searchEventsShouldBeDispatched() const = 0;
56
57     virtual int size() const = 0;
58     virtual const String& suggestedValue() const = 0;
59     virtual String value() const = 0;
60     virtual void setValue(const String&, bool sendChangeEvent = false) = 0;
61     virtual void setValueForUser(const String&) = 0;
62
63     // Returns true if the specified string can be set as the value of InputElement.
64     virtual bool isAcceptableValue(const String&) const = 0;
65     virtual String sanitizeValue(const String&) const = 0;
66     virtual void setValueFromRenderer(const String&) = 0;
67
68     virtual void cacheSelection(int start, int end) = 0;
69     virtual void select() = 0;
70   
71 #if ENABLE(WCSS)
72     virtual InputElementData data() const = 0; 
73 #endif
74
75     static const int s_maximumLength;
76     static const int s_defaultSize;
77
78 protected:
79     static void dispatchFocusEvent(InputElement*, Element*);
80     static void dispatchBlurEvent(InputElement*, Element*);
81     static void updateFocusAppearance(InputElementData&, InputElement*, Element*, bool restorePreviousSelection);
82     static void updateSelectionRange(InputElement*, Element*, int start, int end);
83     static void aboutToUnload(InputElement*, Element*);
84     static void setValueFromRenderer(InputElementData&, InputElement*, Element*, const String&);
85     // Replaces CRs and LFs, shrinks the value for s_maximumLength.
86     // This should be applied to values from the HTML value attribute and the DOM value property.
87     // This function should be called only by sanitizeValue() implementations.
88     static String sanitizeValueForTextField(const InputElement*, const String&);
89     // Replaces CRs and LFs, shrinks the value for the specified maximum length.
90     // This should be applied to values specified by users.
91     // The input string may be a fragment of the whole value.
92     static String sanitizeUserInputValue(const InputElement*, const String&, int);
93     static void handleBeforeTextInsertedEvent(InputElementData&, InputElement*, Element*, Event*);
94     static void parseSizeAttribute(InputElementData&, Element*, Attribute*);
95     static void parseMaxLengthAttribute(InputElementData&, InputElement*, Element*, Attribute*);
96     static void updateValueIfNeeded(InputElementData&, InputElement*);
97     static void notifyFormStateChanged(Element*);
98 #if ENABLE(WCSS)
99     static bool isConformToInputMask(const InputElementData&, const String&);
100     static bool isConformToInputMask(const InputElementData&, UChar, unsigned);
101     static String validateInputMask(InputElementData&, String&);
102 #endif
103 };
104
105 // HTML/WMLInputElement hold this struct as member variable
106 // and pass it to the static helper functions in InputElement
107 class InputElementData {
108 public:
109     InputElementData();
110     ~InputElementData();
111
112     const AtomicString& name() const;
113     void setName(const AtomicString& value) { m_name = value; }
114
115     String value() const { return m_value; }
116     void setValue(const String& value) { m_value = value; }
117
118     const String& suggestedValue() const { return m_suggestedValue; }
119     void setSuggestedValue(const String& value) { m_suggestedValue = value; }
120
121     int size() const { return m_size; }
122     void setSize(int value) { m_size = value; }
123
124     int maxLength() const { return m_maxLength; }
125     void setMaxLength(int value) { m_maxLength = value; }
126
127     int cachedSelectionStart() const { return m_cachedSelectionStart; }
128     void setCachedSelectionStart(int value) { m_cachedSelectionStart = value; }
129
130     int cachedSelectionEnd() const { return m_cachedSelectionEnd; }
131     void setCachedSelectionEnd(int value) { m_cachedSelectionEnd = value; }
132
133 #if ENABLE(WCSS)
134     String inputFormatMask() const { return m_inputFormatMask; }
135     void setInputFormatMask(const String& mask) { m_inputFormatMask = mask; }
136  
137     unsigned maxInputCharsAllowed() const { return m_maxInputCharsAllowed; }
138     void setMaxInputCharsAllowed(unsigned maxLength) { m_maxInputCharsAllowed = maxLength; }
139   
140 #endif
141
142 private:
143     AtomicString m_name;
144     String m_value;
145     String m_suggestedValue;
146     int m_size;
147     int m_maxLength;
148     int m_cachedSelectionStart;
149     int m_cachedSelectionEnd;
150 #if ENABLE(WCSS)
151     String m_inputFormatMask;
152     unsigned m_maxInputCharsAllowed;
153 #endif
154 };
155
156 InputElement* toInputElement(Element*);
157
158 }
159
160 #endif