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.
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.
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.
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.
24 #ifndef HTMLInputElement_h
25 #define HTMLInputElement_h
27 #include "HTMLFormControlElement.h"
28 #include <wtf/OwnPtr.h>
33 class HTMLImageLoader;
37 class HTMLInputElement : public HTMLFormControlElementWithState {
55 enum AutoCompleteSetting {
61 HTMLInputElement(Document*, HTMLFormElement* = 0);
62 HTMLInputElement(const QualifiedName& tagName, Document*, HTMLFormElement* = 0);
63 virtual ~HTMLInputElement();
65 virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; }
66 virtual int tagPriority() const { return 0; }
68 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
69 virtual bool isMouseFocusable() const;
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;
77 virtual const AtomicString& name() const;
79 bool autoComplete() const;
81 // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state
82 virtual bool isChecked() const { return checked() && (inputType() == CHECKBOX || inputType() == RADIO); }
83 virtual bool isIndeterminate() const { return indeterminate(); }
85 bool readOnly() const { return isReadOnlyControl(); }
87 virtual bool isTextControl() const { return isTextField(); }
89 bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
90 virtual bool isRadioButton() const { return m_type == RADIO; }
91 bool isTextField() const { return m_type == TEXT || m_type == PASSWORD || m_type == SEARCH || m_type == ISINDEX; }
92 bool isSearchField() const { return m_type == SEARCH; }
93 virtual bool isInputTypeHidden() const { return m_type == HIDDEN; }
94 virtual bool isPasswordField() const { return m_type == PASSWORD; }
96 bool checked() const { return m_checked; }
97 void setChecked(bool, bool sendChangeEvent = false);
98 bool indeterminate() const { return m_indeterminate; }
99 void setIndeterminate(bool);
100 int maxLength() const { return m_maxLen; }
101 int size() const { return m_size; }
102 virtual const AtomicString& type() const;
103 void setType(const String&);
105 String value() const;
106 void setValue(const String&);
108 String valueWithDefault() const;
110 void setValueFromRenderer(const String&);
112 virtual bool saveState(String& value) const;
113 virtual void restoreState(const String&);
115 virtual bool canStartSelection() const;
117 bool canHaveSelection() const;
118 int selectionStart() const;
119 int selectionEnd() const;
120 void setSelectionStart(int);
121 void setSelectionEnd(int);
123 void setSelectionRange(int start, int end);
125 virtual void accessKeyAction(bool sendToAnyElement);
127 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
128 virtual void parseMappedAttribute(MappedAttribute*);
130 virtual void copyNonAttributeProperties(const Element* source);
132 virtual void attach();
133 virtual bool rendererIsNeeded(RenderStyle*);
134 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
135 virtual void detach();
136 virtual bool appendFormData(FormDataList&, bool);
138 virtual bool isSuccessfulSubmitButton() const;
139 virtual bool isActivatedSubmit() const;
140 virtual void setActivatedSubmit(bool flag);
142 InputType inputType() const { return static_cast<InputType>(m_type); }
143 void setInputType(const String&);
145 // Report if this input type uses height & width attributes
146 bool respectHeightAndWidthAttrs() const { return inputType() == IMAGE || inputType() == HIDDEN; }
148 virtual void reset();
150 virtual void* preDispatchEventHandler(Event*);
151 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch);
152 virtual void defaultEventHandler(Event*);
154 String altText() const;
156 virtual bool isURLAttribute(Attribute*) const;
158 int maxResults() const { return m_maxResults; }
160 String defaultValue() const;
161 void setDefaultValue(const String&);
163 bool defaultChecked() const;
164 void setDefaultChecked(bool);
166 String accept() const;
167 void setAccept(const String&);
169 String accessKey() const;
170 void setAccessKey(const String&);
172 String align() const;
173 void setAlign(const String&);
176 void setAlt(const String&);
178 void setSize(unsigned);
181 void setSrc(const String&);
183 void setMaxLength(int);
185 String useMap() const;
186 void setUseMap(const String&);
188 bool autofilled() const { return m_autofilled; }
189 void setAutofilled(bool b = true) { m_autofilled = b; }
193 void cacheSelection(int s, int e) { cachedSelStart = s; cachedSelEnd = e; };
194 void addSearchResult();
197 Selection selection() const;
199 String constrainValue(const String& proposedValue) const;
201 virtual void didRestoreFromCache();
203 virtual void getSubresourceAttributeStrings(Vector<String>&) const;
206 virtual void willMoveToNewOwnerDocument();
207 virtual void didMoveToNewOwnerDocument();
213 bool storesValueSeparateFromAttribute() const;
214 String constrainValue(const String& proposedValue, int maxLen) const;
218 String m_originalValue;
226 OwnPtr<HTMLImageLoader> m_imageLoader;
228 RefPtr<FileList> m_fileList;
230 unsigned m_type : 4; // InputType
232 bool m_defaultChecked : 1;
233 bool m_useDefaultChecked : 1;
234 bool m_indeterminate : 1;
236 bool m_activeSubmit : 1;
237 AutoCompleteSetting m_autocomplete : 2;
238 bool m_autofilled : 1;