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/FormState.h"
31 #include "core/loader/FormSubmission.h"
32 #include "wtf/OwnPtr.h"
33 #include "wtf/WeakPtr.h"
42 class FormAssociatedElement;
44 class HTMLFormControlElement;
45 class HTMLImageElement;
46 class HTMLInputElement;
48 class HTMLFormElement FINAL : public HTMLElement {
50 static PassRefPtr<HTMLFormElement> create(Document&);
51 virtual ~HTMLFormElement();
53 PassRefPtr<HTMLCollection> elements();
54 void getNamedElements(const AtomicString&, Vector<RefPtr<Element> >&);
56 unsigned length() const;
57 Element* 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&);
71 WeakPtr<HTMLFormElement> createWeakPtr();
72 void didAssociateByParser();
74 bool prepareForSubmission(Event*);
76 void submitFromJavaScript();
79 void setDemoted(bool);
81 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
85 bool noValidate() const;
87 const AtomicString& action() const;
89 String method() const;
90 void setMethod(const AtomicString&);
92 bool wasUserSubmitted() const;
94 HTMLFormControlElement* defaultButton() const;
97 bool checkValidityWithoutDispatchingEvents();
99 enum AutocompleteResult {
100 AutocompleteResultSuccess,
101 AutocompleteResultErrorDisabled,
102 AutocompleteResultErrorCancel,
103 AutocompleteResultErrorInvalid,
106 void requestAutocomplete();
107 void finishRequestAutocomplete(AutocompleteResult);
109 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocomplete);
110 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocompleteerror);
112 RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; }
114 const Vector<FormAssociatedElement*>& associatedElements() const;
115 const Vector<HTMLImageElement*>& imageElements();
117 void getTextFieldValues(StringPairVector& fieldNamesAndValues) const;
118 void anonymousNamedGetter(const AtomicString& name, bool&, RefPtr<RadioNodeList>&, bool&, RefPtr<Element>&);
121 explicit HTMLFormElement(Document&);
123 virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
124 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
125 virtual void removedFrom(ContainerNode*) OVERRIDE;
126 virtual void finishParsingChildren() OVERRIDE;
128 virtual void handleLocalEvents(Event*) OVERRIDE;
130 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
131 virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
133 virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
135 virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE;
137 void submitDialog(PassRefPtr<FormSubmission>);
138 void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
140 void scheduleFormSubmission(PassRefPtr<FormSubmission>);
142 void collectAssociatedElements(Node* root, Vector<FormAssociatedElement*>&) const;
143 void collectImageElements(Node* root, Vector<HTMLImageElement*>&);
145 // Returns true if the submission should proceed.
146 bool validateInteractively(Event*);
148 // Validates each of the controls, and stores controls of which 'invalid'
149 // event was not canceled to the specified vector. Returns true if there
150 // are any invalid controls in this form.
151 bool checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<FormAssociatedElement> >*, HTMLFormControlElement::CheckValidityDispatchEvents = HTMLFormControlElement::CheckValidityDispatchEventsAllowed);
153 Element* elementFromPastNamesMap(const AtomicString&);
154 void addToPastNamesMap(Element*, const AtomicString& pastName);
155 void removeFromPastNamesMap(HTMLElement&);
157 typedef HashMap<AtomicString, Element*> PastNamesMap;
159 FormSubmission::Attributes m_attributes;
160 OwnPtr<PastNamesMap> m_pastNamesMap;
162 RadioButtonGroupScope m_radioButtonGroupScope;
164 // Do not access m_associatedElements directly. Use associatedElements() instead.
165 Vector<FormAssociatedElement*> m_associatedElements;
166 // Do not access m_imageElements directly. Use imageElements() instead.
167 Vector<HTMLImageElement*> m_imageElements;
168 WeakPtrFactory<HTMLFormElement> m_weakPtrFactory;
169 bool m_associatedElementsAreDirty;
170 bool m_imageElementsAreDirty;
171 bool m_hasElementsAssociatedByParser;
172 bool m_didFinishParsingChildren;
174 bool m_wasUserSubmitted;
175 bool m_isSubmittingOrPreparingForSubmission;
178 bool m_isInResetFunction;
182 void requestAutocompleteTimerFired(Timer<HTMLFormElement>*);
184 Vector<RefPtr<Event> > m_pendingAutocompleteEvents;
185 Timer<HTMLFormElement> m_requestAutocompleteTimer;
188 DEFINE_NODE_TYPE_CASTS(HTMLFormElement, hasTagName(HTMLNames::formTag));
190 } // namespace WebCore
192 #endif // HTMLFormElement_h