1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Dirk Mueller (mueller (at) kde.org) 5 * Copyright (C) 2004, 2005, 2006, 2007, 2010 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 30 namespace WebCore { 31 32 class FileList; 33 class HTMLDataListElement; 34 class HTMLOptionElement; 35 class InputType; 36 class KURL; 37 38 class HTMLInputElement : public HTMLTextFormControlElement, public InputElement { 39 public: 40 static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser); 41 virtual ~HTMLInputElement(); 42 43 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange); 44 45 virtual InputElement* toInputElement() { return this; } 46 47 bool autoComplete() const; 48 49 // For ValidityState 50 bool typeMismatch() const; 51 // valueMissing() ignores the specified string value for CHECKBOX and RADIO. 52 bool valueMissing(const String&) const; 53 bool patternMismatch(const String&) const; 54 bool tooLong(const String&, NeedsToCheckDirtyFlag) const; 55 bool rangeUnderflow(const String&) const; 56 bool rangeOverflow(const String&) const; 57 // Returns the minimum value for type=date, number, or range. Don't call this for other types. 58 double minimum() const; 59 // Returns the maximum value for type=date, number, or range. Don't call this for other types. 60 // This always returns a value which is >= minimum(). 61 double maximum() const; 62 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer. 63 // Returns false if there is no "allowed value step." 64 bool getAllowedValueStep(double*) const; 65 bool getAllowedValueStepWithDecimalPlaces(double*, unsigned*) const; 66 // For ValidityState. 67 bool stepMismatch(const String&) const; 68 String minimumString() const; 69 String maximumString() const; 70 String stepBaseString() const; 71 String stepString() const; 72 String typeMismatchText() const; 73 String valueMissingText() const; 74 75 // Implementations of HTMLInputElement::stepUp() and stepDown(). 76 void stepUp(int, ExceptionCode&); 77 void stepDown(int, ExceptionCode&); 78 void stepUp(ExceptionCode& ec) { stepUp(1, ec); } 79 void stepDown(ExceptionCode& ec) { stepDown(1, ec); } 80 // stepUp()/stepDown() for user-interaction. 81 void stepUpFromRenderer(int); 82 83 bool isTextButton() const; 84 85 virtual bool isRadioButton() const; 86 virtual bool isTextField() const; 87 virtual bool isSearchField() const; 88 virtual bool isInputTypeHidden() const; 89 virtual bool isPasswordField() const; 90 virtual bool isCheckbox() const; 91 92 // FIXME: It's highly likely that any call site calling this function should instead 93 // be using a different one. Many input elements behave like text fields, and in addition 94 // any unknown input type is treated as text. Consider, for example, isTextField or 95 // isTextField && !isPasswordField. 96 bool isText() const; 97 98 bool isEmailField() const; 99 bool isFileUpload() const; 100 bool isImageButton() const; 101 bool isNumberField() const; 102 bool isSubmitButton() const; 103 bool isTelephoneField() const; 104 bool isURLField() const; 105 106 #if ENABLE(INPUT_SPEECH) 107 virtual bool isSpeechEnabled() const; 108 #endif 109 110 bool checked() const { return m_isChecked; } 111 void setChecked(bool, bool sendChangeEvent = false); 112 113 // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state. 114 bool indeterminate() const { return m_isIndeterminate; } 115 void setIndeterminate(bool); 116 117 virtual int size() const; 118 119 void setType(const String&); 120 121 virtual String value() const; 122 virtual void setValue(const String&, bool sendChangeEvent = false); 123 virtual void setValueForUser(const String&); 124 // Checks if the specified string would be a valid value. 125 // We should not call this for types with no string value such as CHECKBOX and RADIO. 126 bool isValidValue(const String&) const; 127 128 virtual const String& suggestedValue() const; 129 void setSuggestedValue(const String&); 130 131 double valueAsDate() const; 132 void setValueAsDate(double, ExceptionCode&); 133 134 double valueAsNumber() const; 135 void setValueAsNumber(double, ExceptionCode&); 136 137 virtual String placeholder() const; 138 virtual void setPlaceholder(const String&); 139 140 String valueWithDefault() const; 141 142 virtual void setValueFromRenderer(const String&); 143 void setFileListFromRenderer(const Vector<String>&); 144 145 bool canHaveSelection() const; 146 virtual void select() { HTMLTextFormControlElement::select(); } 147 148 virtual bool rendererIsNeeded(RenderStyle*); 149 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 150 virtual void detach(); 151 152 // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making 153 // it private virtual in all classes and expose a public method in HTMLFormControlElement to call 154 // the private virtual method. 155 virtual bool isActivatedSubmit() const; 156 virtual void setActivatedSubmit(bool flag); 157 158 String altText() const; 159 160 int maxResults() const { return m_maxResults; } 161 162 String defaultValue() const; 163 void setDefaultValue(const String&); 164 165 void setDefaultName(const AtomicString&); 166 167 String accept() const; 168 String alt() const; 169 170 void setSize(unsigned); 171 172 KURL src() const; 173 174 virtual int maxLength() const; 175 void setMaxLength(int, ExceptionCode&); 176 177 bool multiple() const; 178 179 virtual bool isAutofilled() const { return m_isAutofilled; } 180 void setAutofilled(bool = true); 181 182 FileList* files(); 183 184 void addSearchResult(); 185 void onSearch(); 186 187 #if ENABLE(DATALIST) 188 HTMLElement* list() const; 189 HTMLOptionElement* selectedOption() const; 190 #endif 191 192 #if ENABLE(WCSS) 193 void setWapInputFormat(String& mask); 194 #endif 195 196 // These functions are public so they can be used in InputType classes. 197 // Otherwise, they would be private. 198 CheckedRadioButtons& checkedRadioButtons() const; 199 void handleBeforeTextInsertedEvent(Event*); 200 void updateCheckedRadioButtons(); 201 202 bool lastChangeWasUserEdit() const; 203 204 protected: 205 HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser); 206 207 virtual void defaultEventHandler(Event*); 208 209 private: 210 enum AutoCompleteSetting { Uninitialized, On, Off }; 211 212 virtual void willMoveToNewOwnerDocument(); 213 virtual void didMoveToNewOwnerDocument(); 214 215 virtual bool isKeyboardFocusable(KeyboardEvent*) const; 216 virtual bool isMouseFocusable() const; 217 virtual bool isEnumeratable() const; 218 virtual void updateFocusAppearance(bool restorePreviousSelection); 219 virtual void aboutToUnload(); 220 virtual bool shouldUseInputMethod() const; 221 222 virtual const AtomicString& formControlName() const; 223 224 // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state 225 virtual bool isChecked() const; 226 virtual bool isIndeterminate() const { return indeterminate(); } 227 228 virtual bool isTextFormControl() const { return isTextField(); } 229 230 virtual bool hasSpinButton() const; 231 virtual bool canTriggerImplicitSubmission() const { return isTextField(); } 232 233 virtual const AtomicString& formControlType() const; 234 235 virtual bool searchEventsShouldBeDispatched() const; 236 237 virtual bool saveFormControlState(String& value) const; 238 virtual void restoreFormControlState(const String&); 239 240 virtual bool canStartSelection() const; 241 242 virtual void accessKeyAction(bool sendToAnyElement); 243 244 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; 245 virtual void parseMappedAttribute(Attribute*); 246 virtual void finishParsingChildren(); 247 248 virtual void copyNonAttributeProperties(const Element* source); 249 250 virtual void attach(); 251 252 virtual bool appendFormData(FormDataList&, bool); 253 254 virtual bool isSuccessfulSubmitButton() const; 255 256 virtual void reset(); 257 258 virtual void* preDispatchEventHandler(Event*); 259 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch); 260 261 virtual bool isURLAttribute(Attribute*) const; 262 263 virtual void cacheSelection(int start, int end); 264 265 virtual String visibleValue() const; 266 virtual String convertFromVisibleValue(const String&) const; 267 virtual bool isAcceptableValue(const String&) const; 268 virtual String sanitizeValue(const String&) const; 269 virtual bool hasUnacceptableValue() const; 270 271 virtual bool isInRange() const; 272 virtual bool isOutOfRange() const; 273 274 virtual void documentDidBecomeActive(); 275 276 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; 277 278 bool needsActivationCallback(); 279 void registerForActivationCallbackIfNeeded(); 280 void unregisterForActivationCallbackIfNeeded(); 281 282 virtual bool supportsMaxLength() const { return isTextType(); } 283 bool isTextType() const; 284 285 virtual bool supportsPlaceholder() const; 286 virtual bool isEmptyValue() const { return value().isEmpty(); } 287 virtual bool isEmptySuggestedValue() const { return suggestedValue().isEmpty(); } 288 virtual void handleFocusEvent(); 289 virtual void handleBlurEvent(); 290 virtual int cachedSelectionStart() const { return m_data.cachedSelectionStart(); } 291 virtual int cachedSelectionEnd() const { return m_data.cachedSelectionEnd(); } 292 293 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } 294 virtual bool isRequiredFormControl() const; 295 virtual bool recalcWillValidate() const; 296 297 void updateType(); 298 299 // Helper for stepUp()/stepDown(). Adds step value * count to the current value. 300 void applyStep(double count, ExceptionCode&); 301 302 #if ENABLE(DATALIST) 303 HTMLDataListElement* dataList() const; 304 #endif 305 306 #if ENABLE(WCSS) 307 virtual InputElementData data() const { return m_data; } 308 #endif 309 310 InputElementData m_data; 311 short m_maxResults; 312 bool m_isChecked : 1; 313 bool m_reflectsCheckedAttribute : 1; 314 bool m_isIndeterminate : 1; 315 bool m_hasType : 1; 316 bool m_isActivatedSubmit : 1; 317 unsigned m_autocomplete : 2; // AutoCompleteSetting 318 bool m_isAutofilled : 1; 319 #if ENABLE(DATALIST) 320 bool m_hasNonEmptyList : 1; 321 #endif 322 bool m_stateRestored : 1; 323 bool m_parsingInProgress : 1; 324 OwnPtr<InputType> m_inputType; 325 }; 326 327 } //namespace 328 329 #endif 330