initial import
[vuplus_webkit] / Source / WebCore / html / HTMLFormElement.h
1 /*
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.
6  *
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.
11  *
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.
16  *
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.
21  *
22  */
23
24 #ifndef HTMLFormElement_h
25 #define HTMLFormElement_h
26
27 #include "CheckedRadioButtons.h"
28 #include "FormState.h"
29 #include "FormSubmission.h"
30 #include "HTMLElement.h"
31 #include <wtf/OwnPtr.h>
32
33 namespace WebCore {
34
35 class Event;
36 class FormAssociatedElement;
37 class FormData;
38 class HTMLFormControlElement;
39 class HTMLImageElement;
40 class HTMLInputElement;
41 class HTMLFormCollection;
42 class TextEncoding;
43
44 struct CollectionCache;
45
46 class HTMLFormElement : public HTMLElement {
47 public:
48     static PassRefPtr<HTMLFormElement> create(Document*);
49     static PassRefPtr<HTMLFormElement> create(const QualifiedName&, Document*);
50     virtual ~HTMLFormElement();
51
52     PassRefPtr<HTMLCollection> elements();
53     void getNamedElements(const AtomicString&, Vector<RefPtr<Node> >&);
54
55     unsigned length() const;
56     Node* item(unsigned index);
57
58     String enctype() const { return m_attributes.encodingType(); }
59     void setEnctype(const String&);
60
61     String encoding() const { return m_attributes.encodingType(); }
62     void setEncoding(const String& value) { setEnctype(value); }
63
64     bool shouldAutocomplete() const;
65
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*);
69
70     void registerImgElement(HTMLImageElement*);
71     void removeImgElement(HTMLImageElement*);
72
73     bool prepareForSubmission(Event*);
74     void submit();
75     void submitFromJavaScript();
76     void reset();
77
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; }
82
83     void setDemoted(bool demoted) { m_wasDemoted = demoted; }
84
85     void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
86     bool formWouldHaveSecureSubmission(const String& url);
87
88     String name() const;
89
90     bool noValidate() const;
91
92     String acceptCharset() const { return m_attributes.acceptCharset(); }
93     void setAcceptCharset(const String&);
94
95     String action() const;
96     void setAction(const String&);
97
98     String method() const;
99     void setMethod(const String&);
100
101     virtual String target() const;
102
103     bool wasUserSubmitted() const;
104
105     HTMLFormControlElement* defaultButton() const;
106
107     bool checkValidity();
108
109     HTMLFormControlElement* elementForAlias(const AtomicString&);
110     void addElementAlias(HTMLFormControlElement*, const AtomicString& alias);
111
112     CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
113
114     const Vector<FormAssociatedElement*>& associatedElements() const { return m_associatedElements; }
115
116 private:
117     HTMLFormElement(const QualifiedName&, Document*);
118
119     virtual bool rendererIsNeeded(const NodeRenderingContext&);
120     virtual void insertedIntoDocument();
121     virtual void removedFromDocument();
122
123     virtual void handleLocalEvents(Event*);
124
125     virtual void parseMappedAttribute(Attribute*);
126
127     virtual bool isURLAttribute(Attribute*) const;
128
129     virtual void documentDidBecomeActive();
130
131     virtual void willMoveToNewOwnerDocument();
132     virtual void didMoveToNewOwnerDocument();
133
134     void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
135
136     unsigned formElementIndexWithFormAttribute(Element*);
137     unsigned formElementIndex(FormAssociatedElement*);
138
139     // Returns true if the submission should proceed.
140     bool validateInteractively(Event*);
141
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> >&);
146
147     friend class HTMLFormCollection;
148
149     typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap;
150
151     FormSubmission::Attributes m_attributes;
152     OwnPtr<AliasMap> m_elementAliases;
153     OwnPtr<CollectionCache> m_collectionCache;
154
155     CheckedRadioButtons m_checkedRadioButtons;
156
157     unsigned m_associatedElementsBeforeIndex;
158     unsigned m_associatedElementsAfterIndex;
159     Vector<FormAssociatedElement*> m_associatedElements;
160     Vector<HTMLImageElement*> m_imageElements;
161
162     bool m_wasUserSubmitted;
163     bool m_isSubmittingOrPreparingForSubmission;
164     bool m_shouldSubmit;
165
166     bool m_isInResetFunction;
167
168     bool m_wasMalformed;
169     bool m_wasDemoted;
170
171     AtomicString m_name;
172 };
173
174 } // namespace WebCore
175
176 #endif // HTMLFormElement_h