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 VisibleSelection; 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 EMAIL, 55 NUMBER, 56 TELEPHONE, 57 URL 58 }; 59 60 enum AutoCompleteSetting { 61 Uninitialized, 62 On, 63 Off 64 }; 65 66 HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement* = 0); 67 virtual ~HTMLInputElement(); 68 endTagRequirement()69 virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } tagPriority()70 virtual int tagPriority() const { return 0; } 71 72 virtual bool isKeyboardFocusable(KeyboardEvent*) const; 73 virtual bool isMouseFocusable() const; isEnumeratable()74 virtual bool isEnumeratable() const { return inputType() != IMAGE; } 75 virtual void dispatchFocusEvent(); 76 virtual void dispatchBlurEvent(); 77 virtual void updateFocusAppearance(bool restorePreviousSelection); 78 virtual void aboutToUnload(); 79 virtual bool shouldUseInputMethod() const; 80 81 virtual const AtomicString& formControlName() const; 82 83 bool autoComplete() const; 84 85 // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state isChecked()86 virtual bool isChecked() const { return checked() && (inputType() == CHECKBOX || inputType() == RADIO); } isIndeterminate()87 virtual bool isIndeterminate() const { return indeterminate(); } 88 readOnly()89 bool readOnly() const { return isReadOnlyFormControl(); } 90 isTextFormControl()91 virtual bool isTextFormControl() const { return isTextField(); } 92 93 virtual bool valueMissing() const; 94 virtual bool patternMismatch() const; 95 isTextButton()96 bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; } isRadioButton()97 virtual bool isRadioButton() const { return m_type == RADIO; } isTextField()98 virtual bool isTextField() const { return m_type == TEXT || m_type == PASSWORD || m_type == SEARCH || m_type == ISINDEX || m_type == EMAIL || m_type == NUMBER || m_type == TELEPHONE || m_type == URL; } isSearchField()99 virtual bool isSearchField() const { return m_type == SEARCH; } isInputTypeHidden()100 virtual bool isInputTypeHidden() const { return m_type == HIDDEN; } isPasswordField()101 virtual bool isPasswordField() const { return m_type == PASSWORD; } 102 checked()103 bool checked() const { return m_checked; } 104 void setChecked(bool, bool sendChangeEvent = false); indeterminate()105 bool indeterminate() const { return m_indeterminate; } 106 void setIndeterminate(bool); 107 virtual int size() const; 108 virtual const AtomicString& formControlType() const; 109 void setType(const String&); 110 111 virtual String value() const; 112 virtual void setValue(const String&); 113 114 virtual String placeholder() const; 115 virtual void setPlaceholder(const String&); 116 117 virtual bool searchEventsShouldBeDispatched() const; 118 119 String valueWithDefault() const; 120 121 virtual void setValueFromRenderer(const String&); 122 void setFileListFromRenderer(const Vector<String>&); 123 124 virtual bool saveFormControlState(String& value) const; 125 virtual void restoreFormControlState(const String&); 126 127 virtual bool canStartSelection() const; 128 129 bool canHaveSelection() const; 130 int selectionStart() const; 131 int selectionEnd() const; 132 void setSelectionStart(int); 133 void setSelectionEnd(int); 134 virtual void select(); 135 void setSelectionRange(int start, int end); 136 137 virtual void accessKeyAction(bool sendToAnyElement); 138 139 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; 140 virtual void parseMappedAttribute(MappedAttribute*); 141 142 virtual void copyNonAttributeProperties(const Element* source); 143 144 virtual void attach(); 145 virtual bool rendererIsNeeded(RenderStyle*); 146 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 147 virtual void detach(); 148 virtual bool appendFormData(FormDataList&, bool); 149 150 virtual bool isSuccessfulSubmitButton() const; 151 virtual bool isActivatedSubmit() const; 152 virtual void setActivatedSubmit(bool flag); 153 inputType()154 InputType inputType() const { return static_cast<InputType>(m_type); } 155 void setInputType(const String&); 156 157 // Report if this input type uses height & width attributes respectHeightAndWidthAttrs()158 bool respectHeightAndWidthAttrs() const { return inputType() == IMAGE || inputType() == HIDDEN; } 159 160 virtual void reset(); 161 162 virtual void* preDispatchEventHandler(Event*); 163 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch); 164 virtual void defaultEventHandler(Event*); 165 166 String altText() const; 167 168 virtual bool isURLAttribute(Attribute*) const; 169 maxResults()170 int maxResults() const { return m_maxResults; } 171 172 String defaultValue() const; 173 void setDefaultValue(const String&); 174 175 bool defaultChecked() const; 176 void setDefaultChecked(bool); 177 178 void setDefaultName(const AtomicString&); 179 180 String accept() const; 181 void setAccept(const String&); 182 183 String accessKey() const; 184 void setAccessKey(const String&); 185 186 String align() const; 187 void setAlign(const String&); 188 189 String alt() const; 190 void setAlt(const String&); 191 192 void setSize(unsigned); 193 194 KURL src() const; 195 void setSrc(const String&); 196 197 int maxLength() const; 198 void setMaxLength(int); 199 200 bool multiple() const; 201 void setMultiple(bool); 202 203 String useMap() const; 204 void setUseMap(const String&); 205 isAutofilled()206 virtual bool isAutofilled() const { return m_autofilled; } 207 void setAutofilled(bool value = true); 208 209 FileList* files(); 210 211 virtual void cacheSelection(int start, int end); 212 void addSearchResult(); 213 void onSearch(); 214 215 VisibleSelection selection() const; 216 217 virtual String constrainValue(const String& proposedValue) const; 218 219 virtual void documentDidBecomeActive(); 220 221 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; 222 223 virtual bool willValidate() const; 224 225 virtual bool placeholderShouldBeVisible() const; 226 227 protected: 228 virtual void willMoveToNewOwnerDocument(); 229 virtual void didMoveToNewOwnerDocument(); 230 updatePlaceholderVisibility()231 void updatePlaceholderVisibility() 232 { 233 InputElement::updatePlaceholderVisibility(m_data, this, this, true); 234 } 235 236 private: 237 bool storesValueSeparateFromAttribute() const; 238 239 bool needsActivationCallback(); 240 void registerForActivationCallbackIfNeeded(); 241 void unregisterForActivationCallbackIfNeeded(); 242 isOptionalFormControl()243 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } 244 virtual bool isRequiredFormControl() const; 245 246 InputElementData m_data; 247 int m_xPos; 248 int m_yPos; 249 short m_maxResults; 250 OwnPtr<HTMLImageLoader> m_imageLoader; 251 RefPtr<FileList> m_fileList; 252 unsigned m_type : 5; // InputType 253 bool m_checked : 1; 254 bool m_defaultChecked : 1; 255 bool m_useDefaultChecked : 1; 256 bool m_indeterminate : 1; 257 bool m_haveType : 1; 258 bool m_activeSubmit : 1; 259 unsigned m_autocomplete : 2; // AutoCompleteSetting 260 bool m_autofilled : 1; 261 bool m_inited : 1; 262 }; 263 264 } //namespace 265 266 #endif 267