|
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 "FormDataBuilder.h" |
|
29 #include "FormState.h" |
|
30 #include "HTMLElement.h" |
|
31 #include <wtf/OwnPtr.h> |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 class Event; |
|
36 class FormData; |
|
37 class FormSubmission; |
|
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_formDataBuilder.encodingType(); } |
|
59 void setEnctype(const String&); |
|
60 |
|
61 String encoding() const { return m_formDataBuilder.encodingType(); } |
|
62 void setEncoding(const String& value) { setEnctype(value); } |
|
63 |
|
64 bool autoComplete() const { return m_autocomplete; } |
|
65 |
|
66 // FIXME: Should rename these two functions to say "form control" |
|
67 // or "form-associated element" instead of "form element". |
|
68 void registerFormElement(HTMLFormControlElement*); |
|
69 void removeFormElement(HTMLFormControlElement*); |
|
70 void registerImgElement(HTMLImageElement*); |
|
71 void removeImgElement(HTMLImageElement*); |
|
72 |
|
73 bool prepareSubmit(Event*); |
|
74 void submit(Frame* javaScriptActiveFrame = 0); |
|
75 void reset(); |
|
76 |
|
77 // Used to indicate a malformed state to keep from applying the bottom margin of the form. |
|
78 void setMalformed(bool malformed) { m_malformed = malformed; } |
|
79 bool isMalformed() const { return m_malformed; } |
|
80 |
|
81 void setDemoted(bool demoted) { m_demoted = demoted; } |
|
82 bool isDemoted() const { return m_demoted; } |
|
83 |
|
84 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger); |
|
85 bool formWouldHaveSecureSubmission(const String& url); |
|
86 |
|
87 String name() const; |
|
88 |
|
89 bool noValidate() const; |
|
90 |
|
91 String acceptCharset() const { return m_formDataBuilder.acceptCharset(); } |
|
92 |
|
93 String action() const; |
|
94 void setAction(const String&); |
|
95 |
|
96 String method() const; |
|
97 void setMethod(const String&); |
|
98 |
|
99 virtual String target() const; |
|
100 |
|
101 FormSubmissionTrigger submissionTrigger() const; |
|
102 |
|
103 HTMLFormControlElement* defaultButton() const; |
|
104 |
|
105 bool checkValidity(); |
|
106 |
|
107 PassRefPtr<HTMLFormControlElement> elementForAlias(const AtomicString&); |
|
108 void addElementAlias(HTMLFormControlElement*, const AtomicString& alias); |
|
109 |
|
110 CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; } |
|
111 |
|
112 const Vector<HTMLFormControlElement*>& associatedElements() const { return m_associatedElements; } |
|
113 |
|
114 private: |
|
115 HTMLFormElement(const QualifiedName&, Document*); |
|
116 |
|
117 virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } |
|
118 virtual int tagPriority() const { return 3; } |
|
119 |
|
120 virtual bool rendererIsNeeded(RenderStyle*); |
|
121 virtual void insertedIntoDocument(); |
|
122 virtual void removedFromDocument(); |
|
123 |
|
124 virtual void handleLocalEvents(Event*); |
|
125 |
|
126 virtual void parseMappedAttribute(Attribute*); |
|
127 |
|
128 virtual bool isURLAttribute(Attribute*) const; |
|
129 |
|
130 virtual void documentDidBecomeActive(); |
|
131 |
|
132 virtual void willMoveToNewOwnerDocument(); |
|
133 virtual void didMoveToNewOwnerDocument(); |
|
134 |
|
135 void submit(Event*, bool activateSubmitButton, bool lockHistory, FormSubmissionTrigger); |
|
136 |
|
137 PassRefPtr<FormSubmission> prepareFormSubmission(Event*, bool lockHistory, FormSubmissionTrigger); |
|
138 unsigned formElementIndex(HTMLFormControlElement*); |
|
139 // Returns true if the submission should be proceeded. |
|
140 bool validateInteractively(Event*); |
|
141 // Validates each of the controls, and stores controls of which 'invalid' |
|
142 // event was not canceled to the specified vector. |
|
143 void collectUnhandledInvalidControls(Vector<RefPtr<HTMLFormControlElement> >&); |
|
144 |
|
145 friend class HTMLFormCollection; |
|
146 |
|
147 typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap; |
|
148 |
|
149 FormDataBuilder m_formDataBuilder; |
|
150 OwnPtr<AliasMap> m_elementAliases; |
|
151 OwnPtr<CollectionCache> m_collectionCache; |
|
152 |
|
153 CheckedRadioButtons m_checkedRadioButtons; |
|
154 |
|
155 Vector<HTMLFormControlElement*> m_associatedElements; |
|
156 Vector<HTMLImageElement*> m_imageElements; |
|
157 |
|
158 FormSubmissionTrigger m_submissionTrigger; |
|
159 |
|
160 bool m_autocomplete : 1; |
|
161 bool m_insubmit : 1; |
|
162 bool m_doingsubmit : 1; |
|
163 bool m_inreset : 1; |
|
164 bool m_malformed : 1; |
|
165 bool m_demoted : 1; |
|
166 AtomicString m_name; |
|
167 }; |
|
168 |
|
169 } // namespace WebCore |
|
170 |
|
171 #endif // HTMLFormElement_h |