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, 2010 Apple Inc. All rights reserved. 6 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 * 23 */ 24 25 #ifndef HTMLInputElement_h 26 #define HTMLInputElement_h 27 28 #include "core/html/HTMLTextFormControlElement.h" 29 #include "core/html/forms/StepRange.h" 30 #include "platform/FileChooser.h" 31 32 namespace blink { 33 34 class AXObject; 35 class DragData; 36 class ExceptionState; 37 class FileList; 38 class HTMLDataListElement; 39 class HTMLImageLoader; 40 class HTMLOptionElement; 41 class InputType; 42 class InputTypeView; 43 class KURL; 44 class ListAttributeTargetObserver; 45 class RadioButtonGroupScope; 46 struct DateTimeChooserParameters; 47 48 class HTMLInputElement : public HTMLTextFormControlElement { 49 DEFINE_WRAPPERTYPEINFO(); 50 public: 51 static PassRefPtrWillBeRawPtr<HTMLInputElement> create(Document&, HTMLFormElement*, bool createdByParser); 52 virtual ~HTMLInputElement(); 53 virtual void trace(Visitor*) OVERRIDE; 54 55 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange); 56 57 virtual bool shouldAutocomplete() const OVERRIDE FINAL; 58 59 // For ValidityState 60 virtual bool hasBadInput() const OVERRIDE FINAL; 61 virtual bool patternMismatch() const OVERRIDE FINAL; 62 virtual bool rangeUnderflow() const OVERRIDE FINAL; 63 virtual bool rangeOverflow() const OVERRIDE FINAL; 64 virtual bool stepMismatch() const OVERRIDE FINAL; 65 virtual bool tooLong() const OVERRIDE FINAL; 66 virtual bool typeMismatch() const OVERRIDE FINAL; 67 virtual bool valueMissing() const OVERRIDE FINAL; 68 virtual String validationMessage() const OVERRIDE FINAL; 69 70 // Returns the minimum value for type=date, number, or range. Don't call this for other types. 71 double minimum() const; 72 // Returns the maximum value for type=date, number, or range. Don't call this for other types. 73 // This always returns a value which is >= minimum(). 74 double maximum() const; 75 // Sets the "allowed value step" defined in the HTML spec to the specified double pointer. 76 // Returns false if there is no "allowed value step." 77 bool getAllowedValueStep(Decimal*) const; 78 StepRange createStepRange(AnyStepHandling) const; 79 80 Decimal findClosestTickMarkValue(const Decimal&); 81 82 // Implementations of HTMLInputElement::stepUp() and stepDown(). 83 void stepUp(int, ExceptionState&); 84 void stepDown(int, ExceptionState&); 85 // stepUp()/stepDown() for user-interaction. 86 bool isSteppable() const; 87 88 // Returns true if the type is button, reset, or submit. 89 bool isTextButton() const; 90 // Returns true if the type is email, number, password, search, tel, text, 91 // or url. 92 bool isTextField() const; 93 checked()94 bool checked() const { return m_isChecked; } 95 void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent); 96 97 // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state. indeterminate()98 bool indeterminate() const { return m_isIndeterminate; } 99 void setIndeterminate(bool); 100 // shouldAppearChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state 101 bool shouldAppearChecked() const; 102 virtual bool shouldAppearIndeterminate() const OVERRIDE; 103 104 int size() const; 105 bool sizeShouldIncludeDecoration(int& preferredSize) const; 106 107 void setType(const AtomicString&); 108 109 virtual String value() const OVERRIDE; 110 void setValue(const String&, ExceptionState&, TextFieldEventBehavior = DispatchNoEvent); 111 void setValue(const String&, TextFieldEventBehavior = DispatchNoEvent); 112 void setValueForUser(const String&); 113 // Checks if the specified string would be a valid value. 114 // We should not call this for types with no string value such as CHECKBOX and RADIO. 115 bool isValidValue(const String&) const; hasDirtyValue()116 bool hasDirtyValue() const { return !m_valueIfDirty.isNull(); }; 117 118 String sanitizeValue(const String&) const; 119 120 String localizeValue(const String&) const; 121 122 const String& suggestedValue() const; 123 void setSuggestedValue(const String&); 124 125 void setEditingValue(const String&); 126 127 double valueAsDate(bool& isNull) const; 128 void setValueAsDate(double, ExceptionState&); 129 130 double valueAsNumber() const; 131 void setValueAsNumber(double, ExceptionState&, TextFieldEventBehavior = DispatchNoEvent); 132 133 String valueWithDefault() const; 134 135 void setValueFromRenderer(const String&); 136 137 int selectionStartForBinding(ExceptionState&) const; 138 int selectionEndForBinding(ExceptionState&) const; 139 String selectionDirectionForBinding(ExceptionState&) const; 140 void setSelectionStartForBinding(int, ExceptionState&); 141 void setSelectionEndForBinding(int, ExceptionState&); 142 void setSelectionDirectionForBinding(const String&, ExceptionState&); 143 void setSelectionRangeForBinding(int start, int end, ExceptionState&); 144 void setSelectionRangeForBinding(int start, int end, const String& direction, ExceptionState&); 145 146 virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE FINAL; 147 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE; 148 virtual void detach(const AttachContext& = AttachContext()) OVERRIDE FINAL; 149 virtual void updateFocusAppearance(bool restorePreviousSelection) OVERRIDE FINAL; 150 151 // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making 152 // it private virtual in all classes and expose a public method in HTMLFormControlElement to call 153 // the private virtual method. 154 virtual bool isActivatedSubmit() const OVERRIDE FINAL; 155 virtual void setActivatedSubmit(bool flag) OVERRIDE FINAL; 156 157 String altText() const; 158 maxResults()159 int maxResults() const { return m_maxResults; } 160 161 const AtomicString& defaultValue() const; 162 163 Vector<String> acceptMIMETypes(); 164 Vector<String> acceptFileExtensions(); 165 const AtomicString& alt() const; 166 167 void setSize(unsigned); 168 void setSize(unsigned, ExceptionState&); 169 170 KURL src() const; 171 172 int maxLength() const; 173 void setMaxLength(int, ExceptionState&); 174 175 bool multiple() const; 176 177 FileList* files(); 178 void setFiles(PassRefPtrWillBeRawPtr<FileList>); 179 180 // Returns true if the given DragData has more than one dropped files. 181 bool receiveDroppedFiles(const DragData*); 182 183 String droppedFileSystemId(); 184 185 // These functions are used for rendering the input active during a 186 // drag-and-drop operation. 187 bool canReceiveDroppedFiles() const; 188 void setCanReceiveDroppedFiles(bool); 189 190 void onSearch(); 191 192 void updateClearButtonVisibility(); 193 194 virtual bool willRespondToMouseClickEvents() OVERRIDE; 195 196 HTMLElement* list() const; 197 HTMLDataListElement* dataList() const; 198 bool hasValidDataListOptions() const; 199 void listAttributeTargetChanged(); 200 201 HTMLInputElement* checkedRadioButtonForGroup(); 202 bool isInRequiredRadioButtonGroup(); 203 204 // Functions for InputType classes. 205 void setValueInternal(const String&, TextFieldEventBehavior); valueAttributeWasUpdatedAfterParsing()206 bool valueAttributeWasUpdatedAfterParsing() const { return m_valueAttributeWasUpdatedAfterParsing; } 207 void updateView(); needsToUpdateViewValue()208 bool needsToUpdateViewValue() const { return m_needsToUpdateViewValue; } 209 virtual void setInnerEditorValue(const String&) OVERRIDE; 210 cacheSelectionInResponseToSetValue(int caretOffset)211 void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); } 212 213 // For test purposes. 214 void selectColorInColorChooser(const Color&); 215 void endColorChooser(); 216 217 String defaultToolTip() const; 218 219 static const int maximumLength; 220 221 unsigned height() const; 222 unsigned width() const; 223 void setHeight(unsigned); 224 void setWidth(unsigned); 225 226 virtual void blur() OVERRIDE FINAL; 227 void defaultBlur(); 228 229 virtual const AtomicString& name() const OVERRIDE FINAL; 230 231 void beginEditing(); 232 void endEditing(); 233 234 static Vector<FileChooserFileInfo> filesFromFileInputFormControlState(const FormControlState&); 235 236 virtual bool matchesReadOnlyPseudoClass() const OVERRIDE FINAL; 237 virtual bool matchesReadWritePseudoClass() const OVERRIDE FINAL; 238 virtual void setRangeText(const String& replacement, ExceptionState&) OVERRIDE FINAL; 239 virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionState&) OVERRIDE FINAL; 240 hasImageLoader()241 bool hasImageLoader() const { return m_imageLoader; } 242 HTMLImageLoader* imageLoader(); 243 244 bool setupDateTimeChooserParameters(DateTimeChooserParameters&); 245 246 bool supportsInputModeAttribute() const; 247 248 void setShouldRevealPassword(bool value); shouldRevealPassword()249 bool shouldRevealPassword() const { return m_shouldRevealPassword; } 250 AXObject* popupRootAXObject(); 251 virtual void didNotifySubtreeInsertionsToDocument() OVERRIDE; 252 253 protected: 254 HTMLInputElement(Document&, HTMLFormElement*, bool createdByParser); 255 256 virtual void defaultEventHandler(Event*) OVERRIDE; 257 258 private: 259 enum AutoCompleteSetting { Uninitialized, On, Off }; 260 261 virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE FINAL; 262 virtual void willAddFirstAuthorShadowRoot() OVERRIDE FINAL; 263 264 virtual void willChangeForm() OVERRIDE FINAL; 265 virtual void didChangeForm() OVERRIDE FINAL; 266 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; 267 virtual void removedFrom(ContainerNode*) OVERRIDE FINAL; 268 virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE FINAL; 269 virtual void removeAllEventListeners() OVERRIDE FINAL; 270 271 virtual bool hasCustomFocusLogic() const OVERRIDE FINAL; 272 virtual bool isKeyboardFocusable() const OVERRIDE FINAL; 273 virtual bool shouldShowFocusRingOnMouseFocus() const OVERRIDE FINAL; 274 virtual bool isEnumeratable() const OVERRIDE FINAL; 275 virtual bool isInteractiveContent() const OVERRIDE FINAL; 276 virtual bool supportLabels() const OVERRIDE FINAL; 277 isTextFormControl()278 virtual bool isTextFormControl() const OVERRIDE FINAL { return isTextField(); } 279 canTriggerImplicitSubmission()280 virtual bool canTriggerImplicitSubmission() const OVERRIDE FINAL { return isTextField(); } 281 282 virtual const AtomicString& formControlType() const OVERRIDE FINAL; 283 284 virtual bool shouldSaveAndRestoreFormControlState() const OVERRIDE FINAL; 285 virtual FormControlState saveFormControlState() const OVERRIDE FINAL; 286 virtual void restoreFormControlState(const FormControlState&) OVERRIDE FINAL; 287 288 virtual bool canStartSelection() const OVERRIDE FINAL; 289 290 virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE FINAL; 291 292 virtual void attributeWillChange(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue) OVERRIDE; 293 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 294 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE FINAL; 295 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE FINAL; 296 virtual void finishParsingChildren() OVERRIDE FINAL; 297 298 virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE FINAL; 299 300 virtual void attach(const AttachContext& = AttachContext()) OVERRIDE FINAL; 301 302 virtual bool appendFormData(FormDataList&, bool) OVERRIDE FINAL; 303 virtual String resultForDialogSubmit() OVERRIDE FINAL; 304 305 virtual bool canBeSuccessfulSubmitButton() const OVERRIDE FINAL; 306 307 virtual void resetImpl() OVERRIDE FINAL; 308 virtual bool supportsAutofocus() const OVERRIDE FINAL; 309 310 virtual void* preDispatchEventHandler(Event*) OVERRIDE FINAL; 311 virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch) OVERRIDE FINAL; 312 313 virtual bool isURLAttribute(const Attribute&) const OVERRIDE FINAL; 314 virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE FINAL; 315 virtual const QualifiedName& subResourceAttributeName() const OVERRIDE FINAL; 316 virtual bool isInRange() const OVERRIDE FINAL; 317 virtual bool isOutOfRange() const OVERRIDE FINAL; 318 319 bool tooLong(const String&, NeedsToCheckDirtyFlag) const; 320 321 virtual bool supportsPlaceholder() const OVERRIDE FINAL; 322 virtual void updatePlaceholderText() OVERRIDE FINAL; isEmptyValue()323 virtual bool isEmptyValue() const OVERRIDE FINAL { return innerEditorValue().isEmpty(); } isEmptySuggestedValue()324 virtual bool isEmptySuggestedValue() const OVERRIDE FINAL { return suggestedValue().isEmpty(); } 325 virtual void handleFocusEvent(Element* oldFocusedElement, FocusType) OVERRIDE FINAL; 326 virtual void handleBlurEvent() OVERRIDE FINAL; 327 virtual void dispatchFocusInEvent(const AtomicString& eventType, Element* oldFocusedElement, FocusType) OVERRIDE FINAL; 328 isOptionalFormControl()329 virtual bool isOptionalFormControl() const OVERRIDE FINAL { return !isRequiredFormControl(); } 330 virtual bool isRequiredFormControl() const OVERRIDE FINAL; 331 virtual bool recalcWillValidate() const OVERRIDE FINAL; 332 virtual void requiredAttributeChanged() OVERRIDE FINAL; 333 334 void updateType(); 335 336 virtual void subtreeHasChanged() OVERRIDE FINAL; 337 338 void setListAttributeTargetObserver(PassOwnPtrWillBeRawPtr<ListAttributeTargetObserver>); 339 void resetListAttributeTargetObserver(); 340 void parseMaxLengthAttribute(const AtomicString&); 341 void updateValueIfNeeded(); 342 343 // Returns null if this isn't associated with any radio button group. 344 RadioButtonGroupScope* radioButtonGroupScope() const; 345 void addToRadioButtonGroup(); 346 void removeFromRadioButtonGroup(); 347 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 348 virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE; 349 #endif 350 351 virtual bool shouldDispatchFormControlChangeEvent(String&, String&) OVERRIDE; 352 353 AtomicString m_name; 354 String m_valueIfDirty; 355 String m_suggestedValue; 356 int m_size; 357 int m_maxLength; 358 short m_maxResults; 359 bool m_isChecked : 1; 360 bool m_reflectsCheckedAttribute : 1; 361 bool m_isIndeterminate : 1; 362 bool m_isActivatedSubmit : 1; 363 unsigned m_autocomplete : 2; // AutoCompleteSetting 364 bool m_hasNonEmptyList : 1; 365 bool m_stateRestored : 1; 366 bool m_parsingInProgress : 1; 367 bool m_valueAttributeWasUpdatedAfterParsing : 1; 368 bool m_canReceiveDroppedFiles : 1; 369 bool m_hasTouchEventHandler : 1; 370 bool m_shouldRevealPassword : 1; 371 bool m_needsToUpdateViewValue : 1; 372 RefPtrWillBeMember<InputType> m_inputType; 373 RefPtrWillBeMember<InputTypeView> m_inputTypeView; 374 // The ImageLoader must be owned by this element because the loader code assumes 375 // that it lives as long as its owning element lives. If we move the loader into 376 // the ImageInput object we may delete the loader while this element lives on. 377 OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader; 378 OwnPtrWillBeMember<ListAttributeTargetObserver> m_listAttributeTargetObserver; 379 }; 380 381 } // namespace blink 382 383 #endif // HTMLInputElement_h 384