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 "InputElement.h"
29 #include <wtf/OwnPtr.h>
34 class HTMLImageLoader
;
38 class HTMLInputElement
: public HTMLFormControlElementWithState
, public InputElement
{
56 enum AutoCompleteSetting
{
62 HTMLInputElement(const QualifiedName
&, 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 virtual bool isTextField() const { return m_type
== TEXT
|| m_type
== PASSWORD
|| m_type
== SEARCH
|| m_type
== ISINDEX
; }
92 virtual 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 virtual int size() const;
101 virtual const AtomicString
& type() const;
102 void setType(const String
&);
104 virtual String
value() const;
105 virtual void setValue(const String
&);
107 virtual String
placeholderValue() const;
108 virtual bool searchEventsShouldBeDispatched() const;
110 String
valueWithDefault() const;
112 virtual void setValueFromRenderer(const String
&);
113 void setFileListFromRenderer(const Vector
<String
>&);
115 virtual bool saveState(String
& value
) const;
116 virtual void restoreState(const String
&);
118 virtual bool canStartSelection() const;
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
);
128 virtual void accessKeyAction(bool sendToAnyElement
);
130 virtual bool mapToEntry(const QualifiedName
& attrName
, MappedAttributeEntry
& result
) const;
131 virtual void parseMappedAttribute(MappedAttribute
*);
133 virtual void copyNonAttributeProperties(const Element
* source
);
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);
141 virtual bool isSuccessfulSubmitButton() const;
142 virtual bool isActivatedSubmit() const;
143 virtual void setActivatedSubmit(bool flag
);
145 InputType
inputType() const { return static_cast<InputType
>(m_type
); }
146 void setInputType(const String
&);
148 // Report if this input type uses height & width attributes
149 bool respectHeightAndWidthAttrs() const { return inputType() == IMAGE
|| inputType() == HIDDEN
; }
151 virtual void reset();
153 virtual void* preDispatchEventHandler(Event
*);
154 virtual void postDispatchEventHandler(Event
*, void* dataFromPreDispatch
);
155 virtual void defaultEventHandler(Event
*);
157 String
altText() const;
159 virtual bool isURLAttribute(Attribute
*) const;
161 int maxResults() const { return m_maxResults
; }
163 String
defaultValue() const;
164 void setDefaultValue(const String
&);
166 bool defaultChecked() const;
167 void setDefaultChecked(bool);
169 void setDefaultName(const AtomicString
&);
171 String
accept() const;
172 void setAccept(const String
&);
174 String
accessKey() const;
175 void setAccessKey(const String
&);
177 String
align() const;
178 void setAlign(const String
&);
181 void setAlt(const String
&);
183 void setSize(unsigned);
186 void setSrc(const String
&);
188 int maxLength() const;
189 void setMaxLength(int);
191 String
useMap() const;
192 void setUseMap(const String
&);
194 bool isAutofilled() const { return m_autofilled
; }
195 void setAutofilled(bool value
= true);
199 virtual void cacheSelection(int start
, int end
);
200 void addSearchResult();
203 Selection
selection() const;
205 virtual String
constrainValue(const String
& proposedValue
) const;
207 virtual void documentDidBecomeActive();
209 virtual void addSubresourceAttributeURLs(ListHashSet
<KURL
>&) const;
211 virtual bool willRespondToMouseClickEvents();
212 virtual void setDisabled(bool isDisabled
) { HTMLFormControlElement::setDisabled(inputType() == FILE || isDisabled
); }
214 virtual bool willValidate() const;
216 virtual bool placeholderShouldBeVisible() const;
219 virtual void willMoveToNewOwnerDocument();
220 virtual void didMoveToNewOwnerDocument();
223 bool storesValueSeparateFromAttribute() const;
225 bool needsActivationCallback();
226 void registerForActivationCallbackIfNeeded();
227 void unregisterForActivationCallbackIfNeeded();
229 InputElementData m_data
;
233 OwnPtr
<HTMLImageLoader
> m_imageLoader
;
234 RefPtr
<FileList
> m_fileList
;
235 unsigned m_type
: 4; // InputType
237 bool m_defaultChecked
: 1;
238 bool m_useDefaultChecked
: 1;
239 bool m_indeterminate
: 1;
241 bool m_activeSubmit
: 1;
242 unsigned m_autocomplete
: 2; // AutoCompleteSetting
243 bool m_autofilled
: 1;