• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
enctype()58     String enctype() const { return m_attributes.encodingType(); }
59     void setEnctype(const String&);
60 
encoding()61     String encoding() const { return m_attributes.encodingType(); }
setEncoding(const String & value)62     void setEncoding(const String& value) { setEnctype(value); }
63 
64     // FIXME: Rename this function to shouldAutocomplete.
65     bool autoComplete() const;
66 
67     // FIXME: Should rename these two functions to say "form control" or "form-associated element" instead of "form element".
68     void registerFormElement(FormAssociatedElement*);
69     void removeFormElement(FormAssociatedElement*);
70 
71     void registerImgElement(HTMLImageElement*);
72     void removeImgElement(HTMLImageElement*);
73 
74     bool prepareForSubmission(Event*);
75     void submit();
76     void submitFromJavaScript();
77     void reset();
78 
79     // Used to indicate a malformed state to keep from applying the bottom margin of the form.
80     // FIXME: Would probably be better to call this wasUnclosed; that's more specific.
setMalformed(bool malformed)81     void setMalformed(bool malformed) { m_wasMalformed = malformed; }
isMalformed()82     bool isMalformed() const { return m_wasMalformed; }
83 
setDemoted(bool demoted)84     void setDemoted(bool demoted) { m_wasDemoted = demoted; }
85 
86     void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
87     bool formWouldHaveSecureSubmission(const String& url);
88 
89     String name() const;
90 
91     bool noValidate() const;
92 
acceptCharset()93     String acceptCharset() const { return m_attributes.acceptCharset(); }
94     void setAcceptCharset(const String&);
95 
96     String action() const;
97     void setAction(const String&);
98 
99     String method() const;
100     void setMethod(const String&);
101 
102     virtual String target() const;
103 
104     bool wasUserSubmitted() const;
105 
106     HTMLFormControlElement* defaultButton() const;
107 
108     bool checkValidity();
109 
110     HTMLFormControlElement* elementForAlias(const AtomicString&);
111     void addElementAlias(HTMLFormControlElement*, const AtomicString& alias);
112 
checkedRadioButtons()113     CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
114 
associatedElements()115     const Vector<FormAssociatedElement*>& associatedElements() const { return m_associatedElements; }
116 
117 private:
118     HTMLFormElement(const QualifiedName&, Document*);
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 processingUserGesture, FormSubmissionTrigger);
136 
137     unsigned formElementIndexWithFormAttribute(Element*);
138     unsigned formElementIndex(FormAssociatedElement*);
139 
140     // Returns true if the submission should proceed.
141     bool validateInteractively(Event*);
142 
143     // Validates each of the controls, and stores controls of which 'invalid'
144     // event was not canceled to the specified vector. Returns true if there
145     // are any invalid controls in this form.
146     bool checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<FormAssociatedElement> >&);
147 
148     friend class HTMLFormCollection;
149 
150     typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap;
151 
152     FormSubmission::Attributes m_attributes;
153     OwnPtr<AliasMap> m_elementAliases;
154     OwnPtr<CollectionCache> m_collectionCache;
155 
156     CheckedRadioButtons m_checkedRadioButtons;
157 
158     unsigned m_associatedElementsBeforeIndex;
159     unsigned m_associatedElementsAfterIndex;
160     Vector<FormAssociatedElement*> m_associatedElements;
161     Vector<HTMLImageElement*> m_imageElements;
162 
163     bool m_wasUserSubmitted;
164     bool m_isSubmittingOrPreparingForSubmission;
165     bool m_shouldSubmit;
166 
167     bool m_isInResetFunction;
168 
169     bool m_wasMalformed;
170     bool m_wasDemoted;
171 
172     AtomicString m_name;
173 };
174 
175 } // namespace WebCore
176 
177 #endif // HTMLFormElement_h
178