diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/HTMLInputElement.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/html/HTMLInputElement.h')
-rw-r--r-- | Source/WebCore/html/HTMLInputElement.h | 364 |
1 files changed, 183 insertions, 181 deletions
diff --git a/Source/WebCore/html/HTMLInputElement.h b/Source/WebCore/html/HTMLInputElement.h index 286b8a699..05393355e 100644 --- a/Source/WebCore/html/HTMLInputElement.h +++ b/Source/WebCore/html/HTMLInputElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2004-2017 Apple Inc. All rights reserved. * Copyright (C) 2012 Samsung Electronics. All rights reserved. * * This library is free software; you can redistribute it and/or @@ -22,12 +22,12 @@ * */ -#ifndef HTMLInputElement_h -#define HTMLInputElement_h +#pragma once #include "FileChooser.h" #include "HTMLTextFormControlElement.h" #include "StepRange.h" +#include <memory> #if PLATFORM(IOS) #include "DateComponents.h" @@ -35,52 +35,44 @@ namespace WebCore { -class CheckedRadioButtons; class DragData; class FileList; class HTMLDataListElement; class HTMLImageLoader; -class HTMLOptionElement; class Icon; class InputType; class ListAttributeTargetObserver; -class TextControlInnerTextElement; +class RadioButtonGroups; class URL; + struct DateTimeChooserParameters; struct InputElementClickState { - InputElementClickState() - : stateful(false) - , checked(false) - , indeterminate(false) - { } - bool stateful; - bool checked; - bool indeterminate; + bool stateful { false }; + bool checked { false }; + bool indeterminate { false }; RefPtr<HTMLInputElement> checkedRadioButton; }; class HTMLInputElement : public HTMLTextFormControlElement { public: - static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser); + static Ref<HTMLInputElement> create(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser); virtual ~HTMLInputElement(); - DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitspeechchange); - - virtual HTMLInputElement* toInputElement() override { return this; } - - virtual bool shouldAutocomplete() const override; + WEBCORE_EXPORT bool shouldAutocomplete() const final; // For ValidityState - virtual bool hasBadInput() const override; - virtual bool patternMismatch() const override; - virtual bool rangeUnderflow() const override; - virtual bool rangeOverflow() const override; - virtual bool stepMismatch() const override; - virtual bool tooLong() const override; - virtual bool typeMismatch() const override; - virtual bool valueMissing() const override; - virtual String validationMessage() const override; + bool hasBadInput() const final; + bool patternMismatch() const final; + bool rangeUnderflow() const final; + bool rangeOverflow() const final; + bool stepMismatch() const final; + bool tooShort() const final; + bool tooLong() const final; + bool typeMismatch() const final; + bool valueMissing() const final; + bool isValid() const final; + WEBCORE_EXPORT String validationMessage() const final; // Returns the minimum value for type=date, number, or range. Don't call this for other types. double minimum() const; @@ -93,24 +85,22 @@ public: StepRange createStepRange(AnyStepHandling) const; #if ENABLE(DATALIST_ELEMENT) - Decimal findClosestTickMarkValue(const Decimal&); + std::optional<Decimal> findClosestTickMarkValue(const Decimal&); #endif - // Implementations of HTMLInputElement::stepUp() and stepDown(). - void stepUp(int, ExceptionCode&); - void stepDown(int, ExceptionCode&); - void stepUp(ExceptionCode& ec) { stepUp(1, ec); } - void stepDown(ExceptionCode& ec) { stepDown(1, ec); } + WEBCORE_EXPORT ExceptionOr<void> stepUp(int = 1); + WEBCORE_EXPORT ExceptionOr<void> stepDown(int = 1); + // stepUp()/stepDown() for user-interaction. bool isSteppable() const; bool isTextButton() const; bool isRadioButton() const; - bool isTextField() const; - bool isSearchField() const; + WEBCORE_EXPORT bool isTextField() const; + WEBCORE_EXPORT bool isSearchField() const; bool isInputTypeHidden() const; - bool isPasswordField() const; + WEBCORE_EXPORT bool isPasswordField() const; bool isCheckbox() const; bool isRangeControl() const; @@ -122,63 +112,61 @@ public: // be using a different one. Many input elements behave like text fields, and in addition // any unknown input type is treated as text. Consider, for example, isTextField or // isTextField && !isPasswordField. - bool isText() const; + WEBCORE_EXPORT bool isText() const; - bool isEmailField() const; + WEBCORE_EXPORT bool isEmailField() const; bool isFileUpload() const; bool isImageButton() const; - bool isNumberField() const; + WEBCORE_EXPORT bool isNumberField() const; bool isSubmitButton() const; - bool isTelephoneField() const; - bool isURLField() const; - bool isDateField() const; - bool isDateTimeField() const; - bool isDateTimeLocalField() const; - bool isMonthField() const; - bool isTimeField() const; - bool isWeekField() const; - -#if ENABLE(INPUT_SPEECH) - bool isSpeechEnabled() const; -#endif + WEBCORE_EXPORT bool isTelephoneField() const; + WEBCORE_EXPORT bool isURLField() const; + WEBCORE_EXPORT bool isDateField() const; + WEBCORE_EXPORT bool isDateTimeField() const; + WEBCORE_EXPORT bool isDateTimeLocalField() const; + WEBCORE_EXPORT bool isMonthField() const; + WEBCORE_EXPORT bool isTimeField() const; + WEBCORE_EXPORT bool isWeekField() const; #if PLATFORM(IOS) DateComponents::Type dateType() const; #endif HTMLElement* containerElement() const; - virtual TextControlInnerTextElement* innerTextElement() const override; + + TextControlInnerTextElement* innerTextElement() const final; + RenderStyle createInnerTextStyle(const RenderStyle&) const override; + HTMLElement* innerBlockElement() const; HTMLElement* innerSpinButtonElement() const; + HTMLElement* capsLockIndicatorElement() const; HTMLElement* resultsButtonElement() const; HTMLElement* cancelButtonElement() const; -#if ENABLE(INPUT_SPEECH) - HTMLElement* speechButtonElement() const; -#endif HTMLElement* sliderThumbElement() const; HTMLElement* sliderTrackElement() const; - virtual HTMLElement* placeholderElement() const override; + HTMLElement* placeholderElement() const final; + WEBCORE_EXPORT HTMLElement* autoFillButtonElement() const; bool checked() const { return m_isChecked; } - void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent); + WEBCORE_EXPORT void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent); // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state. bool indeterminate() const { return m_isIndeterminate; } - void setIndeterminate(bool); + WEBCORE_EXPORT void setIndeterminate(bool); // shouldAppearChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state bool shouldAppearChecked() const; - virtual bool shouldAppearIndeterminate() const override; + bool matchesIndeterminatePseudoClass() const final; + bool shouldAppearIndeterminate() const final; - int size() const; + WEBCORE_EXPORT unsigned size() const; bool sizeShouldIncludeDecoration(int& preferredSize) const; float decorationWidth() const; - void setType(const String&); + WEBCORE_EXPORT void setType(const AtomicString&); - virtual String value() const override; - void setValue(const String&, ExceptionCode&, TextFieldEventBehavior = DispatchNoEvent); - void setValue(const String&, TextFieldEventBehavior = DispatchNoEvent); - void setValueForUser(const String&); + WEBCORE_EXPORT String value() const final; + WEBCORE_EXPORT ExceptionOr<void> setValue(const String&, TextFieldEventBehavior = DispatchNoEvent); + WEBCORE_EXPORT void setValueForUser(const String&); // Checks if the specified string would be a valid value. // We should not call this for types with no string value such as CHECKBOX and RADIO. bool isValidValue(const String&) const; @@ -191,34 +179,34 @@ public: // The value which is drawn by a renderer. String visibleValue() const; - const String& suggestedValue() const; - void setSuggestedValue(const String&); - - void setEditingValue(const String&); + WEBCORE_EXPORT void setEditingValue(const String&); - double valueAsDate() const; - void setValueAsDate(double, ExceptionCode&); + WEBCORE_EXPORT double valueAsDate() const; + WEBCORE_EXPORT ExceptionOr<void> setValueAsDate(double); - double valueAsNumber() const; - void setValueAsNumber(double, ExceptionCode&, TextFieldEventBehavior = DispatchNoEvent); + WEBCORE_EXPORT double valueAsNumber() const; + WEBCORE_EXPORT ExceptionOr<void> setValueAsNumber(double, TextFieldEventBehavior = DispatchNoEvent); String valueWithDefault() const; + // This function dispatches 'input' event for non-textfield types. Callers + // need to handle any DOM structure changes by event handlers, or need to + // delay the 'input' event with EventQueueScope. void setValueFromRenderer(const String&); bool canHaveSelection() const; - virtual bool rendererIsNeeded(const RenderStyle&) override; - virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override; - virtual void willAttachRenderers() override; - virtual void didAttachRenderers() override; - virtual void didDetachRenderers() override; + bool rendererIsNeeded(const RenderStyle&) final; + RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final; + void willAttachRenderers() final; + void didAttachRenderers() final; + void didDetachRenderers() final; // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making // it private virtual in all classes and expose a public method in HTMLFormControlElement to call // the private virtual method. - virtual bool isActivatedSubmit() const override; - virtual void setActivatedSubmit(bool flag) override; + bool isActivatedSubmit() const final; + void setActivatedSubmit(bool flag) final; String altText() const; @@ -227,29 +215,30 @@ public: int maxResults() const { return m_maxResults; } - String defaultValue() const; - void setDefaultValue(const String&); + WEBCORE_EXPORT String defaultValue() const; + WEBCORE_EXPORT void setDefaultValue(const String&); Vector<String> acceptMIMETypes(); Vector<String> acceptFileExtensions(); String accept() const; - String alt() const; + WEBCORE_EXPORT String alt() const; - void setSize(unsigned); - void setSize(unsigned, ExceptionCode&); + WEBCORE_EXPORT ExceptionOr<void> setSize(unsigned); URL src() const; - virtual int maxLength() const override; - void setMaxLength(int, ExceptionCode&); + unsigned effectiveMaxLength() const; bool multiple() const; - bool isAutofilled() const { return m_isAutofilled; } - void setAutofilled(bool = true); + bool isAutoFilled() const { return m_isAutoFilled; } + WEBCORE_EXPORT void setAutoFilled(bool = true); + + AutoFillButtonType autoFillButtonType() const { return (AutoFillButtonType)m_autoFillButtonType; } + WEBCORE_EXPORT void setShowAutoFillButton(AutoFillButtonType); - FileList* files(); - void setFiles(PassRefPtr<FileList>); + WEBCORE_EXPORT FileList* files(); + WEBCORE_EXPORT void setFiles(RefPtr<FileList>&&); #if ENABLE(DRAG_SUPPORT) // Returns true if the given DragData has more than one dropped files. @@ -268,9 +257,7 @@ public: void addSearchResult(); void onSearch(); - void updateClearButtonVisibility(); - - virtual bool willRespondToMouseClickEvents() override; + bool willRespondToMouseClickEvents() override; #if ENABLE(DATALIST_ELEMENT) HTMLElement* list() const; @@ -278,164 +265,180 @@ public: void listAttributeTargetChanged(); #endif + Vector<HTMLInputElement*> radioButtonGroup() const; HTMLInputElement* checkedRadioButtonForGroup() const; bool isInRequiredRadioButtonGroup(); + // Returns null if this isn't associated with any radio button group. + RadioButtonGroups* radioButtonGroups() const; // Functions for InputType classes. void setValueInternal(const String&, TextFieldEventBehavior); bool isTextFormControlFocusable() const; - bool isTextFormControlKeyboardFocusable(KeyboardEvent*) const; + bool isTextFormControlKeyboardFocusable(KeyboardEvent&) const; bool isTextFormControlMouseFocusable() const; bool valueAttributeWasUpdatedAfterParsing() const { return m_valueAttributeWasUpdatedAfterParsing; } void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); } -#if ENABLE(INPUT_TYPE_COLOR) - // For test purposes. - void selectColorInColorChooser(const Color&); -#endif + Color valueAsColor() const; // Returns transparent color if not type=color. + WEBCORE_EXPORT void selectColor(const Color&); // Does nothing if not type=color. Simulates user selection of color; intended for testing. String defaultToolTip() const; #if ENABLE(MEDIA_CAPTURE) - String capture() const; - void setCapture(const String& value); + MediaCaptureType mediaCaptureType() const; #endif - static const int maximumLength; + static const unsigned maxEffectiveLength; - unsigned height() const; - unsigned width() const; - void setHeight(unsigned); - void setWidth(unsigned); + WEBCORE_EXPORT unsigned height() const; + WEBCORE_EXPORT unsigned width() const; + WEBCORE_EXPORT void setHeight(unsigned); + WEBCORE_EXPORT void setWidth(unsigned); - virtual void blur() override; + void blur() final; void defaultBlur(); - virtual const AtomicString& name() const override; + const AtomicString& name() const final; void endEditing(); + void setSpellcheckDisabledExceptTextReplacement(bool disabled) { m_isSpellcheckDisabledExceptTextReplacement = disabled; } + bool isSpellcheckDisabledExceptTextReplacement() const { return m_isSpellcheckDisabledExceptTextReplacement; } + static Vector<FileChooserFileInfo> filesFromFileInputFormControlState(const FormControlState&); - virtual bool matchesReadOnlyPseudoClass() const override; - virtual bool matchesReadWritePseudoClass() const override; - virtual void setRangeText(const String& replacement, ExceptionCode&) override; - virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionCode&) override; + bool matchesReadWritePseudoClass() const final; + WEBCORE_EXPORT ExceptionOr<void> setRangeText(const String& replacement) final; + WEBCORE_EXPORT ExceptionOr<void> setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode) final; - bool hasImageLoader() const { return m_imageLoader; } - HTMLImageLoader* imageLoader(); + HTMLImageLoader* imageLoader() { return m_imageLoader.get(); } + HTMLImageLoader& ensureImageLoader(); #if ENABLE(DATE_AND_TIME_INPUT_TYPES) bool setupDateTimeChooserParameters(DateTimeChooserParameters&); #endif + void capsLockStateMayHaveChanged(); + + bool shouldTruncateText(const RenderStyle&) const; + + ExceptionOr<int> selectionStartForBindings() const; + ExceptionOr<void> setSelectionStartForBindings(int); + + ExceptionOr<int> selectionEndForBindings() const; + ExceptionOr<void> setSelectionEndForBindings(int); + + ExceptionOr<String> selectionDirectionForBindings() const; + ExceptionOr<void> setSelectionDirectionForBindings(const String&); + + ExceptionOr<void> setSelectionRangeForBindings(int start, int end, const String& direction); + protected: HTMLInputElement(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser); - virtual void defaultEventHandler(Event*) override; + void defaultEventHandler(Event&) override; private: enum AutoCompleteSetting { Uninitialized, On, Off }; - // FIXME: Author shadows should be allowed - // https://bugs.webkit.org/show_bug.cgi?id=92608 - virtual bool areAuthorShadowsAllowed() const override { return false; } - - virtual void didAddUserAgentShadowRoot(ShadowRoot*) override; + void didAddUserAgentShadowRoot(ShadowRoot*) final; - virtual void willChangeForm() override; - virtual void didChangeForm() override; - virtual InsertionNotificationRequest insertedInto(ContainerNode&) override; - virtual void removedFrom(ContainerNode&) override; - virtual void didMoveToNewDocument(Document* oldDocument) override; + void willChangeForm() final; + void didChangeForm() final; + InsertionNotificationRequest insertedInto(ContainerNode&) final; + void finishedInsertingSubtree() final; + void removedFrom(ContainerNode&) final; + void didMoveToNewDocument(Document& oldDocument) final; - virtual bool hasCustomFocusLogic() const override; - virtual bool isKeyboardFocusable(KeyboardEvent*) const override; - virtual bool isMouseFocusable() const override; - virtual bool isEnumeratable() const override; - virtual bool supportLabels() const override; - virtual void updateFocusAppearance(bool restorePreviousSelection) override; - virtual bool shouldUseInputMethod() override final; + bool hasCustomFocusLogic() const final; + bool isKeyboardFocusable(KeyboardEvent&) const final; + bool isMouseFocusable() const final; + bool isEnumeratable() const final; + bool supportLabels() const final; + void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode) final; + bool shouldUseInputMethod() final; - virtual bool isTextFormControl() const override { return isTextField(); } + bool isTextFormControl() const final { return isTextField(); } - virtual bool canTriggerImplicitSubmission() const override { return isTextField(); } + bool canTriggerImplicitSubmission() const final { return isTextField(); } - virtual const AtomicString& formControlType() const override; + const AtomicString& formControlType() const final; - virtual bool shouldSaveAndRestoreFormControlState() const override; - virtual FormControlState saveFormControlState() const override; - virtual void restoreFormControlState(const FormControlState&) override; + bool shouldSaveAndRestoreFormControlState() const final; + FormControlState saveFormControlState() const final; + void restoreFormControlState(const FormControlState&) final; - virtual bool canStartSelection() const override; + bool canStartSelection() const final; - virtual void accessKeyAction(bool sendMouseEvents) override; + void accessKeyAction(bool sendMouseEvents) final; - virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; - virtual bool isPresentationAttribute(const QualifiedName&) const override; - virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override; - virtual void finishParsingChildren() override; + void parseAttribute(const QualifiedName&, const AtomicString&) final; + bool isPresentationAttribute(const QualifiedName&) const final; + void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) final; + void finishParsingChildren() final; + void parserDidSetAttributes() final; - virtual void copyNonAttributePropertiesFromElement(const Element&) override; + void copyNonAttributePropertiesFromElement(const Element&) final; - virtual bool appendFormData(FormDataList&, bool) override; + bool appendFormData(FormDataList&, bool) final; - virtual bool isSuccessfulSubmitButton() const override; + bool isSuccessfulSubmitButton() const final; + bool matchesDefaultPseudoClass() const final; - virtual void reset() override; + void reset() final; - virtual bool isURLAttribute(const Attribute&) const override; - virtual bool isInRange() const override; - virtual bool isOutOfRange() const override; + bool isURLAttribute(const Attribute&) const final; + bool isInRange() const final; + bool isOutOfRange() const final; - virtual void documentDidResumeFromPageCache() override; + void resumeFromDocumentSuspension() final; #if ENABLE(INPUT_TYPE_COLOR) - virtual void documentWillSuspendForPageCache() override; + void prepareForDocumentSuspension() final; #endif - virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const override; + void addSubresourceAttributeURLs(ListHashSet<URL>&) const final; bool needsSuspensionCallback(); void registerForSuspensionCallbackIfNeeded(); void unregisterForSuspensionCallbackIfNeeded(); + bool supportsMinLength() const { return isTextType(); } bool supportsMaxLength() const { return isTextType(); } bool isTextType() const; - bool tooLong(const String&, NeedsToCheckDirtyFlag) const; + bool tooShort(StringView, NeedsToCheckDirtyFlag) const; + bool tooLong(StringView, NeedsToCheckDirtyFlag) const; - virtual bool supportsPlaceholder() const override; - virtual void updatePlaceholderText() override; - virtual bool isEmptyValue() const override { return innerTextValue().isEmpty(); } - virtual bool isEmptySuggestedValue() const override { return suggestedValue().isEmpty(); } - virtual void handleFocusEvent(Node* oldFocusedNode, FocusDirection) override; - virtual void handleBlurEvent() override; + bool supportsPlaceholder() const final; + void updatePlaceholderText() final; + bool isEmptyValue() const final; + void handleFocusEvent(Node* oldFocusedNode, FocusDirection) final; + void handleBlurEvent() final; - virtual bool isOptionalFormControl() const override { return !isRequiredFormControl(); } - virtual bool isRequiredFormControl() const override; - virtual bool recalcWillValidate() const override; - virtual void requiredAttributeChanged() override; + bool isOptionalFormControl() const final { return !isRequiredFormControl(); } + bool isRequiredFormControl() const final; + bool computeWillValidate() const final; + void requiredAttributeChanged() final; + void initializeInputType(); void updateType(); + void runPostTypeUpdateTasks(); - virtual void subtreeHasChanged() override; + void subtreeHasChanged() final; #if ENABLE(DATALIST_ELEMENT) void resetListAttributeTargetObserver(); #endif - void parseMaxLengthAttribute(const AtomicString&); + void maxLengthAttributeChanged(const AtomicString& newValue); + void minLengthAttributeChanged(const AtomicString& newValue); void updateValueIfNeeded(); - // Returns null if this isn't associated with any radio button group. - CheckedRadioButtons* checkedRadioButtons() const; void addToRadioButtonGroup(); void removeFromRadioButtonGroup(); AtomicString m_name; String m_valueIfDirty; - String m_suggestedValue; - int m_size; - int m_maxLength; + unsigned m_size; short m_maxResults; bool m_isChecked : 1; bool m_reflectsCheckedAttribute : 1; @@ -443,7 +446,8 @@ private: bool m_hasType : 1; bool m_isActivatedSubmit : 1; unsigned m_autocomplete : 2; // AutoCompleteSetting - bool m_isAutofilled : 1; + bool m_isAutoFilled : 1; + unsigned m_autoFillButtonType : 2; // AutoFillButtonType; #if ENABLE(DATALIST_ELEMENT) bool m_hasNonEmptyList : 1; #endif @@ -455,17 +459,15 @@ private: #if ENABLE(TOUCH_EVENTS) bool m_hasTouchEventHandler : 1; #endif + bool m_isSpellcheckDisabledExceptTextReplacement : 1; std::unique_ptr<InputType> m_inputType; // The ImageLoader must be owned by this element because the loader code assumes // that it lives as long as its owning element lives. If we move the loader into // the ImageInput object we may delete the loader while this element lives on. - OwnPtr<HTMLImageLoader> m_imageLoader; + std::unique_ptr<HTMLImageLoader> m_imageLoader; #if ENABLE(DATALIST_ELEMENT) - OwnPtr<ListAttributeTargetObserver> m_listAttributeTargetObserver; + std::unique_ptr<ListAttributeTargetObserver> m_listAttributeTargetObserver; #endif }; -NODE_TYPE_CASTS(HTMLInputElement) - -} //namespace -#endif +} |