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"
41 class FormAssociatedElement;
43 class GenericEventQueue;
44 class HTMLFormControlElement;
45 class HTMLFormControlsCollection;
46 class HTMLImageElement;
47 class HTMLInputElement;
49 class HTMLFormElement FINAL : public HTMLElement {
50 DEFINE_WRAPPERTYPEINFO();
52 static PassRefPtrWillBeRawPtr<HTMLFormElement> create(Document&);
53 virtual ~HTMLFormElement();
54 virtual void trace(Visitor*) OVERRIDE;
56 PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> elements();
57 void getNamedElements(const AtomicString&, WillBeHeapVector<RefPtrWillBeMember<Element> >&);
59 unsigned length() const;
60 HTMLElement* item(unsigned index);
62 String enctype() const { return m_attributes.encodingType(); }
63 void setEnctype(const AtomicString&);
65 String encoding() const { return m_attributes.encodingType(); }
66 void setEncoding(const AtomicString& value) { setEnctype(value); }
68 bool shouldAutocomplete() const;
70 void associate(FormAssociatedElement&);
71 void disassociate(FormAssociatedElement&);
72 void associate(HTMLImageElement&);
73 void disassociate(HTMLImageElement&);
75 WeakPtr<HTMLFormElement> createWeakPtr();
77 void didAssociateByParser();
79 void prepareForSubmission(Event*);
81 void submitFromJavaScript();
84 void setDemoted(bool);
86 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
90 bool noValidate() const;
92 const AtomicString& action() const;
94 String method() const;
95 void setMethod(const AtomicString&);
97 bool wasUserSubmitted() const;
99 HTMLFormControlElement* defaultButton() const;
101 bool checkValidity();
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, RefPtrWillBeRawPtr<RadioNodeList>&, RefPtrWillBeRawPtr<Element>&);
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(Event*);
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<FormAssociatedElement> >*);
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