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 {
51 static PassRefPtrWillBeRawPtr<HTMLFormElement> create(Document&);
52 virtual ~HTMLFormElement();
53 virtual void trace(Visitor*) OVERRIDE;
55 PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> elements();
56 void getNamedElements(const AtomicString&, WillBeHeapVector<RefPtrWillBeMember<Element> >&);
58 unsigned length() const;
59 Element* item(unsigned index);
61 String enctype() const { return m_attributes.encodingType(); }
62 void setEnctype(const AtomicString&);
64 String encoding() const { return m_attributes.encodingType(); }
65 void setEncoding(const AtomicString& value) { setEnctype(value); }
67 bool shouldAutocomplete() const;
69 void associate(FormAssociatedElement&);
70 void disassociate(FormAssociatedElement&);
71 void associate(HTMLImageElement&);
72 void disassociate(HTMLImageElement&);
74 WeakPtr<HTMLFormElement> createWeakPtr();
76 void didAssociateByParser();
78 void prepareForSubmission(Event*);
80 void submitFromJavaScript();
83 void setDemoted(bool);
85 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
89 bool noValidate() const;
91 const AtomicString& action() const;
93 String method() const;
94 void setMethod(const AtomicString&);
96 bool wasUserSubmitted() const;
98 HTMLFormControlElement* defaultButton() const;
100 bool checkValidity();
102 enum AutocompleteResult {
103 AutocompleteResultSuccess,
104 AutocompleteResultErrorDisabled,
105 AutocompleteResultErrorCancel,
106 AutocompleteResultErrorInvalid,
109 void requestAutocomplete();
110 void finishRequestAutocomplete(AutocompleteResult);
112 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocomplete);
113 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocompleteerror);
115 RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; }
117 const FormAssociatedElement::List& associatedElements() const;
118 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >& imageElements();
120 void anonymousNamedGetter(const AtomicString& name, bool&, RefPtrWillBeRawPtr<RadioNodeList>&, bool&, RefPtrWillBeRawPtr<Element>&);
123 explicit HTMLFormElement(Document&);
125 virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
126 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
127 virtual void removedFrom(ContainerNode*) OVERRIDE;
128 virtual void finishParsingChildren() OVERRIDE;
130 virtual void handleLocalEvents(Event*) OVERRIDE;
132 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
133 virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
134 virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
136 virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
138 virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE;
140 void submitDialog(PassRefPtrWillBeRawPtr<FormSubmission>);
141 void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
143 void scheduleFormSubmission(PassRefPtrWillBeRawPtr<FormSubmission>);
145 void collectAssociatedElements(Node& root, FormAssociatedElement::List&) const;
146 void collectImageElements(Node& root, WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >&);
148 // Returns true if the submission should proceed.
149 bool validateInteractively(Event*);
151 // Validates each of the controls, and stores controls of which 'invalid'
152 // event was not canceled to the specified vector. Returns true if there
153 // are any invalid controls in this form.
154 bool checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >*);
156 Element* elementFromPastNamesMap(const AtomicString&);
157 void addToPastNamesMap(Element*, const AtomicString& pastName);
158 void removeFromPastNamesMap(HTMLElement&);
160 typedef WillBeHeapHashMap<AtomicString, RawPtrWillBeMember<Element> > PastNamesMap;
162 FormSubmission::Attributes m_attributes;
163 OwnPtrWillBeMember<PastNamesMap> m_pastNamesMap;
165 RadioButtonGroupScope m_radioButtonGroupScope;
167 // Do not access m_associatedElements directly. Use associatedElements() instead.
168 FormAssociatedElement::List m_associatedElements;
169 // Do not access m_imageElements directly. Use imageElements() instead.
170 WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> > m_imageElements;
172 WeakPtrFactory<HTMLFormElement> m_weakPtrFactory;
174 bool m_associatedElementsAreDirty;
175 bool m_imageElementsAreDirty;
176 bool m_hasElementsAssociatedByParser;
177 bool m_didFinishParsingChildren;
179 bool m_wasUserSubmitted;
180 bool m_isSubmittingOrInUserJSSubmitEvent;
183 bool m_isInResetFunction;
187 OwnPtrWillBeMember<GenericEventQueue> m_pendingAutocompleteEventsQueue;
190 } // namespace WebCore
192 #endif // HTMLFormElement_h