#ifndef HTMLFormElement_h
#define HTMLFormElement_h
#include "FormState.h"
#include "FormSubmission.h"
#include "HTMLElement.h"
#include "RadioButtonGroups.h"
#include <memory>
#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<HTMLFormElement> create(Document&);
static Ref<HTMLFormElement> create(const QualifiedName&, Document&);
virtual ~HTMLFormElement();
Ref<HTMLFormControlsCollection> elements();
Ref<HTMLCollection> elementsForNativeBindings();
Vector<Ref<Element>> 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;
void setAutocomplete(const AtomicString&);
const AtomicString& autocomplete() 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
void registerFormElement(FormAssociatedElement*);
void removeFormElement(FormAssociatedElement*);
void registerInvalidAssociatedFormControl(const HTMLFormControlElement&);
void removeInvalidAssociatedFormControlIfNeeded(const HTMLFormControlElement&);
void registerImgElement(HTMLImageElement*);
void removeImgElement(HTMLImageElement*);
void prepareForSubmission(Event*); 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&);
String target() const final;
bool wasUserSubmitted() const;
HTMLFormControlElement* defaultButton() const;
void resetDefaultButton();
bool checkValidity();
#if ENABLE(REQUEST_AUTOCOMPLETE)
enum class AutocompleteResult {
Success,
ErrorDisabled,
ErrorCancel,
ErrorInvalid,
};
void requestAutocomplete();
void finishRequestAutocomplete(AutocompleteResult);
#endif
RadioButtonGroups& radioButtonGroups() { return m_radioButtonGroups; }
const Vector<FormAssociatedElement*>& associatedElements() const { return m_associatedElements; }
const Vector<HTMLImageElement*>& imageElements() const { return m_imageElements; }
void getTextFieldValues(StringPairVector& fieldNamesAndValues) const;
static HTMLFormElement* findClosestFormAncestor(const Element&);
private:
HTMLFormElement(const QualifiedName&, Document&);
bool rendererIsNeeded(const RenderStyle&) final;
InsertionNotificationRequest insertedInto(ContainerNode&) final;
void removedFrom(ContainerNode&) final;
void finishParsingChildren() final;
void handleLocalEvents(Event&) final;
void parseAttribute(const QualifiedName&, const AtomicString&) final;
bool isURLAttribute(const Attribute&) const final;
void resumeFromDocumentSuspension() final;
void didMoveToNewDocument(Document* oldDocument) final;
void copyNonAttributePropertiesFromElement(const Element&) final;
void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
unsigned formElementIndexWithFormAttribute(Element*, unsigned rangeStart, unsigned rangeEnd);
unsigned formElementIndex(FormAssociatedElement*);
bool validateInteractively(Event*);
bool checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<FormAssociatedElement>>&);
HTMLElement* elementFromPastNamesMap(const AtomicString&) const;
void addToPastNamesMap(FormNamedItem*, const AtomicString& pastName);
void assertItemCanBeInPastNamesMap(FormNamedItem*) const;
void removeFromPastNamesMap(FormNamedItem*);
bool matchesValidPseudoClass() const final;
bool matchesInvalidPseudoClass() const final;
typedef HashMap<RefPtr<AtomicStringImpl>, FormNamedItem*> PastNamesMap;
FormSubmission::Attributes m_attributes;
std::unique_ptr<PastNamesMap> m_pastNamesMap;
RadioButtonGroups m_radioButtonGroups;
mutable HTMLFormControlElement* m_defaultButton { nullptr };
unsigned m_associatedElementsBeforeIndex;
unsigned m_associatedElementsAfterIndex;
Vector<FormAssociatedElement*> m_associatedElements;
Vector<HTMLImageElement*> m_imageElements;
HashSet<const HTMLFormControlElement*> m_invalidAssociatedFormControls;
bool m_wasUserSubmitted;
bool m_isSubmittingOrPreparingForSubmission;
bool m_shouldSubmit;
bool m_isInResetFunction;
bool m_wasDemoted;
#if ENABLE(REQUEST_AUTOCOMPLETE)
void requestAutocompleteTimerFired();
Vector<RefPtr<Event>> m_pendingAutocompleteEvents;
Timer m_requestAutocompleteTimer;
#endif
};
}
#endif // HTMLFormElement_h