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, 2008, 2009, 2010 Apple Inc. All rights reserved.
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.
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.
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.
24 #ifndef HTMLFormElement_h
25 #define HTMLFormElement_h
27 #include "core/html/HTMLElement.h"
28 #include "core/html/HTMLFormControlElement.h"
29 #include "core/html/forms/RadioButtonGroupScope.h"
30 #include "core/loader/FormSubmission.h"
31 #include "wtf/OwnPtr.h"
32 #include "wtf/WeakPtr.h"
37 class FormAssociatedElement;
38 class GenericEventQueue;
39 class HTMLFormControlElement;
40 class HTMLFormControlsCollection;
41 class HTMLImageElement;
42 class RadioNodeListOrElement;
44 class HTMLFormElement final : public HTMLElement {
45 DEFINE_WRAPPERTYPEINFO();
47 static PassRefPtrWillBeRawPtr<HTMLFormElement> create(Document&);
48 virtual ~HTMLFormElement();
49 virtual void trace(Visitor*) override;
51 void setNeedsValidityCheck();
53 PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> elements();
54 void getNamedElements(const AtomicString&, WillBeHeapVector<RefPtrWillBeMember<Element>>&);
56 unsigned length() const;
57 HTMLElement* item(unsigned index);
59 String enctype() const { return m_attributes.encodingType(); }
60 void setEnctype(const AtomicString&);
62 String encoding() const { return m_attributes.encodingType(); }
63 void setEncoding(const AtomicString& value) { setEnctype(value); }
65 bool shouldAutocomplete() const;
67 void associate(FormAssociatedElement&);
68 void disassociate(FormAssociatedElement&);
69 void associate(HTMLImageElement&);
70 void disassociate(HTMLImageElement&);
72 WeakPtr<HTMLFormElement> createWeakPtr();
74 void didAssociateByParser();
76 void prepareForSubmission(Event*);
78 void submitFromJavaScript();
81 void setDemoted(bool);
83 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
87 bool noValidate() const;
89 const AtomicString& action() const;
91 String method() const;
92 void setMethod(const AtomicString&);
94 bool wasUserSubmitted() const;
96 HTMLFormControlElement* defaultButton() const;
99 bool reportValidity();
100 virtual bool matchesValidityPseudoClasses() const override final;
101 virtual bool isValidElement() override final;
103 enum AutocompleteResult {
104 AutocompleteResultSuccess,
105 AutocompleteResultErrorDisabled,
106 AutocompleteResultErrorCancel,
107 AutocompleteResultErrorInvalid,
110 void requestAutocomplete();
111 void finishRequestAutocomplete(AutocompleteResult);
113 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocomplete);
114 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocompleteerror);
116 RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; }
118 const FormAssociatedElement::List& associatedElements() const;
119 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>& imageElements();
121 void anonymousNamedGetter(const AtomicString& name, RadioNodeListOrElement&);
124 explicit HTMLFormElement(Document&);
126 virtual bool rendererIsNeeded(const RenderStyle&) override;
127 virtual InsertionNotificationRequest insertedInto(ContainerNode*) override;
128 virtual void removedFrom(ContainerNode*) override;
129 virtual void finishParsingChildren() override;
131 virtual void handleLocalEvents(Event*) override;
133 virtual void attributeWillChange(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue) override;
134 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
135 virtual bool isURLAttribute(const Attribute&) const override;
136 virtual bool hasLegalLinkAttribute(const QualifiedName&) const override;
138 virtual bool shouldRegisterAsNamedItem() const override { return true; }
140 virtual void copyNonAttributePropertiesFromElement(const Element&) override;
142 void submitDialog(PassRefPtrWillBeRawPtr<FormSubmission>);
143 void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
145 void scheduleFormSubmission(PassRefPtrWillBeRawPtr<FormSubmission>);
147 void collectAssociatedElements(Node& root, FormAssociatedElement::List&) const;
148 void collectImageElements(Node& root, WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>&);
150 // Returns true if the submission should proceed.
151 bool validateInteractively();
153 // Validates each of the controls, and stores controls of which 'invalid'
154 // event was not canceled to the specified vector. Returns true if there
155 // are any invalid controls in this form.
156 bool checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement>>*, CheckValidityEventBehavior);
158 Element* elementFromPastNamesMap(const AtomicString&);
159 void addToPastNamesMap(Element*, const AtomicString& pastName);
160 void removeFromPastNamesMap(HTMLElement&);
162 typedef WillBeHeapHashMap<AtomicString, RawPtrWillBeMember<Element>> PastNamesMap;
164 FormSubmission::Attributes m_attributes;
165 OwnPtrWillBeMember<PastNamesMap> m_pastNamesMap;
167 RadioButtonGroupScope m_radioButtonGroupScope;
169 // Do not access m_associatedElements directly. Use associatedElements() instead.
170 FormAssociatedElement::List m_associatedElements;
171 // Do not access m_imageElements directly. Use imageElements() instead.
172 WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>> m_imageElements;
174 WeakPtrFactory<HTMLFormElement> m_weakPtrFactory;
176 bool m_associatedElementsAreDirty : 1;
177 bool m_imageElementsAreDirty : 1;
178 bool m_hasElementsAssociatedByParser : 1;
179 bool m_didFinishParsingChildren : 1;
181 bool m_wasUserSubmitted : 1;
182 bool m_isSubmittingOrInUserJSSubmitEvent : 1;
183 bool m_shouldSubmit : 1;
185 bool m_isInResetFunction : 1;
187 bool m_wasDemoted : 1;
189 OwnPtrWillBeMember<GenericEventQueue> m_pendingAutocompleteEventsQueue;
194 #endif // HTMLFormElement_h