• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Dirk Mueller (mueller@kde.org)
5  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #ifndef HTMLInputElement_h
25 #define HTMLInputElement_h
26 
27 #include "HTMLFormControlElement.h"
28 #include "InputElement.h"
29 #include <wtf/OwnPtr.h>
30 
31 namespace WebCore {
32 
33 class FileList;
34 class HTMLImageLoader;
35 class KURL;
36 class Selection;
37 
38 class HTMLInputElement : public HTMLFormControlElementWithState, public InputElement {
39 public:
40     enum InputType {
41         TEXT,
42         PASSWORD,
43         ISINDEX,
44         CHECKBOX,
45         RADIO,
46         SUBMIT,
47         RESET,
48         FILE,
49         HIDDEN,
50         IMAGE,
51         BUTTON,
52         SEARCH,
53         RANGE
54     };
55 
56     enum AutoCompleteSetting {
57         Uninitialized,
58         On,
59         Off
60     };
61 
62     HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
63     virtual ~HTMLInputElement();
64 
endTagRequirement()65     virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; }
tagPriority()66     virtual int tagPriority() const { return 0; }
67 
68     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
69     virtual bool isMouseFocusable() const;
isEnumeratable()70     virtual bool isEnumeratable() const { return inputType() != IMAGE; }
71     virtual void dispatchFocusEvent();
72     virtual void dispatchBlurEvent();
73     virtual void updateFocusAppearance(bool restorePreviousSelection);
74     virtual void aboutToUnload();
75     virtual bool shouldUseInputMethod() const;
76 
77     virtual const AtomicString& name() const;
78 
79     bool autoComplete() const;
80 
81     // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
isChecked()82     virtual bool isChecked() const { return checked() && (inputType() == CHECKBOX || inputType() == RADIO); }
isIndeterminate()83     virtual bool isIndeterminate() const { return indeterminate(); }
84 
readOnly()85     bool readOnly() const { return isReadOnlyControl(); }
86 
isTextControl()87     virtual bool isTextControl() const { return isTextField(); }
88 
isTextButton()89     bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
isRadioButton()90     virtual bool isRadioButton() const { return m_type == RADIO; }
isTextField()91     virtual bool isTextField() const { return m_type == TEXT || m_type == PASSWORD || m_type == SEARCH || m_type == ISINDEX; }
isSearchField()92     virtual bool isSearchField() const { return m_type == SEARCH; }
isInputTypeHidden()93     virtual bool isInputTypeHidden() const { return m_type == HIDDEN; }
isPasswordField()94     virtual bool isPasswordField() const { return m_type == PASSWORD; }
95 
checked()96     bool checked() const { return m_checked; }
97     void setChecked(bool, bool sendChangeEvent = false);
indeterminate()98     bool indeterminate() const { return m_indeterminate; }
99     void setIndeterminate(bool);
100     virtual int size() const;
101     virtual const AtomicString& type() const;
102     void setType(const String&);
103 
104     virtual String value() const;
105     virtual void setValue(const String&);
106 
107     virtual String placeholderValue() const;
108     virtual bool searchEventsShouldBeDispatched() const;
109 
110     String valueWithDefault() const;
111 
112     virtual void setValueFromRenderer(const String&);
113     void setFileListFromRenderer(const Vector<String>&);
114 
115     virtual bool saveState(String& value) const;
116     virtual void restoreState(const String&);
117 
118     virtual bool canStartSelection() const;
119 
120     bool canHaveSelection() const;
121     int selectionStart() const;
122     int selectionEnd() const;
123     void setSelectionStart(int);
124     void setSelectionEnd(int);
125     virtual void select();
126     void setSelectionRange(int start, int end);
127 
128     virtual void accessKeyAction(bool sendToAnyElement);
129 
130     virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
131     virtual void parseMappedAttribute(MappedAttribute*);
132 
133     virtual void copyNonAttributeProperties(const Element* source);
134 
135     virtual void attach();
136     virtual bool rendererIsNeeded(RenderStyle*);
137     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
138     virtual void detach();
139     virtual bool appendFormData(FormDataList&, bool);
140 
141     virtual bool isSuccessfulSubmitButton() const;
142     virtual bool isActivatedSubmit() const;
143     virtual void setActivatedSubmit(bool flag);
144 
inputType()145     InputType inputType() const { return static_cast<InputType>(m_type); }
146     void setInputType(const String&);
147 
148     // Report if this input type uses height & width attributes
respectHeightAndWidthAttrs()149     bool respectHeightAndWidthAttrs() const { return inputType() == IMAGE || inputType() == HIDDEN; }
150 
151     virtual void reset();
152 
153     virtual void* preDispatchEventHandler(Event*);
154     virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
155     virtual void defaultEventHandler(Event*);
156 
157     String altText() const;
158 
159     virtual bool isURLAttribute(Attribute*) const;
160 
maxResults()161     int maxResults() const { return m_maxResults; }
162 
163     String defaultValue() const;
164     void setDefaultValue(const String&);
165 
166     bool defaultChecked() const;
167     void setDefaultChecked(bool);
168 
169     void setDefaultName(const AtomicString&);
170 
171     String accept() const;
172     void setAccept(const String&);
173 
174     String accessKey() const;
175     void setAccessKey(const String&);
176 
177     String align() const;
178     void setAlign(const String&);
179 
180     String alt() const;
181     void setAlt(const String&);
182 
183     void setSize(unsigned);
184 
185     KURL src() const;
186     void setSrc(const String&);
187 
188     int maxLength() const;
189     void setMaxLength(int);
190 
191     String useMap() const;
192     void setUseMap(const String&);
193 
isAutofilled()194     bool isAutofilled() const { return m_autofilled; }
195     void setAutofilled(bool value = true);
196 
197     FileList* files();
198 
199     virtual void cacheSelection(int start, int end);
200     void addSearchResult();
201     void onSearch();
202 
203     Selection selection() const;
204 
205     virtual String constrainValue(const String& proposedValue) const;
206 
207     virtual void documentDidBecomeActive();
208 
209     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
210 
211     virtual bool willValidate() const;
212 
213     virtual bool placeholderShouldBeVisible() const;
214 
215 protected:
216     virtual void willMoveToNewOwnerDocument();
217     virtual void didMoveToNewOwnerDocument();
218 
219 private:
220     bool storesValueSeparateFromAttribute() const;
221 
222     bool needsActivationCallback();
223     void registerForActivationCallbackIfNeeded();
224     void unregisterForActivationCallbackIfNeeded();
225 
226     InputElementData m_data;
227     int m_xPos;
228     int m_yPos;
229     short m_maxResults;
230     OwnPtr<HTMLImageLoader> m_imageLoader;
231     RefPtr<FileList> m_fileList;
232     unsigned m_type : 4; // InputType
233     bool m_checked : 1;
234     bool m_defaultChecked : 1;
235     bool m_useDefaultChecked : 1;
236     bool m_indeterminate : 1;
237     bool m_haveType : 1;
238     bool m_activeSubmit : 1;
239     unsigned m_autocomplete : 2; // AutoCompleteSetting
240     bool m_autofilled : 1;
241     bool m_inited : 1;
242 };
243 
244 } //namespace
245 
246 #endif
247