/* * 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, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef HTMLFormElement_h #define HTMLFormElement_h #include "CheckedRadioButtons.h" #include "FormState.h" #include "FormSubmission.h" #include "HTMLElement.h" #include #if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE) #include "Autocapitalize.h" #endif namespace WebCore { class Event; class FormAssociatedElement; class FormData; class HTMLFormControlElement; class HTMLFormControlsCollection; class HTMLImageElement; class HTMLInputElement; class TextEncoding; class HTMLFormElement final : public HTMLElement { public: static Ref create(Document&); static Ref create(const QualifiedName&, Document&); virtual ~HTMLFormElement(); Ref elements(); Ref elementsForNativeBindings(); Vector> namedElements(const AtomicString&); unsigned length() const; HTMLElement* item(unsigned index); String enctype() const { return m_attributes.encodingType(); } void setEnctype(const String&); String encoding() const { return m_attributes.encodingType(); } void setEncoding(const String& value) { setEnctype(value); } bool shouldAutocomplete() const; #if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE) WEBCORE_EXPORT bool autocorrect() const; void setAutocorrect(bool); WEBCORE_EXPORT WebAutocapitalizeType autocapitalizeType() const; const AtomicString& autocapitalize() const; void setAutocapitalize(const AtomicString&); #endif // FIXME: Should rename these two functions to say "form control" or "form-associated element" instead of "form element". void registerFormElement(FormAssociatedElement*); void removeFormElement(FormAssociatedElement*); void registerInvalidAssociatedFormControl(const HTMLFormControlElement&); void removeInvalidAssociatedFormControlIfNeeded(const HTMLFormControlElement&); void registerImgElement(HTMLImageElement*); void removeImgElement(HTMLImageElement*); void prepareForSubmission(Event*); // FIXME: This function doesn't only prepare, it sometimes calls submit() itself. void submit(); void submitFromJavaScript(); void reset(); void setDemoted(bool demoted) { m_wasDemoted = demoted; } void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger); bool formWouldHaveSecureSubmission(const String& url); String name() const; bool noValidate() const; String acceptCharset() const { return m_attributes.acceptCharset(); } void setAcceptCharset(const String&); String action() const; void setAction(const String&); String method() const; void setMethod(const String&); virtual String target() const override; bool wasUserSubmitted() const; HTMLFormControlElement* defaultButton() const; bool checkValidity(); #if ENABLE(REQUEST_AUTOCOMPLETE) enum class AutocompleteResult { Success, ErrorDisabled, ErrorCancel, ErrorInvalid, }; void requestAutocomplete(); void finishRequestAutocomplete(AutocompleteResult); #endif CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; } const Vector& associatedElements() const { return m_associatedElements; } const Vector& imageElements() const { return m_imageElements; } void getTextFieldValues(StringPairVector& fieldNamesAndValues) const; static HTMLFormElement* findClosestFormAncestor(const Element&); private: HTMLFormElement(const QualifiedName&, Document&); virtual bool rendererIsNeeded(const RenderStyle&) override; virtual InsertionNotificationRequest insertedInto(ContainerNode&) override; virtual void removedFrom(ContainerNode&) override; virtual void finishParsingChildren() override; virtual void handleLocalEvents(Event&) override; virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; virtual bool isURLAttribute(const Attribute&) const override; virtual void resumeFromDocumentSuspension() override; virtual void didMoveToNewDocument(Document* oldDocument) override; virtual void copyNonAttributePropertiesFromElement(const Element&) override; void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger); unsigned formElementIndexWithFormAttribute(Element*, unsigned rangeStart, unsigned rangeEnd); unsigned formElementIndex(FormAssociatedElement*); // Returns true if the submission should proceed. bool validateInteractively(Event*); // Validates each of the controls, and stores controls of which 'invalid' // event was not canceled to the specified vector. Returns true if there // are any invalid controls in this form. bool checkInvalidControlsAndCollectUnhandled(Vector>&); HTMLElement* elementFromPastNamesMap(const AtomicString&) const; void addToPastNamesMap(FormNamedItem*, const AtomicString& pastName); void assertItemCanBeInPastNamesMap(FormNamedItem*) const; void removeFromPastNamesMap(FormNamedItem*); virtual bool matchesValidPseudoClass() const override; virtual bool matchesInvalidPseudoClass() const override; void resetAssociatedFormControlElements(); typedef HashMap, FormNamedItem*> PastNamesMap; FormSubmission::Attributes m_attributes; std::unique_ptr m_pastNamesMap; CheckedRadioButtons m_checkedRadioButtons; unsigned m_associatedElementsBeforeIndex { 0 }; unsigned m_associatedElementsAfterIndex { 0 }; Vector m_associatedElements; Vector m_imageElements; HashSet m_invalidAssociatedFormControls; bool m_wasUserSubmitted { false }; bool m_isSubmittingOrPreparingForSubmission { false }; bool m_shouldSubmit { false }; bool m_isInResetFunction { false }; bool m_wasDemoted { false }; #if ENABLE(REQUEST_AUTOCOMPLETE) void requestAutocompleteTimerFired(); Vector> m_pendingAutocompleteEvents; Timer m_requestAutocompleteTimer; #endif }; } // namespace WebCore #endif // HTMLFormElement_h