Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 "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"
34
35 namespace WTF{
36 class TextEncoding;
37 }
38
39 namespace WebCore {
40
41 class Event;
42 class FormAssociatedElement;
43 class FormData;
44 class HTMLFormControlElement;
45 class HTMLImageElement;
46 class HTMLInputElement;
47
48 class HTMLFormElement FINAL : public HTMLElement {
49 public:
50     static PassRefPtr<HTMLFormElement> create(Document&);
51     virtual ~HTMLFormElement();
52
53     PassRefPtr<HTMLCollection> elements();
54     void getNamedElements(const AtomicString&, Vector<RefPtr<Element> >&);
55
56     unsigned length() const;
57     Element* item(unsigned index);
58
59     String enctype() const { return m_attributes.encodingType(); }
60     void setEnctype(const AtomicString&);
61
62     String encoding() const { return m_attributes.encodingType(); }
63     void setEncoding(const AtomicString& value) { setEnctype(value); }
64
65     bool shouldAutocomplete() const;
66
67     void associate(FormAssociatedElement&);
68     void disassociate(FormAssociatedElement&);
69     void associate(HTMLImageElement&);
70     void disassociate(HTMLImageElement&);
71     WeakPtr<HTMLFormElement> createWeakPtr();
72     void didAssociateByParser();
73
74     bool prepareForSubmission(Event*);
75     void submit();
76     void submitFromJavaScript();
77     void reset();
78
79     void setDemoted(bool);
80
81     void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
82
83     String name() const;
84
85     bool noValidate() const;
86
87     const AtomicString& action() const;
88
89     String method() const;
90     void setMethod(const AtomicString&);
91
92     bool wasUserSubmitted() const;
93
94     HTMLFormControlElement* defaultButton() const;
95
96     bool checkValidity();
97     bool checkValidityWithoutDispatchingEvents();
98
99     enum AutocompleteResult {
100         AutocompleteResultSuccess,
101         AutocompleteResultErrorDisabled,
102         AutocompleteResultErrorCancel,
103         AutocompleteResultErrorInvalid,
104     };
105
106     void requestAutocomplete();
107     void finishRequestAutocomplete(AutocompleteResult);
108
109     DEFINE_ATTRIBUTE_EVENT_LISTENER(autocomplete);
110     DEFINE_ATTRIBUTE_EVENT_LISTENER(autocompleteerror);
111
112     RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; }
113
114     const Vector<FormAssociatedElement*>& associatedElements() const;
115     const Vector<HTMLImageElement*>& imageElements();
116
117     void getTextFieldValues(StringPairVector& fieldNamesAndValues) const;
118     void anonymousNamedGetter(const AtomicString& name, bool&, RefPtr<RadioNodeList>&, bool&, RefPtr<Element>&);
119
120 private:
121     explicit HTMLFormElement(Document&);
122
123     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
124     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
125     virtual void removedFrom(ContainerNode*) OVERRIDE;
126     virtual void finishParsingChildren() OVERRIDE;
127
128     virtual void handleLocalEvents(Event*) OVERRIDE;
129
130     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
131     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
132
133     virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
134
135     virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE;
136
137     void submitDialog(PassRefPtr<FormSubmission>);
138     void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
139
140     void scheduleFormSubmission(PassRefPtr<FormSubmission>);
141
142     void collectAssociatedElements(Node* root, Vector<FormAssociatedElement*>&) const;
143     void collectImageElements(Node* root, Vector<HTMLImageElement*>&);
144
145     // Returns true if the submission should proceed.
146     bool validateInteractively(Event*);
147
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);
152
153     Element* elementFromPastNamesMap(const AtomicString&);
154     void addToPastNamesMap(Element*, const AtomicString& pastName);
155     void removeFromPastNamesMap(HTMLElement&);
156
157     typedef HashMap<AtomicString, Element*> PastNamesMap;
158
159     FormSubmission::Attributes m_attributes;
160     OwnPtr<PastNamesMap> m_pastNamesMap;
161
162     RadioButtonGroupScope m_radioButtonGroupScope;
163
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;
173
174     bool m_wasUserSubmitted;
175     bool m_isSubmittingOrPreparingForSubmission;
176     bool m_shouldSubmit;
177
178     bool m_isInResetFunction;
179
180     bool m_wasDemoted;
181
182     void requestAutocompleteTimerFired(Timer<HTMLFormElement>*);
183
184     Vector<RefPtr<Event> > m_pendingAutocompleteEvents;
185     Timer<HTMLFormElement> m_requestAutocompleteTimer;
186 };
187
188 DEFINE_NODE_TYPE_CASTS(HTMLFormElement, hasTagName(HTMLNames::formTag));
189
190 } // namespace WebCore
191
192 #endif // HTMLFormElement_h