Upstream version 11.40.277.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/FormSubmission.h"
31 #include "wtf/OwnPtr.h"
32 #include "wtf/WeakPtr.h"
33
34 namespace blink {
35
36 class Event;
37 class FormAssociatedElement;
38 class GenericEventQueue;
39 class HTMLFormControlElement;
40 class HTMLFormControlsCollection;
41 class HTMLImageElement;
42 class RadioNodeListOrElement;
43
44 class HTMLFormElement final : public HTMLElement {
45     DEFINE_WRAPPERTYPEINFO();
46 public:
47     static PassRefPtrWillBeRawPtr<HTMLFormElement> create(Document&);
48     virtual ~HTMLFormElement();
49     virtual void trace(Visitor*) override;
50
51     void setNeedsValidityCheck();
52
53     PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> elements();
54     void getNamedElements(const AtomicString&, WillBeHeapVector<RefPtrWillBeMember<Element>>&);
55
56     unsigned length() const;
57     HTMLElement* 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 #if !ENABLE(OILPAN)
72     WeakPtr<HTMLFormElement> createWeakPtr();
73 #endif
74     void didAssociateByParser();
75
76     void prepareForSubmission(Event*);
77     void submit();
78     void submitFromJavaScript();
79     void reset();
80
81     void setDemoted(bool);
82
83     void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
84
85     String name() const;
86
87     bool noValidate() const;
88
89     const AtomicString& action() const;
90
91     String method() const;
92     void setMethod(const AtomicString&);
93
94     bool wasUserSubmitted() const;
95
96     HTMLFormControlElement* defaultButton() const;
97
98     bool checkValidity();
99     bool reportValidity();
100     virtual bool matchesValidityPseudoClasses() const override final;
101     virtual bool isValidElement() override final;
102
103     enum AutocompleteResult {
104         AutocompleteResultSuccess,
105         AutocompleteResultErrorDisabled,
106         AutocompleteResultErrorCancel,
107         AutocompleteResultErrorInvalid,
108     };
109
110     void requestAutocomplete();
111     void finishRequestAutocomplete(AutocompleteResult);
112
113     DEFINE_ATTRIBUTE_EVENT_LISTENER(autocomplete);
114     DEFINE_ATTRIBUTE_EVENT_LISTENER(autocompleteerror);
115
116     RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; }
117
118     const FormAssociatedElement::List& associatedElements() const;
119     const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>& imageElements();
120
121     void anonymousNamedGetter(const AtomicString& name, RadioNodeListOrElement&);
122
123 private:
124     explicit HTMLFormElement(Document&);
125
126     virtual bool rendererIsNeeded(const RenderStyle&) override;
127     virtual InsertionNotificationRequest insertedInto(ContainerNode*) override;
128     virtual void removedFrom(ContainerNode*) override;
129     virtual void finishParsingChildren() override;
130
131     virtual void handleLocalEvents(Event*) override;
132
133     virtual void attributeWillChange(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue) override;
134     virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
135     virtual bool isURLAttribute(const Attribute&) const override;
136     virtual bool hasLegalLinkAttribute(const QualifiedName&) const override;
137
138     virtual bool shouldRegisterAsNamedItem() const override { return true; }
139
140     virtual void copyNonAttributePropertiesFromElement(const Element&) override;
141
142     void submitDialog(PassRefPtrWillBeRawPtr<FormSubmission>);
143     void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
144
145     void scheduleFormSubmission(PassRefPtrWillBeRawPtr<FormSubmission>);
146
147     void collectAssociatedElements(Node& root, FormAssociatedElement::List&) const;
148     void collectImageElements(Node& root, WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>&);
149
150     // Returns true if the submission should proceed.
151     bool validateInteractively();
152
153     // Validates each of the controls, and stores controls of which 'invalid'
154     // event was not canceled to the specified vector. Returns true if there
155     // are any invalid controls in this form.
156     bool checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<RefPtrWillBeMember<HTMLFormControlElement>>*, CheckValidityEventBehavior);
157
158     Element* elementFromPastNamesMap(const AtomicString&);
159     void addToPastNamesMap(Element*, const AtomicString& pastName);
160     void removeFromPastNamesMap(HTMLElement&);
161
162     typedef WillBeHeapHashMap<AtomicString, RawPtrWillBeMember<Element>> PastNamesMap;
163
164     FormSubmission::Attributes m_attributes;
165     OwnPtrWillBeMember<PastNamesMap> m_pastNamesMap;
166
167     RadioButtonGroupScope m_radioButtonGroupScope;
168
169     // Do not access m_associatedElements directly. Use associatedElements() instead.
170     FormAssociatedElement::List m_associatedElements;
171     // Do not access m_imageElements directly. Use imageElements() instead.
172     WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>> m_imageElements;
173 #if !ENABLE(OILPAN)
174     WeakPtrFactory<HTMLFormElement> m_weakPtrFactory;
175 #endif
176     bool m_associatedElementsAreDirty : 1;
177     bool m_imageElementsAreDirty : 1;
178     bool m_hasElementsAssociatedByParser : 1;
179     bool m_didFinishParsingChildren : 1;
180
181     bool m_wasUserSubmitted : 1;
182     bool m_isSubmittingOrInUserJSSubmitEvent : 1;
183     bool m_shouldSubmit : 1;
184
185     bool m_isInResetFunction : 1;
186
187     bool m_wasDemoted : 1;
188
189     OwnPtrWillBeMember<GenericEventQueue> m_pendingAutocompleteEventsQueue;
190 };
191
192 } // namespace blink
193
194 #endif // HTMLFormElement_h