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 "CheckedRadioButtons.h"
28 #include "FormState.h"
29 #include "FormSubmission.h"
30 #include "HTMLElement.h"
31 #include <wtf/OwnPtr.h>
36 class FormAssociatedElement;
38 class HTMLFormControlElement;
39 class HTMLImageElement;
40 class HTMLInputElement;
41 class HTMLFormCollection;
44 struct CollectionCache;
46 class HTMLFormElement : public HTMLElement {
48 static PassRefPtr<HTMLFormElement> create(Document*);
49 static PassRefPtr<HTMLFormElement> create(const QualifiedName&, Document*);
50 virtual ~HTMLFormElement();
52 PassRefPtr<HTMLCollection> elements();
53 void getNamedElements(const AtomicString&, Vector<RefPtr<Node> >&);
55 unsigned length() const;
56 Node* item(unsigned index);
58 String enctype() const { return m_attributes.encodingType(); }
59 void setEnctype(const String&);
61 String encoding() const { return m_attributes.encodingType(); }
62 void setEncoding(const String& value) { setEnctype(value); }
64 bool shouldAutocomplete() const;
66 // FIXME: Should rename these two functions to say "form control" or "form-associated element" instead of "form element".
67 void registerFormElement(FormAssociatedElement*);
68 void removeFormElement(FormAssociatedElement*);
70 void registerImgElement(HTMLImageElement*);
71 void removeImgElement(HTMLImageElement*);
73 bool prepareForSubmission(Event*);
75 void submitFromJavaScript();
78 // Used to indicate a malformed state to keep from applying the bottom margin of the form.
79 // FIXME: Would probably be better to call this wasUnclosed; that's more specific.
80 void setMalformed(bool malformed) { m_wasMalformed = malformed; }
81 bool isMalformed() const { return m_wasMalformed; }
83 void setDemoted(bool demoted) { m_wasDemoted = demoted; }
85 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
86 bool formWouldHaveSecureSubmission(const String& url);
90 bool noValidate() const;
92 String acceptCharset() const { return m_attributes.acceptCharset(); }
93 void setAcceptCharset(const String&);
95 String action() const;
96 void setAction(const String&);
98 String method() const;
99 void setMethod(const String&);
101 virtual String target() const;
103 bool wasUserSubmitted() const;
105 HTMLFormControlElement* defaultButton() const;
107 bool checkValidity();
109 HTMLFormControlElement* elementForAlias(const AtomicString&);
110 void addElementAlias(HTMLFormControlElement*, const AtomicString& alias);
112 CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
114 const Vector<FormAssociatedElement*>& associatedElements() const { return m_associatedElements; }
117 HTMLFormElement(const QualifiedName&, Document*);
119 virtual bool rendererIsNeeded(const NodeRenderingContext&);
120 virtual void insertedIntoDocument();
121 virtual void removedFromDocument();
123 virtual void handleLocalEvents(Event*);
125 virtual void parseMappedAttribute(Attribute*);
127 virtual bool isURLAttribute(Attribute*) const;
129 virtual void documentDidBecomeActive();
131 virtual void willMoveToNewOwnerDocument();
132 virtual void didMoveToNewOwnerDocument();
134 void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
136 unsigned formElementIndexWithFormAttribute(Element*);
137 unsigned formElementIndex(FormAssociatedElement*);
139 // Returns true if the submission should proceed.
140 bool validateInteractively(Event*);
142 // Validates each of the controls, and stores controls of which 'invalid'
143 // event was not canceled to the specified vector. Returns true if there
144 // are any invalid controls in this form.
145 bool checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<FormAssociatedElement> >&);
147 friend class HTMLFormCollection;
149 typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap;
151 FormSubmission::Attributes m_attributes;
152 OwnPtr<AliasMap> m_elementAliases;
153 OwnPtr<CollectionCache> m_collectionCache;
155 CheckedRadioButtons m_checkedRadioButtons;
157 unsigned m_associatedElementsBeforeIndex;
158 unsigned m_associatedElementsAfterIndex;
159 Vector<FormAssociatedElement*> m_associatedElements;
160 Vector<HTMLImageElement*> m_imageElements;
162 bool m_wasUserSubmitted;
163 bool m_isSubmittingOrPreparingForSubmission;
166 bool m_isInResetFunction;
174 } // namespace WebCore
176 #endif // HTMLFormElement_h